我有这个java代码,使用apache jena api查询比萨本体
String queryStr =
"prefix pizza: <" + PIZZA_NS + "> " +
"prefix rdfs: <" + RDFS.getURI() + "> " +
"prefix owl: <" + OWL.getURI() + "> " +
"select ?pizza where {?pizza a owl:Class ; " +
"rdfs:subClassOf ?restriction. " +
"?restriction owl:onProperty pizza:hasTopping ;" +
"owl:someValuesFrom pizza:PeperoniSausageTopping" +
"}";
Query query = QueryFactory.create(queryStr);
QueryExecution qe = QueryExecutionFactory.create(query, model);
ResultSet rs = qe.execSelect();
ArrayList rsList = (ArrayList)ResultSetFormatter.toList(rs);
for(int i=0;i<rsList.size();i++){
out.println(rsList.get(i).toString());
}
它返回:
( ?pizza = <http://www.co-ode.org/ontologies/pizza/pizza.owl#AmericanHot> )
( ?pizza = <http://www.co-ode.org/ontologies/pizza/pizza.owl#FourSeasons> )
( ?pizza = <http://www.co-ode.org/ontologies/pizza/pizza.owl#American> )
但我只需要
AmericanHot
FourSeasons
美国
如何获得此结果?
答案 0 :(得分:5)
for ( ; rs.hasNext() ; ){
QuerySolution soln = rs.nextSolution() ;
RDFNode x = soln.get("pizza") ;
out.println(x.asNode().getLocalName());
}
对于谁会有同样的问题,其他信息可以从here
中检索答案 1 :(得分:3)
SPARQL 1.1函数STRAFTER可以提供帮助:
SELECT ?pizza (strafter(str(?pizza), "#") AS ?localName)
WHERE
但是客户端解决方案同样适用于SPARQL 1.0。