Hey Holger, thanks for the explanation. I'm using SPIN API in the implementation of Graphity Linked Data platform which has the following processing model: - request URI is matched against resource templates (classes) in a sitemap ontology like this one: https://raw.github.com/Graphity/graphity-ldp/rf-input-mode/src/main/resources/org/graphity/platform/ontology/sitemap.ttl - each of the template classes has a DESCRIBE/CONSTRUCT spin:Template attached to it via spin:constraint. Common SPIN Templates are grouped in a separate ontology: https://raw.github.com/Graphity/graphity-ldp/rf-input-mode/src/main/resources/org/graphity/platform/vocabulary/gp.ttl Each of the templates also indicate the source RDF dataset of the resource, which normally has a SPARQL endpoint. - SPARQL query string is generated from the TemplateCall, the request URI is bound to ?this variable afterwards, and the query is executed on the endpoint of the dataset of the resource - the result RDF is returned as the response (if the resource matched no template or the query result is empty, 404 is returned)
Having an RDFNode of the spin:constraint object, I'm converting it to TemplateCall using SPINFactory.asTemplateCall() and run getQueryString() to generate the SPARQL query string. Around line #400 here: https://github.com/Graphity/graphity-ldp/blob/rf-input-mode/src/main/java/org/graphity/platform/model/ResourceBase.java Afterwards I'm binding ?this variable to a URI value using simple string replacement. If there is a better alternative to generate SPARQL query strings from TemplateCall (and maybe bind variable(s) to URIs at the same time), I will be happy to refactor my code. Martynas graphity.org 2013 m. kovas 18 d., pirmadienis 02:16:52 UTC+2, Holger Knublauch rašė: > > Hi Martynas, > > this is indeed not working correctly (in the current SPIN API release > 1.3.0). The role of this method is to return a parsable query string > with the given variables of the template call pre-bound. The problem is > that the current code is expecting to apply variable substitutions while > printing the query string from the RDF tree. However, if no RDF tree > exists, it simply returns the sp:text unchanged. > > I believe I can provide a partial fix, but thinking more about this > method I am wondering whether it should be deprecated altogether or at > least have some severe warnings around it. Background: SPIN constraints > and inferencing algorithms do not use this mechanism (of hard-wiring the > variables in the query string) because it is comparably slow (to create > the new strings each time - they are hard to cache) and because there > are cases where the approach doesn't work in general. Consider you have > a bound(?x) statement in the WHERE clause, but then ?x is pre-bound: it > would create a non-parsable string. The approach that SPIN API uses in > most other places is to keep the query strings (or Query objects) and > the initial bindings in separate structures, and then let the Jena > engine do the substitution at run-time - not only the query String but > on the Query and algebra objects. > > So before we can make a decision on the future of this > TemplateCall.getQueryString method: could you clarify what your use case > is and whether you could also soft-bind the substitutions? If you could > refactor your surrounding code then I could probably just deprecate this > method for good. > > Thanks > Holger > > > On 3/17/2013 5:56, [email protected] <javascript:> wrote: > > Hey Holger, > > > > I have a spin:Template with an argument (in gp: namespace): > > > > :DescribeInstancesTemplate a spin:Template ; > > spin:constraint [ a spl:Argument ; > > spl:predicate :type ; > > spl:valueType rdfs:Resource > > ] ; > > spin:body [ a sp:Describe, sp:Query ; > > sp:resultNodes (_:instanceVar) ; > > sp:text """DESCRIBE ?instance WHERE { > > { > > SELECT ?instance > > WHERE { > > ?instance a ?type . > > } > > } . > > }"""^^xsd:string ; > > sp:where ([ a sp:SubQuery ; > > # full RDF representation follows here > > > > _:instanceVar sp:varName "instance"^^xsd:string . > > > > When called it like this > > > > spin:constraint [ a gp:DescribeInstancesTemplate ; > > gp:type owl:Ontology > > ] ; > > > > I get the query I want (using the TemplateCall.getQueryString() method): > > > > DESCRIBE ?instance > > WHERE > > { { SELECT ?instance > > WHERE > > { ?instance <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> > > <http://www.w3.org/2002/07/owl#Ontology> } > > } > > } > > > > However, if I change the template's query to use spin:text only: > > > > :DescribeInstancesTemplate a spin:Template ; > > spin:constraint [ a spl:Argument ; > > spl:predicate :type ; > > spl:valueType rdfs:Resource > > ] ; > > spin:body [ a sp:Describe, sp:Query ; > > sp:text """DESCRIBE ?instance WHERE { > > { > > SELECT ?instance > > WHERE { > > ?instance a ?type . > > } > > } . > > }"""^^xsd:string ] . > > > > the ?type argument is not set: > > > > DESCRIBE ?instance > > WHERE > > { { SELECT ?instance > > WHERE > > { ?instance <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> > > ?type } > > } > > } > > > > Is that the expected behaviour or am I missing something? spin:text > > syntax is a really nice simplification, but I would expect Template > > and TemplateCall to work the same way. > > > > Martynas > > graphity.org > > -- > > -- You received this message because you are subscribed to the Google > > Group "TopBraid Suite Users", the topics of which include Enterprise > > Vocabulary Network (EVN), TopBraid Composer, TopBraid Live, > > TopBraid Ensemble, SPARQLMotion, SPARQL Web Pages and SPIN. > > To post to this group, send email to > > [email protected] <javascript:> > > To unsubscribe from this group, send email to > > [email protected] <javascript:> > > For more options, visit this group at > > http://groups.google.com/group/topbraid-users?hl=en > > --- > > You received this message because you are subscribed to the Google > > Groups "TopBraid Suite Users" group. > > To unsubscribe from this group and stop receiving emails from it, send > > an email to [email protected] <javascript:>. > > For more options, visit https://groups.google.com/groups/opt_out. > > > > > > -- -- You received this message because you are subscribed to the Google Group "TopBraid Suite Users", the topics of which include Enterprise Vocabulary Network (EVN), TopBraid Composer, TopBraid Live, TopBraid Ensemble, SPARQLMotion, SPARQL Web Pages and SPIN. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/topbraid-users?hl=en --- You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
