private bool templateContainsVar(IResource list) { if (list != null && !list.isLiteral()) { IEnumerator <IResource> nodes = list.AsList().GetEnumerator(); while (nodes.MoveNext()) { IResource node = nodes.Current; if (node.hasProperty(RDF.PropertyType, SP.ClassNamedGraph)) { INamedGraph namedGraph = (INamedGraph)node.As(typeof(NamedGraphImpl)); foreach (IElement element in namedGraph.getElements()) { if (element is ITriple) { if (containsVar((ITriple)element)) { return(true); } } } } else { if (containsVar((ITripleTemplate)node.As(typeof(TripleTemplateImpl)))) { return(true); } } } } return(false); }
/** * Checks if a given INode is a SPIN query, and returns an * instance of a subclass of Query if so. * @param resource the INode to test * @return resource as a Query or null */ public static IQuery asQuery(IResource resource) { if (resource == null) { return(null); } if (resource.canAs(SP.ClassSelect)) { return((IQuery)resource.As(typeof(SelectImpl))); } else if (resource.canAs(SP.ClassConstruct)) { return((IQuery)resource.As(typeof(ConstructImpl))); } else if (resource.canAs(SP.ClassAsk)) { return((IQuery)resource.As(typeof(AskImpl))); } else if (resource.canAs(SP.ClassDescribe)) { return((IQuery)resource.As(typeof(DescribeImpl))); } else { return(null); } }
/* * * Checks if a given INode is a subclass of sp:Update and * casts it into the most specific Java class possible. * @param resource the INode to cast * @return the Update or null if resource cannot be cast */ public static IUpdate asUpdate(IResource resource) { if (resource == null) { return(null); } if (resource.canAs(SP.ClassModify)) { return((IModify)resource.As(typeof(ModifyImpl))); } else if (resource.canAs(SP.ClassClear)) { return((IClear)resource.As(typeof(ClearImpl))); } else if (resource.canAs(SP.ClassCreate)) { return((ICreate)resource.As(typeof(CreateImpl))); } else if (resource.canAs(SP.ClassDeleteData)) { return((IDeleteData)resource.As(typeof(DeleteDataImpl))); } else if (resource.canAs(SP.ClassDeleteWhere)) { return((IDeleteWhere)resource.As(typeof(DeleteWhereImpl))); } else if (resource.canAs(SP.ClassDrop)) { return((IDrop)resource.As(typeof(DropImpl))); } else if (resource.canAs(SP.ClassInsertData)) { return((IInsertData)resource.As(typeof(InsertDataImpl))); } else if (resource.canAs(SP.ClassLoad)) { return((ILoad)resource.As(typeof(LoadImpl))); } #pragma warning disable 612 else if (resource.canAs(SP.ClassDelete)) { return((IDelete)resource.As(typeof(DeleteImpl))); } else if (resource.canAs(SP.ClassInsert)) { return((IInsert)resource.As(typeof(InsertImpl))); } #pragma warning restore 612 else { return(null); } }
/** * Converts a given INode into a Template instance. * No other tests are done. * @param resource the INode to convert * @return the Template */ public static ITemplate asTemplate(IResource resource) { if (resource == null) { return(null); } return((ITemplate)resource.As(typeof(TemplateImpl))); }
/** * Converts a given INode into a Function instance. * No other tests are done. * @param resource the INode to convert * @return the Function */ public static IFunction asFunction(IResource resource) { if (resource == null) { return(null); } return((IFunction)resource.As(typeof(FunctionImpl))); }
private void Unload(IResource resource) { IDisposable disposable = resource.As <IDisposable>(); if (disposable != null) { disposable.Dispose(); } }
private void addTriplePatterns(INode predicate, HashSet <ITriplePattern> results) { IEnumerator <Triple> it = getModel().GetTriplesWithPredicateObject(predicate, this).GetEnumerator(); while (it.MoveNext()) { IResource subject = Resource.Get(it.Current.Subject, getModel()); results.Add((TriplePatternImpl)subject.As(typeof(TriplePatternImpl))); } }
override public IModule getModule() { IResource function = getFunction(); if (function != null) { return((IModule)function.As(typeof(FunctionImpl))); } else { return(null); } }
public IVariable getVariable() { IResource var = getResource(SP.PropertyVariable); if (var != null) { return((IVariable)var.As(typeof(VariableImpl))); } else { return(null); } }
public IValues getValues() { IResource values = getResource(SP.PropertyValues); if (values != null) { return((IValues)values.As(typeof(ValuesImpl))); } else { return(null); } }
/** * Checks whether a given INode can be cast into a Variable and - if yes - * converts it into an instance of Variable. The INode must have a value * for spin:varName. * @param node the node to check * @return resource as a Variable or null */ public static IVariable asVariable(IResource resource) { if (resource == null) { return(null); } if (resource.hasProperty(SP.PropertyVarName)) { return((IVariable)resource.As(typeof(VariableImpl))); } else { return(null); } }
protected void printNestedElementList(ISparqlPrinter p, INode predicate) { p.print(" {"); p.println(); IResource elementsRaw = getObject(predicate); if (elementsRaw != null) { IElementList elements = (IElementList)elementsRaw.As(typeof(ElementListImpl)); p.setIndentation(p.getIndentation() + 1); elements.Print(p); p.setIndentation(p.getIndentation() - 1); } p.printIndentation(p.getIndentation()); p.print("}"); }
/** * 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); }
/** * 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); }
// 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); }
/** * Checks whether a given INode can be cast into TemplateCall, and returns * it as a TemplateCall instance if so. * @param node the node to convert * @return an instance of TemplateCall or null */ public static ITemplateCall asTemplateCall(IResource resource) { if (resource == null) { return(null); } if (!resource.isLiteral()) { IResource t = resource.getResource(RDF.PropertyType); if (t != null && t.isUri()) { ITemplate template = SPINModuleRegistry.getTemplate(t.Uri, t.getModel()); if (template != null) { return((ITemplateCall)resource.As(typeof(TemplateCallImpl))); } } } return(null); }
private void Unload(IResource resource) { IDisposable disposable = resource.As<IDisposable>(); if (disposable != null) disposable.Dispose(); }
/** * Checks whether a given INode represents a SPARQL element, and returns * an instance of a subclass of Element if so. * @param resource the INode to check * @return INode as an Element or null if resource is not an element */ public static IElement asElement(IResource resource) { if (resource == null) { return(null); } /*sealed*/ ITriplePattern triplePattern = asTriplePattern(resource); if (triplePattern != null) { return(triplePattern); } else if (resource.canAs(SP.ClassTriplePath)) { return((ITriplePath)resource.As(typeof(TriplePathImpl))); } else if (resource.canAs(SP.ClassFilter)) { return((IFilter)resource.As(typeof(FilterImpl))); } else if (resource.canAs(SP.ClassBind)) { return((IBind)resource.As(typeof(BindImpl))); } else if (resource.canAs(SP.ClassOptional)) { return((IOptional)resource.As(typeof(OptionalImpl))); } else if (resource.canAs(SP.ClassNamedGraph)) { return((INamedGraph)resource.As(typeof(NamedGraphImpl))); } else if (resource.canAs(SP.ClassMinus)) { return((IMinus)resource.As(typeof(MinusImpl))); } else if (resource.canAs(SP.ClassExists)) { return((IExists)resource.As(typeof(ExistsImpl))); } else if (resource.canAs(SP.ClassNotExists)) { return((INotExists)resource.As(typeof(NotExistsImpl))); } else if (resource.canAs(SP.ClassService)) { return((IService)resource.As(typeof(ServiceImpl))); } else if (resource.canAs(SP.ClassSubQuery)) { return((ISubQuery)resource.As(typeof(SubQueryImpl))); } else if (resource.canAs(SP.ClassUnion)) { return((IUnion)resource.As(typeof(UnionImpl))); } else if (resource.canAs(SP.ClassValues)) { return((IValues)resource.As(typeof(ValuesImpl))); } else if (isElementList(resource)) { return((IElementList)resource.As(typeof(ElementListImpl))); } else { return(null); } }