我有這樣的Java代碼,使用Apache耶拿API,查詢比薩餅本體獲取後,才從SPARQL查詢 「#」
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
美國
如何獲得這樣的結果?
我想應該有一個更多的鏈接到這些項目的文本 – Randy
@Randy對不起,我不明白,我是新的SPARQL,這是什麼意思? –
我在猜測他的意思是你不應該試圖將#後面的那個位用作資源的「人類可讀名稱」。相反,您應該查詢連接到每個URI的'rdfs:label'屬性。 –