Hi Holger, Thank you very much for your help, your codes are working well in creating the Query object and returning the right Jena Query. I did not take the sub queries into account as this is not required yet in my application.
Kind regards, Hong 2012/5/1 Holger Knublauch <hol...@topquadrant.com> > Hi Hong, > > your starting point is an RDF string serialized in Turtle. So you first > need to convert that Turtle snippet to a Jena Model. The following code > should work, assuming source is your Turtle snippet. > > Model model = JenaUtil.createDefaultModel(); > model.read(new StringReader(source), "urn:x-dummy:base", > FileUtils.langTurtle); > > // Get the first instance of sp:Select * > Resource queryResource = model.listStatements(null, RDF.type, > SP.Select).next().getSubject()**; > org.topbraid.spin.model.Query spinQuery = SPINFactory.asQuery(** > queryResource); > > Now you have a SPIN query object that you can turn into either the string > or Jena Query object as shown in SPINParsingExamples. > > HTH > Holger > > * note that this is a bit brittle - the Model may contain another instance > of sp:Select as a nested sub-query. In that case, the query is more > complex, and you would need to get the instance of sp:Select that has no > incoming triples, e.g. !model.contains(null, null, queryResource) > > > > On 4/30/2012 18:37, Hong Sun wrote: > >> Dear All, >> >> I am now looking for a method to in the SPIN API open source to >> convert the SPIN RDF syntax string below to Jena Query. >> >> @prefix ex:<http://example.org/demo#> . >> @prefix >> rdf:<http://www.w3.org/1999/**02/22-rdf-syntax-ns#<http://www.w3.org/1999/02/22-rdf-syntax-ns#>> >> . >> >> [] a<http://spinrdf.org/sp#Select**> ; >> >> <http://spinrdf.org/sp#**resultVariables<http://spinrdf.org/sp#resultVariables> >> > >> (_:b1) ; >> <http://spinrdf.org/sp#where> >> ([<http://spinrdf.org/sp#**object<http://spinrdf.org/sp#object> >> > >> ex:Person ; >> >> <http://spinrdf.org/sp#**predicate<http://spinrdf.org/sp#predicate> >> > >> rdf:type ; >> <http://spinrdf.org/sp#subject**> >> _:b1 >> ]) . >> >> _:b1<http://spinrdf.org/sp#**varName <http://spinrdf.org/sp#varName>> >> >> "person"^^<http://www.w3.org/**2001/XMLSchema#string<http://www.w3.org/2001/XMLSchema#string>> >> . >> >> The online service (SPIN RDF Syntax to SPARQL Text Converter) >> http://spinservices.org/**spinrdfconverter.html<http://spinservices.org/spinrdfconverter.html>provides >> the desired >> function. But which method (in the SPIN API open source) should I use >> to create a Query object with the String text stated above? (e.g. a >> counterpart of ARQFactory.get().createQuery() to create Query based on >> SPIN syntax) >> >> Thanks in advance! >> >> Hong >> >> > -- > 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 and SPIN. > To post to this group, send email to > topbraid-users@googlegroups.**com <topbraid-users@googlegroups.com> > To unsubscribe from this group, send email to > topbraid-users+unsubscribe@**googlegroups.com<topbraid-users%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/**group/topbraid-users?hl=en<http://groups.google.com/group/topbraid-users?hl=en> > -- 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 and SPIN. To post to this group, send email to topbraid-users@googlegroups.com To unsubscribe from this group, send email to topbraid-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/topbraid-users?hl=en