From: Claude Warren <[email protected]> Sent: Monday, May 30, 2022 12:41 PM To: [email protected] Cc: Goławski, Paweł <[email protected]> Subject: Re: Build Full Text Search query using SelectBuilder On 24/05/2022 11:01, Goławski, Paweł wrote: PREFIX ex: http://www.example.org/resources#<http://www.example.org/resources> PREFIX rdfs: http://www.w3.org/2000/01/rdf-schema#<http://www.w3.org/2000/01/rdf-schema> PREFIX text: http://jena.apache.org/text#<http://jena.apache.org/text> SELECT ?s ?lbl WHERE { ?s a ex:Product ; text:query (rdfs:label 'printer'); rdfs:label ?lbl }
To generate the above the following should work:
final SelectBuilder builder = new SelectBuilder();
final Query query = builder.setDistinct(true)
.addPrefix("ex",
"http://www.example.org/resources#"<http://www.example.org/resources>)
.addPrefix("rdf", RDF.uri).addPrefix("rdfs", RDFS.uri)
.addPrefix("text",
"http://jena.apache.org/text#"<http://jena.apache.org/text>)
.addVar("s")
.addVar("lbl")
.addWhere("?s", "rdf:type", "ex:Product ")
.addWhere("?s", "text:query", builder.list("rdfs:label",
"printer"))
.addWhere("?s", "rdfs:label", "?lbl")
.build();
There are a couple of changes from your code:
1. I removed the makeVar() calls and replaced with "?var".
2. Used the build list() method to create the list of variables.
3. Added the prefixes by hand since I didn't have your variable.
The query can also be written using Vars as:
final Var s = Converters.makeVar( "s" );
final Var lbl = Converters.makeVar( "lbl" );
final SelectBuilder builder = new SelectBuilder();
final Query query = builder.setDistinct(true)
.addPrefix("ex",
"http://www.example.org/resources#"<http://www.example.org/resources>)
.addPrefix("rdf", RDF.uri).addPrefix("rdfs", RDFS.uri)
.addPrefix("text",
"http://jena.apache.org/text#"<http://jena.apache.org/text>)
.addVar(s)
.addVar(lbl)
.addWhere(s, "rdf:type", "ex:Product ")
.addWhere(s, "text:query", builder.list("rdfs:label",
"printer"))
.addWhere(s, "rdfs:label", lbl)
.build();
Hope this helps,
Claude
Hi Claude.
Looks that is works.
Thanks a lot 😊
smime.p7s
Description: S/MIME cryptographic signature
