I've got an ontology with the objects ( NamedIndividual
) and their coordinates (X,Y) in form of datatype
. The individual look like this:
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/PredefinedOntology#Door1">
<rdf:type rdf:resource="http://www.semanticweb.org/PredefinedOntology#Objects"/>
<Y rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">20</Y>
<X rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">33</X>
</owl:NamedIndividual>
I do a SPARQL query:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX onto: <http://www.semanticweb.org/PredefinedOntology#>
SELECT ?objects ?X ?Y
WHERE {
?objects rdf:type owl:NamedIndividual
; onto:X ?X
; onto:Y ?Y
FILTER regex(str(?objects),"Door1")
}
My query in Eclipse is this:
Model model = FileManager.get().loadModel("/home/aidos/workspace/OntologicalFramework/files/ontologies/NewOnt.owl");
String queryString = "//THE QUERY I'VE WRITTEN ABOVE IN A STRING FORM"
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results = qexec.execSelect();
ResultSetFormatter.out(System.out, results, query);
This gives me back a result set printed to the console of my IDE, like:
--------------------------
| objects | X | Y |
==========================
| onto:Window1 | 56 | 28 |
--------------------------
What I need is to get those integers 56 and 28 and store them in the int x
and int y
. Could someone help me to understand how can I get them? While debugging process I've found the DataSetImpl
called dataset
in the branch of ResultSet result
Each ResultSet provides access to each row as a QuerySolution through use of the next() method. Then, you can use methods like getLiteral(String) to get the literal value of the variable with a specified name. There are some other methods for getting variable values, too: get(String) returns an RDFNode , and getResource(String) returns a Resource .
In this case, you could use get() or getLiteral() since the numbers are literals, and thus RDF nodes, but you can't use getResource() , since the numbers aren't resources (ie, not IRIs).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.