0

Apache Jena is not able to query RDF Star Triples that have a double data type in them. Here is the code for reproduction of the issue with Jena 3.17 (it can be reproduced on other versions too).

Dataset dataset = TDB2Factory.createDataset();
Model tempModel = ModelFactory.createDefaultModel();
StringReader reader = new StringReader("@prefix : <http://ex#> "
                                     + "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> "
                                     + ":rk :val \"1.0\"^^xsd:double ."
                                     + "<<:rk :val \"1.0\"^^xsd:double>> :p_key 1");
RDFDataMgr.read(tempModel, reader, null, Lang.TURTLE);

dataset.begin(TxnType.WRITE);
Graph repositoryGraph = dataset.getNamedModel("RAW_MODEL").getGraph();
StmtIterator it = tempModel.listStatements();
while(it.hasNext()) {
    repositoryGraph.add(it.nextStatement().asTriple());
}
dataset.commit()
dataset.end()

Now during query time, I am using the following code.

dataset.begin(TxnType.READ);
Query query = QueryFactory.create("SELECT ?s ?o ?id WHERE {"
                                + "<<?s <http://ex#val> ?o>> <http://ex#p_key> ?id"
                                + "}");
try (QueryExecution exec = QueryExecutionFactory.create(query, dataset.getUnionModel())) {
    ResultSet result = exec.execSelect();
    while (result.hasNext()) {
        System.out.println(result.next().toString());
    }
}
dataset.end()

The above query fails to fetch any result. However, if I just replace xsd:double with xsd:float or xsd:decimal the results are fetched. Hence, I am looking for help to understand what is causing this issue with xsd:double?

Note: You might think that I am not using the most optimal way to make insertions. However, this was due to other requirements in the code and reproduction of issue is possible through this route.

penguin2048
  • 1,303
  • 13
  • 25

1 Answers1

2

It works in Jena 4.0.0.

In 3.17.0 - SPARQL was more like the original RDF* in its use of indexing.

As a consequence, the non-canonical term map cause a problem.

Try a lexical form of "1.0e0"^^xsd:double or v 4.x.x.

AndyS
  • 16,345
  • 17
  • 21
  • I realized that Jena 4.0 uses Java 11, but unfortunately I only have an option of using Java 8. If possible can you point me to commits that fix this issue so I can patch v3.17 ? – penguin2048 Jun 02 '21 at 03:56
  • Out of curiosity, why are you restricted to java8? – AndyS Jun 02 '21 at 08:41
  • 1
    It isn't a point change - the defn of RDF-star became clear and the whole area was rewritten. It is simpler to take the latest source code [Early June 2021: 4.1.0 will be out in a few days and is up-to-date with the RDF-star community] and fix for Java8. There are very few places depending on Java11 at the moment. It is only some used of `Files.readAllBytes` (Java9) and Apache Commons FileUtils has `FileUtils.readFileToByteArray`. Over time this will change but currently, that is a lot less work than backporting the RDF-star code. – AndyS Jun 02 '21 at 09:06
  • Thanks! yes I guess compiling for Java8 will be a better option. I am restricted to v8 since I am running Jena on an Android device and Java 11 is a very recent addition to android community. Most of the other dependencies are not compatible with Java 11. – penguin2048 Jun 02 '21 at 15:24