/// <summary> /// Builds a graph of rdf:type triples to restrict subsequent SPIN Constructors, Rules or Constraint checks evaluations /// </summary> /// <param name="resources"></param> internal Uri CreateExecutionContext(IEnumerable <INode> resources) { Uri executionContextUri = null; if (resources != null) { executionContextUri = RDFRuntime.NewTempGraphUri(); SparqlParameterizedString restrictionQuery; IGraph resourceRestrictions = new ThreadSafeGraph(); resourceRestrictions.BaseUri = executionContextUri; INode inputGraphNode = RDFUtil.CreateUriNode(executionContextUri); foreach (INode resource in resources) { resourceRestrictions.Assert(inputGraphNode, RDFRuntime.PropertyExecutionRestrictedTo, resource); } Storage.SaveGraph(resourceRestrictions); restrictionQuery = new SparqlParameterizedString(SparqlTemplates.SetExecutionContext); restrictionQuery.SetUri("resourceRestriction", executionContextUri); StringBuilder sb = new StringBuilder(); foreach (Resource graph in DefaultGraphs) { sb.AppendLine("USING <" + graph.Uri.ToString() + ">"); } restrictionQuery.CommandText = restrictionQuery.CommandText.Replace("@USING_DEFAULT", sb.ToString()); Storage.Update(restrictionQuery.ToString()); } return(executionContextUri); }
private bool nextIsMatchingVarPattern(ITriplePattern main, List <IElement> elements, int i) { if (main.getObject() is IVariable && i < elements.Count - 2 && elements[i + 1] is ITriplePattern && elements[i + 2] is ITriplePattern) { IVariable mainVar = (IVariable)main.getObject(); if (mainVar.isBlankNodeVar()) { ITriplePattern nextPattern = (ITriplePattern)elements[i + 1]; ITriplePattern lastPattern = (ITriplePattern)elements[i + 2]; IResource nextSubject = nextPattern.getSubject(); IResource lastSubject = lastPattern.getSubject(); if (nextSubject is IVariable && lastSubject is IVariable && RDFUtil.sameTerm(RDF.PropertyFirst, nextPattern.getPredicate()) && RDFUtil.sameTerm(RDF.PropertyRest, lastPattern.getPredicate())) { IVariable nextVar = (IVariable)nextSubject; if (mainVar.getName().Equals(nextVar.getName())) { IVariable lastVar = (IVariable)lastSubject; return(mainVar.getName().Equals(lastVar.getName())); } } } } return(false); }
override public void visit(IVariable variable) { if (RDFUtil.sameTerm(_var, variable)) { _checker.setResult(); } }
/** 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()); } } }
public List <Dictionary <String, IResource> > getBindings() { List <String> varNames = getVarNames(); List <Dictionary <String, IResource> > bindings = new List <Dictionary <String, IResource> >(); List <IResource> outerList = getResource(SP.PropertyBindings).AsList(); if (outerList != null) { foreach (IResource innerList in outerList) { Dictionary <String, IResource> binding = new Dictionary <String, IResource>(); bindings.Add(binding); IEnumerator <String> vars = varNames.GetEnumerator(); IEnumerator <IResource> values = innerList.AsList().GetEnumerator(); while (vars.MoveNext()) { String varName = vars.Current; IResource value = values.Current; if (!RDFUtil.sameTerm(SP.ClassPropertyUndef, value)) { binding.Add(varName, value); } } } } return(bindings); }
protected void printGraphIRIs(ISparqlPrinter p, String keyword) { List <String> graphIRIs = new List <String>(); { IEnumerator <Triple> it = listProperties(SP.PropertyGraphIRI).GetEnumerator(); while (it.MoveNext()) { Triple s = it.Current; if (s.Object is IUriNode) { graphIRIs.Add(((IUriNode)s.Object).Uri.ToString()); } } graphIRIs.Sort(); } foreach (String graphIRI in graphIRIs) { p.print(" "); if (keyword != null) { p.printKeyword(keyword); p.print(" "); } p.printURIResource(Resource.Get(RDFUtil.CreateUriNode(UriFactory.Create(graphIRI)), getModel())); } }
/** * 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); }
/// <summary> /// /// </summary> /// <param name="spinGraph"></param> /// <returns></returns> internal IGraph Initialise(IGraph spinGraph) { if (_spinConfiguration.GraphUris.Contains(spinGraph.BaseUri)) { _spinConfiguration.RemoveGraph(spinGraph.BaseUri); } String ontQuery = "CONSTRUCT { ?graphUri a <" + SPIN.ClassLibraryOntology + ">} WHERE { {?s (<" + SPIN.PropertyImports + ">|<" + OWL.PropertyImports + ">) ?graphUri} UNION {?graphUri a <" + SPIN.ClassLibraryOntology + ">} }"; IGraph imports = (Graph)spinGraph.ExecuteQuery(ontQuery); // Explore for subsequent imports foreach (Triple t in imports.GetTriplesWithPredicateObject(RDF.PropertyType, SPIN.ClassLibraryOntology)) { Uri importUri = ((IUriNode)t.Subject).Uri; if (!_spinConfiguration.GraphUris.Contains(importUri) && !RDFUtil.sameTerm(importUri, spinGraph.BaseUri)) { Initialise(importUri); } } _spinConfiguration.AddGraph(spinGraph); _reasoner.Initialise(spinGraph); IGraph inferenceGraph = ApplyInference(spinGraph); _spinConfiguration.AddGraph(inferenceGraph); _reasoner.Initialise(inferenceGraph); return(inferenceGraph); }
/** * * @param constaint is a statement whose subject is a class, and whose predicate is SPIN.constraint * @param results */ private void addArgumentFromConstraint(Triple constraint, List <IArgument> results) { if (constraint.Object is IBlankNode) { // Optimized case to avoid walking up class hierarchy IEnumerator <Triple> types = Resource.Get(constraint.Object, getModel()).listProperties(RDF.PropertyType).GetEnumerator(); while (types.MoveNext()) { Triple typeS = types.Current; if (typeS.Object is IUriNode) { if (RDFUtil.sameTerm(SPL.ClassArgument, typeS.Object)) { results.Add(SPINFactory.asArgument(Resource.Get(constraint.Object, getModel()))); } else if (!RDFUtil.sameTerm(SPL.ClassAttribute, typeS.Object)) { if (Resource.Get(typeS.Object, getModel()).hasProperty(RDFS.PropertySubClassOf, SPL.ClassArgument)) { results.Add(SPINFactory.asArgument(Resource.Get(constraint.Object, getModel()))); } } } } } else if (constraint.Object is IUriNode && Resource.Get(constraint.Object, getModel()).hasProperty(RDFS.PropertySubClassOf, SPL.ClassArgument)) { results.Add(SPINFactory.asArgument(Resource.Get(constraint.Object, getModel()))); } }
override public void visit(ITriplePath triplePath) { if (RDFUtil.sameTerm(_var, triplePath.getObject()) || RDFUtil.sameTerm(_var, triplePath.getSubject())) { _checker.setResult(); } }
// Special treatment of nested rdf:Lists private int printTriplePattern(List <IElement> elements, int i, ISparqlPrinter p) { ITriplePattern main = (ITriplePattern)elements[i]; // Print subject List <IResource> leftList = new List <IResource>(); i = addListMembers(elements, i, leftList); if (leftList.Count == 0) { TupleImpl.print(getModel(), main.getSubject(), p); } else { printRDFList(p, leftList); main = (ITriplePattern)elements[i]; } p.print(" "); // Print predicate if (RDFUtil.sameTerm(RDF.PropertyType, main.getPredicate())) { p.print("a"); } else { TupleImpl.print(getModel(), main.getPredicate(), p); } p.print(" "); // Print object if (nextIsMatchingVarPattern(main, elements, i)) { List <IResource> rightList = new List <IResource>(); i = addListMembers(elements, i + 1, rightList); if (rightList.Count == 0) { TupleImpl.print(getModel(), main.getObject(), p); if (leftList.Count != 0) { i--; } } else { printRDFList(p, rightList); i--; } } else { TupleImpl.print(getModel(), main.getObject(), p); } return(i); }
internal void SortProperties(List <Resource> propertyList) { propertyList.Sort(delegate(Resource x, Resource y) { if (RDFUtil.sameTerm(x, y)) { return(0); } if (ContainsTriple(x, RDFS.PropertySubPropertyOf, y)) { return(1); } return(-1); }); }
internal void SortClasses(List <Resource> classList) { classList.Sort(delegate(Resource x, Resource y) { if (RDFUtil.sameTerm(x, y)) { return(0); } if (ContainsTriple(x, RDFS.PropertySubClassOf, y)) { return(1); } return(-1); }); }
public Dictionary <IResource, IResource> getArgumentsMap() { /*sealed*/ Dictionary <IResource, IResource> values = new Dictionary <IResource, IResource>(); IEnumerator <Triple> it = listProperties().GetEnumerator(); while (it.MoveNext()) { Triple s = it.Current; if (!RDFUtil.sameTerm(RDF.PropertyType, s.Predicate)) { values[Resource.Get(s.Predicate, getModel())] = Resource.Get(s.Object, getModel()); } } return(values); }
/** * Checks if a given INode might represent a Function call, and if * yes returns the resource as Function. The condition here is fairly * general: a function call must be a blank node with an rdf:type triple * where the type triple's object is a URI resource. It is generally * assumed that this function is called after other options have been * exhausted. For example, in order to test whether a resource is a * variable or a function call, the variable test must be done first * as it is more specific than these test conditions * @param resource the INode to test * @return resource as a Function or null if resource cannot be cast */ public static IFunctionCall asFunctionCall(IResource resource) { if (resource == null) { return(null); } if (resource is IBlankNode) { IResource t = resource.getResource(RDF.PropertyType); if (t != null && !RDFUtil.sameTerm(SP.ClassVariable, t)) { return((IFunctionCall)resource.As(typeof(FunctionCallImpl))); } } return(null); }
/* * * 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); }
/** * Gets a Template with a given URI in its defining Model. * @param uri the URI of the Template to look up * @param model an (optional) Model that should also be used for look up * @return a Template or null */ public static ITemplate getTemplate(Uri uri, SpinProcessor model) { if (model != null) { IResource r = Resource.Get(RDFUtil.CreateUriNode(uri), model); if (r.hasProperty(RDF.PropertyType, SPIN.ClassTemplate)) { return((ITemplate)r.As(typeof(TemplateImpl))); } } if (templates.ContainsKey(uri)) { return(templates[uri]); } return(null); }
private String getPrefix(Uri ns, ISparqlPrinter context) { String prefix = getSource().Graph.NamespaceMap.GetPrefix(ns); if (prefix == null && context.getUseExtraPrefixes()) { INamespaceMapper extras = ExtraPrefixes.getExtraPrefixes(); foreach (String extraPrefix in extras.Prefixes) { Uri extraNs = extras.GetNamespaceUri(extraPrefix); if (RDFUtil.sameTerm(ns, extraNs)) { return(extraPrefix); } } } return(prefix); }
// 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); }
/** * Gets an spl:Attribute defined for a given property on a given class. * The spl:Attribute must be a direct spin:constraint on the class. * @param cls the class * @param property the property * @return the Attribute or null if none is found */ public static IAttribute getAttribute(IResource cls, INode property) { IEnumerator <Triple> it = cls.listProperties(SPIN.PropertyConstraint).GetEnumerator(); while (it.MoveNext()) { IResource obj = Resource.Get(it.Current.Object, cls.getModel()); if (obj is INode && ((IResource)obj).hasProperty(RDF.PropertyType, SPL.ClassAttribute)) { IAttribute a = (IAttribute)obj.As(typeof(AttributeImpl)); if (RDFUtil.sameTerm(property, a.getPredicate())) { it.Dispose(); return(a); } } } return(null); }
private int addListMembers(List <IElement> elements, int i, List <IResource> members) { bool first = true; while (i < elements.Count - 1 && elements[i] is ITriplePattern && elements[i + 1] is ITriplePattern) { ITriplePattern firstPattern = (ITriplePattern)elements[i]; ITriplePattern secondPattern = (ITriplePattern)elements[i + 1]; if (RDFUtil.sameTerm(RDF.PropertyFirst, firstPattern.getPredicate()) && RDFUtil.sameTerm(RDF.PropertyRest, secondPattern.getPredicate())) { IResource firstSubject = firstPattern.getSubject(); IResource secondSubject = secondPattern.getSubject(); if (firstSubject is IVariable && secondSubject is IVariable) { IVariable firstVar = (IVariable)firstSubject; IVariable secondVar = (IVariable)secondSubject; if (firstVar.isBlankNodeVar() && firstVar.getName().Equals(secondVar.getName())) { members.Add(firstPattern.getObject()); IResource secondObject = secondPattern.getObject(); i++; if (RDFUtil.sameTerm(RDF.Nil, secondObject)) { return(i + 1); } } } } // We are not in a valid list if (first && members.Count == 0) { break; } first = false; i++; } return(i); }
public static void print(SpinProcessor model, IResource node, ISparqlPrinter p, bool abbrevRDFType) { // TODO find the good tests ????? if (!node.isLiteral()) { if (abbrevRDFType && RDFUtil.sameTerm(RDF.PropertyType, node)) { p.print("a"); } else { printVarOrResource(p, node); } } else { //TODO INamespaceMapper pm = p.getUsePrefixes() ? model.getGraph().getPrefixMapping() : SPINExpressions.emptyPrefixMapping; String str = node.getSource().ToString();// TODO is this correct ? // FmtUtils.stringForNode(node, null/*TODO pm*/); p.print(str); } }
override public void Print(ISparqlPrinter p) { p.printKeyword("SERVICE"); IVariable var = getServiceVariable(); if (var != null) { p.print(" "); p.printVariable(var.getName()); } else { Uri uri = getServiceURI(); if (uri != null) { p.print(" "); p.printURIResource(Resource.Get(RDFUtil.CreateUriNode(uri), getModel())); } } printNestedElementList(p); }
override public void Print(ISparqlPrinter p) { IResource function = getFunction(); List <IResource> args = getArguments(); String symbol = getSymbol(function); //TODO implement isLetter if (symbol != null && (/*TODO !symbol[0].isLetter() ||*/ isSetOperator(symbol))) { printOperator(p, symbol, args); } else if (symbol != null && (RDFUtil.sameTerm(SP.PropertyExists, function) || RDFUtil.sameTerm(SP.PropertyNotExists, function))) { printExistsOrNotExists(p, symbol); } else { printFunction(p, function, args); } }
/** * Gets a registered Function with a given URI. * @param uri the URI of the Function to get * @param model an (optional) Model that should also be used to look up * locally defined functions (currently not used) * @return the Function or null if none was found */ public static IFunction getFunction(Uri uri, SpinProcessor model) { IFunction function = null; if (functions.ContainsKey(uri)) { function = functions[uri]; } if (function != null) { return(function); } if (model != null) { function = (IFunction)Resource.Get(RDFUtil.CreateUriNode(uri), model).As(typeof(FunctionImpl)); if (function.hasProperty(RDF.PropertyType, SPIN.ClassFunction)) { return(function); } } return(null); }
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()))); }
// TODO check whether transactions are supported by the storage provider to make those as atomical as possible /// <summary> /// Flushes changes to the dataset /// TODO handle dataset changes as updates instread of overwriting it to make it workable in a concurrent environment. /// </summary> public void Flush() { if (!Configuration.IsChanged) { return; } // TODO check if the updates did not raise any constraint violation, otherwise reject the Flush request // TODO related to the concurrency policy problem : handle any concurrent updates may have happened and succeded between the first modification and here SpinDatasetDescription updatedSourceDataset = new SpinDatasetDescription(Configuration.SourceUri); updatedSourceDataset.Assert(Configuration.GetTriplesWithPredicateObject(RDF.PropertyType, SPIN.ClassLibraryOntology)); updatedSourceDataset.Assert(Configuration.GetTriplesWithPredicateObject(RDF.PropertyType, SD.ClassGraph)); foreach (SpinWrappedGraph g in Configuration.ModificableGraphs) { Uri updatedGraphUri = Configuration.GetUpdateControlUri(g.BaseUri); Uri sourceGraph = g.BaseUri; if (Configuration.IsGraphReplaced(sourceGraph)) { Storage.Update("WITH <" + updatedGraphUri.ToString() + "> DELETE { ?s <" + RDFRuntime.PropertyResets.Uri.ToString() + "> ?p } WHERE { ?s <" + RDFRuntime.PropertyResets.Uri.ToString() + "> ?p }"); // For safety only Storage.Update("MOVE GRAPH <" + updatedGraphUri.ToString() + "> TO <" + sourceGraph.ToString() + ">"); } else if (Configuration.IsGraphUpdated(sourceGraph)) { Storage.Update("DELETE { GRAPH <" + updatedGraphUri.ToString() + "> { ?s <" + RDFRuntime.PropertyResets.Uri.ToString() + "> ?p } . GRAPH <" + sourceGraph.ToString() + "> { ?s ?p ?o } } USING <" + updatedGraphUri.ToString() + "> USING NAMED <" + g.BaseUri.ToString() + "> WHERE { ?s <" + RDFRuntime.PropertyResets.Uri.ToString() + "> ?p . GRAPH <" + g.BaseUri.ToString() + "> { ?s ?p ?o} }"); Storage.Update("ADD GRAPH <" + updatedGraphUri.ToString() + "> TO <" + sourceGraph.ToString() + ">"); } else { updatedSourceDataset.Retract(Configuration.GetTriplesWithSubject(RDFUtil.CreateUriNode(sourceGraph))); } } // TODO update the original dataset instead of overwriting it Storage.SaveGraph(updatedSourceDataset); DisposeUpdateControlledDataset(); }
private IResource[] getArgumentProperties(Dictionary <IResource, IResource> values) { IResource[] ps = new IResource[values.Count]; List <IResource> others = new List <IResource>(); foreach (IResource p in values.Keys) { if (p.Uri.ToString().StartsWith(SP_ARG) && !RDFUtil.sameTerm(p, SP.PropertyArg)) { int index = int.Parse(p.Uri.ToString().Substring(SP_ARG.Length)); ps[index - 1] = p; } else { others.Add(p); } } if (others.Count > 0) { others.Sort(delegate(IResource arg0, IResource arg1) { //TODO is that OK ? return(RDFUtil.uriComparer.Compare(arg0.Uri, arg1.Uri)); } ); IEnumerator <IResource> it = others.GetEnumerator(); for (int i = 0; i < ps.Length; i++) { if (ps[i] == null) { ps[i] = it.Current; } } } return(ps); }
/** * Checks if a given INode can be cast into an ElementList. * It must be either rdf:nil or an rdf:List where the first * list item is an element using <code>asElement()</code>. * @param resource the resource to test * @return true if resource is an element list */ public static bool isElementList(IResource resource) { if (resource.isUri() && RDFUtil.sameTerm(RDF.Nil, resource)) { return(true); } else { return(resource.hasProperty(RDF.PropertyFirst)); /* * ITriple firstS = Model.getProperty(Model, resource, RDF.first); * if (firstS != null && !(firstS.Object is ILiteralNode)) * { * INode first = firstS.Object; * return asElement(first) != null; * } * else * { * return false; * } */ } }
private ISparqlPath createPath(IResource path) { if (path.isUri()) { return(new Property(path.getSource())); } else { IResource typeS = path.getResource(RDF.PropertyType); if (typeS != null && typeS.isUri()) { INode type = typeS; if (RDFUtil.sameTerm(SP.ClassAltPath, type)) { ISparqlPath leftPath = createPath(path, SP.PropertyPath1); ISparqlPath rightPath = createPath(path, SP.PropertyPath2); return(new AlternativePath(leftPath, rightPath)); } else if (RDFUtil.sameTerm(SP.ClassModPath, type)) { ISparqlPath subPath = createPath(path, SP.PropertySubPath); int? min = path.getInteger(SP.PropertyModMin); int? max = path.getInteger(SP.PropertyModMax); if (max == null || max < 0) { if (min == 1) { return(new OneOrMore(subPath)); // TODO: is this correct? } else if (min == null || min == -1) { return(new ZeroOrMore(subPath)); } else { // -2 return(new NOrMore(subPath, (int)min)); // TODO: is this correct? } } else { if (min == null || min == -1) { return(new ZeroToN(subPath, (int)max)); } else { return(new NToM(subPath, (int)min, (int)max)); } } } else if (RDFUtil.sameTerm(SP.ClassReversePath, type)) { ISparqlPath subPath = createPath(path, SP.PropertySubPath); return(new InversePath(subPath)); } else if (RDFUtil.sameTerm(SP.ClassSeqPath, type)) { ISparqlPath leftPath = createPath(path, SP.PropertyPath1); ISparqlPath rightPath = createPath(path, SP.PropertyPath2); return(new SequencePath(leftPath, rightPath)); } else if (RDFUtil.sameTerm(SP.ClassReverseLinkPath, type)) { IResource node = path.getObject(SP.PropertyNode); ISparqlPath subPath = createPath(node); // TODO: is this correct ? return(new InversePath(subPath)); } } return(null); } }