當我在java中運行此代碼時,出現錯誤,我認爲發生錯誤是因爲「字符串值」。我不知道如何添加,但我有這個想法,從我剛纔的問題的答案,我問在這個網站Query DBpedia to get abstract for different inputs使用VALUES使用Sparql查詢DBpedia
public static void DbpediaResultSparql() {
String values = "New York";
String service = "http://dbpedia.org/sparql";
String sparqlQueryString2 = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"+
"PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>"+
"PREFIX dbpedia: <http://dbpedia.org/resource/>"+
"SELECT DISTINCT ?abstract"+
"WHERE"+
"{ _:b0 rdfs:label ?name ."+
"_:b0 dbpedia-owl:abstract ?abstract"+
"FILTER langMatches(lang(?abstract), 'en')"+
"?name { " + values +" @en }"+
"}" ;
Query query = QueryFactory.create(sparqlQueryString2);
ARQ.getContext().setTrue(ARQ.useSAX);
// Executing SPARQL Query and pointing to the DBpedia SPARQL Endpoint
QueryExecution qexec = QueryExecutionFactory.sparqlService(
"http://DBpedia.org/sparql", query);
// Retrieving the SPARQL Query results
ResultSet results = qexec.execSelect();
// Iterating over the SPARQL Query results
while (results.hasNext()) {
QuerySolution soln = results.nextSolution();
// Printing DBpedia entries' abstract.
System.out.println(soln.get("?abstract"));
}
qexec.close();
}
-1這顯示根本沒有調試嘗試。在將它發送到DBpedia之前打印查詢會立即發現一些問題。請參閱[DBpedia Jena Query返回null](http://stackoverflow.com/q/15663510/1281433),其中描述了此代碼中的一些問題。 – 2014-09-24 01:30:28