我已经有了对象(NamedIndividual
)及其坐标(X,Y)的本体形式datatype
。个人看起来像这样:
<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>
我执行一个SPARQL查询:
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")
}
我在Eclipse中的查询是这样的:
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);
这给了我一个打印到我的IDE控制台的结果集,例如:
--------------------------
| objects | X | Y |
==========================
| onto:Window1 | 56 | 28 |
--------------------------
我需要获取这些整数56和28并将它们存储在int x
and中int y
。有人可以帮助我了解如何获得他们吗?在调试过程中,我发现了DataSetImpl
所谓dataset
的分支ResultSet result
通过使用next()方法,每个ResultSet都可以作为QuerySolution提供对每一行的访问。然后,可以使用诸如getLiteral(String)之类的方法来获取具有指定名称的变量的文字值。还有其他一些获取变量值的方法:get(String)返回一个RDFNode,而getResource(String)返回一个Resource。
在这种情况下,您可以使用get()或getLiteral(),因为数字是文字,因此是RDF节点,但是您不能使用getResource(),因为数字不是资源(即,不是IRI)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句