0

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

此错误与帖子响应中报告的错误不同

使用 strstarts 过滤器在 Java 代码中编写查询 SPARQL

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

4

1 回答 1

2

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

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

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

于 2014-07-09T13:56:07.873 回答