【发布时间】:2014-07-09 13:09:58
【问题描述】:
我在 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 维护完成后。
-
你确定吗?如果我现在尝试(杜林特 DBPedia 维护)这些值: String value = "dbpedia.org/resource/Adriano_Celentano";;字符串对象 = "阿德里亚诺";'查询在 Java 代码中正确执行,而在 Virtuoso Endpoint 中我得到:'您当前尝试访问的网站目前正在维护中。对于由此造成的任何不便,我们深表歉意。'
-
您之前是否运行过可能让上游代理缓存结果的查询?我确实了解您所描述的行为。如果我使用 Adriano Celentano 和 Adriano 运行查询,我会得到结果,但如果我使用不同的字符串,例如“Celen”而不是“Adriano”,我仍然会得到 502。我认为你只是幸运地得到了已缓存查询结果。
-
只是出于好奇,Java 有缓存机制吗?我没有任何设置。
-
我不知道 Java 是否有,但我不希望它在这种情况下使用任何。我希望每天提供大量请求的 DBpedia 可能有一些缓存,以减少实际查找 SPARQL 查询结果的服务器上的负载。如果同一个问题出现两次,为什么要让它搜索两次数据?为什么不在前面有一个(反向)代理发送相同的结果两次?
标签: java sparql jena dbpedia httpexception