I'm currently working on a project where I need to graphically represent a SPARQL-DL query. To do that, I need to get all the entities used in a query (at the end, all the entities used in the query and the results from the query). I'm struggling with getting all the entities of the query. Is there an easy way to get all the atoms of the query ?
The library I'm using is OWL-API 4.2.8 with the latest SPARQL-DL-API. I'm using the Example_Basic.java
file to try my method.
Here's the query I used as an example (it gives me all the wines that are located in New Zealand):
PREFIX wine: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#>
SELECT ?wine
WHERE {
PropertyValue(?wine, wine:locatedIn, wine:NewZealandRegion)
}
the method I use :
extractAllQueryEntities(QueryResult result) {
List<QueryAtomGroup> queryAtomGroups = result.getQuery().getAtomGroups();
for (QueryAtomGroup queryAtomGroup : queryAtomGroups) {
List<QueryAtom> atoms = queryAtomGroup.getAtoms();
System.out.println("Size of the atoms: " + atoms.size());
Iterator<QueryAtom> queryAtom = atoms.iterator();
while (queryAtom.hasNext()) {
QueryAtom element = queryAtom.next();
System.out.println("atom: " + element);
List<QueryArgument> arguments = element.getArguments();
for (QueryArgument argument : arguments) {
System.out.println("type: " + argument.getType() + " : value: " + argument.getValueAsString());
}
}
}
}
and here's the result I get from my method:
Results:
.
.
.
some wines
.
.
.
Size of the atoms: 1
atom: PropertyValue(?de.derivo.sparqldlapi.Var@37b009, http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#locatedIn, http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#NewZealandRegion)
type: VAR : value: wine
type: URI : value: http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#locatedIn
type: URI : value: http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#NewZealandRegion