![](/img/trans.png)
[英]HttpException error when I call SPARQL query (on DBPedia) in Java Code
[英]Error HttpException: 502 when I do query SPARQL on DBPedia
在DBPedia上執行查詢時,SPARQL存在問題。
我有這個Java類:
public class example {
public static void main(String[] args) {
String value = "http://dbpedia.org/resource/McLeod's_Daughters_(season_8)";
String object = "tsmgo";
example le = new example();
QueryExecution qe = le.queryColumn(object, value);
ResultSet results = ResultSetFactory.copyResults( qe.execSelect() );
}
public QueryExecution queryColumn(String object, String string) {
ParameterizedSparqlString qs = new ParameterizedSparqlString( "" +
"prefix dbpediaont: <http://dbpedia.org/ontology/>\n" +
"prefix dbpedia: <http://dbpedia.org/resource/>\n" +
"prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
"prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
"\n" +
"select ?ob where {\n" +
"?subj rdfs:label ?ob\n" +
"FILTER (contains(?ob, ?obj) )\n" +
"}" );
Resource risorsa = ResourceFactory.createResource(string);
qs.setParam( "subj", risorsa );
Literal obj2 = ResourceFactory.createPlainLiteral(object);
qs.setParam( "obj", obj2 );
System.out.println( qs );
QueryExecution exec = QueryExecutionFactory.sparqlService( "http://dbpedia.org/sparql", qs.asQuery() );
ResultSet results = ResultSetFactory.copyResults( exec.execSelect() );
while ( results.hasNext() ) {
System.out.println( results.next().get( "ob" ));
}
// A simpler way of printing the results.
ResultSetFormatter.out( results );
return exec;
}
}
執行此代碼時,出現以下錯誤:
Exception in thread "main" HttpException: 502
at com.hp.hpl.jena.sparql.engine.http.HttpQuery.execGet(HttpQuery.java:340)
at com.hp.hpl.jena.sparql.engine.http.HttpQuery.exec(HttpQuery.java:276)
at com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.execSelect(QueryEngineHTTP.java:345)
at MyPackage.example.queryColumn(example.java:176)
at MyPackage.example.main(example.java:28)
此錯誤與帖子回復中報告的錯誤不同
我還嘗試使用主題“ http://dbpedia.org/resource/Adriano_Celentano ”執行相同的查詢,並正確執行了該查詢。 特別是,我得到了某些查詢的結果,因此並非所有查詢都被拒絕。 可以通過DBPedia的某種緩存機制來實現此行為。為什么會出現此錯誤? 我在這里做錯了什么?
如果嘗試對DBpedia運行查詢時遇到問題,則必須嘗試的最重要的調試技術之一是打印查詢,復制查詢並將其粘貼到基於Web的端點中。 在這種情況下,如果將以下查詢復制並粘貼到終結點中 ,則會收到以下消息,說明502錯誤:
select ?ob where {
<http://dbpedia.org/resource/McLeod's_Daughters_(season_8)> rdfs:label ?ob
FILTER (contains(?ob, "tsmgo") )
}
您當前正在嘗試訪問的網站目前正在維護中。 不便之處,敬請原諒。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.