/** Obsolete since constraints violation are expressed in rdf first
  * Creates an RDF representation (instances of spin:ConstraintViolation) from a
  * collection of ConstraintViolation Java objects.
  * @param cvs  the violation objects
  * @param result  the Model to add the results to
  * @param createSource  true to also create the spin:violationSource
  */
 public static void addConstraintViolationsRDF(List <ConstraintViolation> cvs, IGraph result, bool createSource)
 {
     foreach (ConstraintViolation cv in cvs)
     {
         INode  r       = SPIN.ConstraintViolation;
         String message = cv.getMessage();
         if (message != null && message.Length > 0)
         {
             result.Assert(r, RDFS.label, RDFUtil.CreateLiteralNode(message));
         }
         if (cv.getRoot() != null)
         {
             result.Assert(r, SPIN.violationRoot, cv.getRoot());
         }
         foreach (SimplePropertyPath path in cv.getPaths())
         {
             if (path is ObjectPropertyPath)
             {
                 result.Assert(r, SPIN.violationPath, path.getPredicate());
             }
             else
             {
                 INode p = RDFUtil.nodeFactory.CreateBlankNode(Guid.NewGuid().ToString());
                 result.Assert(p, RDF.type, SP.ReversePath);
                 result.Assert(p, SP.path, path.getPredicate());
                 result.Assert(r, SPIN.violationPath, p);
             }
         }
         if (createSource && cv.getSource() != null)
         {
             result.Assert(r, SPIN.violationSource, cv.getSource());
         }
     }
 }
示例#2
0
        /**
         * Creates a new Variable as a blank node in a given Model.
         * @param model  the Model
         * @param varName  the name of the variable
         * @return the Variable
         */
        public static IVariable createVariable(SpinProcessor model, String varName)
        {
            IVariable variable = (IVariable)model.CreateResource(SP.ClassVariable).As(typeof(VariableImpl));

            variable.AddProperty(SP.PropertyVarName, RDFUtil.CreateLiteralNode(varName));
            return(variable);
        }
示例#3
0
        /* *
         * Creates a new spl:Attribute as a blank node in a given Model.
         * @param model  the Model to create the attribute in
         * @param argProperty  the predicate or null
         * @param argType  the value type or null
         * @param minCount  the minimum cardinality or null
         * @param maxCount  the maximum cardinality or null
         * @return a new Attribute
         */
        public static IAttribute createAttribute(SpinProcessor model, INode argProperty, INode argType, int minCount, int maxCount)
        {
            IAttribute a = (IAttribute)model.CreateResource(SPL.ClassAttribute).As(typeof(AttributeImpl));

            if (argProperty != null)
            {
                a.AddProperty(SPL.PropertyPredicate, argProperty);
            }
            if (argType != null)
            {
                a.AddProperty(SPL.PropertyValueType, argType);
            }
            a.AddProperty(SPL.PropertyMinCount, RDFUtil.CreateLiteralNode(minCount.ToString(), XSD.DatatypeInt.Uri));
            a.AddProperty(SPL.PropertyMaxCount, RDFUtil.CreateLiteralNode(maxCount.ToString(), XSD.DatatypeInt.Uri));
            return(a);
        }
示例#4
0
        // TODO Should not be needed since we would rely on the underlying storage capabilities

        /**
         * Creates a new Values element.
         * @param model  the Model to create the Values in
         * @param data  the Table providing the actual data
         * @return a new Values
         */
        public static IValues createValues(SpinProcessor model, SparqlResultSet data, bool untyped)
        {
            IResource blank  = untyped ? model.CreateResource() : model.CreateResource(SP.ClassValues);
            IValues   values = (IValues)blank.As(typeof(ValuesImpl));

            List <IResource> vars = new List <IResource>();

            foreach (String varName in data.Variables)
            {
                vars.Add(Resource.Get(RDFUtil.CreateLiteralNode(varName), model));
            }
            IResource varList = model.CreateList(vars.GetEnumerator());

            values.AddProperty(SP.PropertyVarNames, varList);

            IEnumerator <SparqlResult> bindings = data.Results.GetEnumerator();

            if (bindings.MoveNext())
            {
                List <IResource> lists = new List <IResource>();
                while (bindings.MoveNext())
                {
                    List <IResource> nodes   = new List <IResource>();
                    SparqlResult     binding = bindings.Current;
                    foreach (String varName in data.Variables)
                    {
                        INode value = binding.Value(varName);
                        if (value == null)
                        {
                            nodes.Add(Resource.Get(SP.ClassPropertyUndef, model));
                        }
                        else
                        {
                            nodes.Add(Resource.Get(value, model));
                        }
                    }
                    lists.Add(model.CreateList(nodes.GetEnumerator()));
                }
                values.AddProperty(SP.PropertyBindings, model.CreateList(lists.GetEnumerator()));
            }

            return(values);
        }
        private static SparqlParameterizedString convertAskToConstruct(SparqlParameterizedString ask, IQuery spinQuery, String label)
        {
            if (label == null)
            {
                label = spinQuery.getComment();
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("\nCONSTRUCT {\n");
            sb.Append("\t_:bnode a <" + SPIN.ConstraintViolation.Uri.ToString() + "> . \n");
            sb.Append("\t_:bnode <" + SPIN.violationRoot.Uri.ToString() + "> ?" + SPIN.THIS_VAR_NAME + " . \n");
            if (label != null)
            {
                // TODO handle literal escaping
                sb.Append("\t_:bnode <" + RDFS.label.Uri.ToString() + "> \"\"\"" + RDFUtil.CreateLiteralNode(label).ToString() + "\"\"\" . \n");
            }
            sb.Append("}\n");

            /*
             * SparqlQuery construct = SparqlUtil._sparqlParser.ParseFromString(ask);
             *  //construct.setQueryConstructType();
             *
             *  List<TriplePattern> list = new List<TriplePattern>();
             *  INode subject = RDFUtil.nodeFactory.CreateBlankNode();
             *  list.Add(new TriplePattern(construct., RDF.type, SPIN.ConstraintViolation));
             *  list.Add(new Triple(subject, SPIN.violationRoot, RDFUtil.CreateLiteralNode(SPIN.THIS_VAR_NAME)));
             *
             *  Bgp bgp = new Bgp(list);
             *  construct.ConstructTemplate = new GraphPattern();
             * construct.ConstructTemplate.
             *  //com.hp.hpl.jena.sparql.syntax.Template template = new com.hp.hpl.jena.sparql.syntax.Template(bgp);
             *  //
             *  //Element where = construct.getQueryPattern();
             *  //construct.RootGraphPattern(where);
             * */
            return(new SparqlParameterizedString(ask.CommandText.Replace("ASK", sb.ToString())));
        }