错误HttpException:502当我在DBPedia上查询SPARQL时

时间:2014-07-09 13:09:58

标签: java sparql jena dbpedia httpexception

我在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)

此错误与帖子

的回复中报告的错误不同
  

To write a query SPARQL in Java code using strstarts filter

我还尝试使用主题“http://dbpedia.org/resource/Adriano_Celentano”执行相同的查询,并正确执行查询。 特别是,我得到一些查询的结果,所以不要拒绝所有查询。这种行为可以通过DBPedia的一些缓存机制给出 为什么我会收到此错误?我在这里做错了什么?

1 个答案:

答案 0 :(得分:2)

如果在尝试对DBpedia运行查询时遇到问题,则必须尝试的最重要的调试技术之一是打印查询,复制查询并将其粘贴到基于Web的端点中。在这种情况下,如果您将以下查询复制并粘贴到the endpoint,则会收到以下消息,说明502错误:

select ?ob where {
  <http://dbpedia.org/resource/McLeod's_Daughters_(season_8)> rdfs:label ?ob
  FILTER (contains(?ob, "tsmgo") ) 
}
  

您当前正在尝试访问的网站目前正在维护中。对由此造成的任何不便,我们深表歉意。