My problem is similar to the one asked on this question: Is there a differense between a CONSTRUCT queries sent to a virtuoso endpoint and one sent to a Jena one?
I am using Virtuoso opensource as my graphstore and using the jena provider in order to access the data in that graphstore. I am doing several querys and everything is working fine (except for the amazing amount of memory and time that takes every inference with virtuoso but that should go in another question...).
The problem came when I tried to generate a model using a construct query. I have try using the VirtuosoQueryExecutionFactory
and the query as string and the default QueryExecutionFactory
with the query factory:
qexec = VirtuosoQueryExecutionFactory.create(queryString,inputModel);
model = qexec.execConstruct();
And
Query query = QueryFactory.create(queryString);
qexec = QueryExecutionFactory.create(query,inputModel);
model = qexec.execConstruct();
The query gives the expected result in the sparql endpoint but an empty model when querying in the code.
LOGGER.info("The model is: {}", model);
LOGGER.info("The size is: {}", model.size());
Gives the following output:
The model is: <ModelCom {} | >
The size is: 0
The model where I execute the querys is not empty and I did the same query from the sparql endpoint, as I said, recieving the spected results.
Anyone know where could be the mistake?
Thanks.
Daniel.
EDIT: Here is the query I am trying to execute.
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl:<http://www.w3.org/2002/07/owl#>
PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>
PREFIX spatiaCore:<http://www.cedint.upm.es/residentialontology.owl#>
PREFIX test:<http://test.url#>
PREFIX spatiaCore: <http://www.cedint.upm.es/residentialontology.owl#>
CONSTRUCT {
?u ?p ?o1.
?o1 ?p2 ?o2.
?o2 ?p3 ?o3.
?o3 ?p4 ?o4.
?o4 ?p5 ?o5.
?o6 ?p6 ?u.
?o7 ?p7 ?o6
}
WHERE {
?u rdf:type spatiaCore:User.
?u spatiaCore:id "0000000003B3B474"^^<http://www.w3.org/2001/XMLSchema#string>.
?u ?p ?o1.
OPTIONAL {
?o1 ?p2 ?o2.
OPTIONAL {
?o2 ?p3 ?o3.
OPTIONAL {
?o3 ?p4 ?o4.
OPTIONAL {
?o4 ?p5 ?o5.
}
}
}
}
OPTIONAL {
?o6 ?p6 ?u.
OPTIONAL {
?o7 ?p7 ?o6
}
}
}
As you can see, the query tries to construct a graph with all the nodes the user is linked to with a depth of max five relationships and the nodes that are linked to the user with a depth of max two relationships.