我試圖獲取有關DBpedia上某些概念的信息。我發現如何獲得1,但更多失敗。我被告知過濾應該有幫助,但處理時間太長,我得到超時。SPARQL Jena迭代以獲取有關更多主題的結果
我不能做的事情是值S {DBpedia中:Facebook的DBpedia中:谷歌}
所以我找了一個替代方式,但它仍然ISN;噸的工作?這裏就是我現在:
public static String concepts[] = { "Facebook", "Google" };
public static String getQuery(String concept) {
return "prefix dbpediaowl: <http://dbpedia.org/ontology/>"
+ " prefix dbpedia: <http://dbpedia.org/resource/>"
+ " prefix owl: <http://www.w3.org/2002/07/owl#>"
+ " prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
+ " PREFIX dbpprop: <http://dbpedia.org/property/>"
+ " prefix dbpedia-owl: <http://dbpedia.org/ontology/>"
+ " select ?s ?p ?o where { "
+ " values ?web { dbpedia:"
+ "Facebook"
+ " } "
+ " { ?web ?p ?o bind(?web as ?s) } " + " union "
+ " { ?s ?p ?web bind(?web as ?o) } " + " filter(?p in ("
+ "dbpprop:available, " + "dbpprop:company, "
+ "dbpprop:inventor, " + "dbpedia-owl:foundedBy, "
+ "dbpedia-owl:subsidiary, " + "dbpprop:foundation, "
+ "dbpprop:founder, " + "dbpprop:industry, "
+ "dbpprop:programmingLanguage, " + "dbpedia-owl:successor)) ";
}
public static void main(String[] args) {
OutputStream os;
PrintStream printStream;
try {
os = new FileOutputStream("C:/Users/alex/Desktop/data.txt");
printStream = new PrintStream(os);
printStream.println("am scris");
for (int i = 0; i < concepts.length; i++) {
printStream.println(i+ " concept");
Query query = QueryFactory.create(getQuery(concepts[i]));
QueryExecution qExe = QueryExecutionFactory.sparqlService(
"http://lod.openlinksw.com/sparql", query);
ResultSet results = qExe.execSelect();
while (results.hasNext()) {
printStream.println(results.nextSolution().toString());
}
}
printStream.close();
os.close();
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getCause());
}
}
對於每次一個概念,在SPARQL它工作正常,但我需要給他們打電話約50。所以我需要知道如何以編程方式進行。另外,如果你可以幫助我選擇謂詞(沒有過濾),那將是非常好的,因爲我還需要允許大約30-40個謂詞。
非常感謝!希望你能幫助。
問題過濾器是他們往往工作較慢和DBpedia的給我超時。我發現了一個更好的端點,它反映了DBpedia,但它仍然有其侷限性,我需要檢查大約30-40-50個資源。 –
另一個端點位於:「http://lod.openlinksw.com/sparql」 –
@AlexDoro如果您只是查詢某些屬性的值,則應該能夠擺脫「union」並使用'價值',對吧?這仍然有超時問題? –