1

How to convert this simple query to Jena java query builder?

SELECT ?city 
WHERE { <<:athens :connected ?city >>  :distance  500}

I tried this in Clojure and it didn't work. No need to write Clojure i just need the Java code.
I created a TipleNode and gave it as subject to a a Triple that i added to Where, but it complains about the subject.

Error : 
Caused by: java.lang.IllegalArgumentException: Subject (<< https://squery.org/joy/athens @https://squery.org/joy/connected ?city >>) 
must be a URI, blank, variable, or a wildcard. 
Is a prefix missing?  Prefix must be defined before use. 
(->
  (SelectBuilder.)
  (.addVar "?city")
  (.addWhere
    (Triple/create
      (NodeFactory/createTripleNode
        (.asNode (ResourceFactory/createResource "https://squery.org/joy/athens"))
        (.asNode (ResourceFactory/createProperty "https://squery.org/joy/connected"))
        (.asNode (Var/alloc "city")))
      (.asNode (ResourceFactory/createProperty "https://squery.org/joy/distance"))
      (.asNode (ResourceFactory/createTypedLiteral 500))))
  .build
  .toString
  println)
Takis
  • 8,314
  • 2
  • 14
  • 25
  • 1
    If you don't get an answer here, try asking on the Jena users list (subscribe first). users@jena.apache.org : https://jena.apache.org/help_and_support/index.html – AndyS May 20 '23 at 11:52
  • 1
    The query builder works with nodes and triples added to patterns. Triple can contain variables (class `Var`). So create a `Node_Triple` using `NodeFactory`, and add it as the subject of the triple you want in the WHERE clause. – AndyS May 20 '23 at 11:54
  • @AndyS This is what i did, and i couldn't make it work it complains about the Subject, i am new in Jena i hope i am not asking something obvious, i added my code, if possible can you add an example with java code? Thank you for the emails list. – Takis May 20 '23 at 16:06
  • i downloaded the source code of jena, and i tried it locally, in the querybuilder, in the Handlers, there is a whereHandler and a function called private static void testTriple(TriplePath t), i commented the throw and it worked, maybe that function is not updated for the RDF-star?.Thank you for helping me, if you can check it sometime, maybe i did something wrong, but this seems to fix it. – Takis May 20 '23 at 20:17
  • 1
    Probably isn't updated for RDF-star. Ask on the Jena users list. More likely to be QueryBuilder users there. – AndyS May 20 '23 at 21:11
  • created an issue https://github.com/apache/jena/issues/1874 – Takis May 20 '23 at 22:11

0 Answers0