[英]SPARQL: get all Predicates and their respective Objects and organize them into a List
我正在尋找一種使用Jena框架將此查詢的結果添加到2D字符串列表中的方法。
sparqlQueryString="
select distinct ?p ?o where
{
<http://dbpedia.org/resource/NVA_(film)> ?p ?o
}
";
第一行包含屬性,第二行包含相應的實例。 問題在於屬性可能有許多實例。
List<List<String>> results= new ArrayList<List<String>>();
query = QueryFactory.create(sparqlQueryString);
qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
s = qexec.execSelect();
res = ResultSetFactory.copyResults(s);
while(res.hasNext())
{
QuerySolution so = res.nextSolution();
results.add(so.getResource("p").toString());
// The part I am looking for to add instance
}
// the results expected
results.get(0) = http://www.w3.org/1999/02/22-rdf-syntax-ns#type
results.get(0).get(0) = http://dbpedia.org/class/yago/2005Films
results.get(0).get(1) = http://www.w3.org/2002/07/owl#Thing
results.get(0).get(2) = http://dbpedia.org/ontology/Work
@AKSW:服務器端解決方案:SPARQL 1.1功能GROUP_CONCAT(有關示例,請參見W3C建議)。 客戶端解決方案:Java基礎。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.