Hi Andy, Many thanks for your support. > To understand the algebra, I suggest looking at the code.
I cloned Jena repo and I’m now looking at the jena-arq-examples module, thanks. > You don't need to manaipulate the algebra to build querys. It was in the tutorial, I thought it was more performant than string replacement (see next reply). > Jena has both a parameterized querystring (for templating) and a query builder > > https://jena.apache.org/documentation/query/parameterized-sparql-strings.html > https://jena.apache.org/documentation/extras/querybuilder/index.html I knew about parametrisation, but not about the query builder, many thanks! Are there noticeable differences in performance? Or an idiomatic approach to be preferred, amongst the two? > Node_Graph is unrelated. It is a placeholder for "graphs within graphs" (N3 > formulae) not for named graphs. > > As the javadoc says: > """ > * For experimentation. > * Otherwise, unsupported. > “"" Sorry, for some reason that Javadoc doesn’t pop up in eclipse (whereas, for instance, Graph does show even if they belong to same package) > For named graphs, the first argument is a graph name - usually a URI, > sometimes a blank node (JSON-LD). e.g. > <file:src/main/resources/dataset-named-graph-1.ttl> > > The dc:date is in the default graph so will not match something inside GRAPH. This is not clear to me. I am trying to reproduce query below from the official tutorial on ARQ PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX : </Users/sm/cdss-pathways/Cdss-pathways-tests/src/main/resources/> SELECT ?date ?title ?g { ?g dc:date ?date . FILTER (?date > "2005-08-01T00:00:00Z"^^xsd:dateTime ) GRAPH ?g { ?b dc:title ?title } } while using algebraic syntax, as an exercise to check my understanding (which is lacking as of now, evidently). I tried with BasicPattern pat = new BasicPattern(); // Make a pattern pattern = Triple.create(Var.alloc("g"), NodeFactory.createURI("http://purl.org/dc/elements/1.1/date"), Var.alloc("date")); pat.add(pattern); // Add our pattern match op = new OpBGP(pat); // Make a BGP from this pattern e = new E_GreaterThan(new ExprVar("date"), ExprUtils.nodeToExpr(NodeFactory.createLiteral( "2005-08-01T00:00:00Z", XSDDateTimeType.XSDdateTime))); op = OpFilter.filter(e, op); // Filter that pattern with our expression op = new OpProject(op, Arrays.asList(Var.alloc("date"), Var.alloc("title"), Var.alloc("g"))); // Reduce to just ?s Graph graph = GraphFactory.createDefaultGraph(); graph.add(Triple.create(Var.alloc("b"), NodeFactory.createURI("http://purl.org/dc/elements/1.1/title"), Var.alloc("title"))); Op opGraph = new OpGraph(Var.alloc("g"), op); Query q = OpAsQuery.asQuery(opGraph); // Convert to a query q.setQuerySelectType(); // Make is a select query try (QueryExecution qexec = QueryExecutionFactory.create(q, dataset)) { results = qexec.execSelect(); LOGGER.info( "----- q8d on dataset (programmatic: algebra-driven) ------"); ResultSetFormatter.out(System.out, results, query); } But I’ am getting no results at al, while result when executing from command line is ------------------------------------------------------------------------------------------------------------------ | s | p | o | g | ================================================================================================================== | :dataset-named-graph-1.ttl | dc:date | "2005-07-14T03:18:56+01:00"^^xsd:dateTime | | | :dataset-named-graph-2.ttl | dc:date | "2005-09-22T05:53:05+01:00"^^xsd:dateTime | | | _:b0 | dc:title | "Harry Potter and the Sorcerer's Stone" | :dataset-named-graph-2.ttl | | _:b1 | dc:title | "Harry Potter and the Chamber of Secrets" | :dataset-named-graph-2.ttl | | _:b2 | dc:title | "Harry Potter and the Chamber of Secrets" | :dataset-named-graph-1.ttl | | _:b3 | dc:title | "Harry Potter and the Philospher's Stone" | :dataset-named-graph-1.ttl | ————————————————————————————————————————————————————————— > Try this: > > q = QueryFactory.create( > "SELECT * { { ?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } } }”); This is another query from the tutorial, and this one works as intended. > The code in the gist does not compile. There are several compile time errors. > > Please - a complete, minimal example, including the data. Updated code, added datasets and Gradle file: https://gist.github.com/stemar87/c3e8cb6dfee92cd5f7ec8e304823e61f -------------------------------------------------------------------------------------------------------------------- Stefano Mariani, PhD Fixed-term research assistant (post-doc) @ Department of Sciences and Methods for Engineering – University of Modena and Reggio Emilia > [email protected] > http://personale.unimore.it/AddressBook/Home/s.mariani --------------------------------------------------------------------------------------------------------------------
