0

I have a problem with SPARQL when I execute a query on DBPedia.

I have this Java class:

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;
    }

}

When I execute this code, I get this error:

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)

This error is different than that reported in the response of the post

To write a query SPARQL in Java code using strstarts filter

I also tried to execute the same query with the subject "http://dbpedia.org/resource/Adriano_Celentano" and to the query is executed correctly. In particular, I get results to some queries, so do not all queries are rejected. This behavior could be given by some caching mechanism of DBPedia Why do I get this error? What am I doing wrong here?

Community
  • 1
  • 1
Musich87
  • 562
  • 1
  • 12
  • 31
  • 1
    This question appears to be off-topic because it is was caused by **a problem that can be reproduced** at time of writing, but which **will not be reproducible** after DBpedia maintenance is completed. – Joshua Taylor Jul 09 '14 at 13:59
  • Are you sure? if I try now (durint DBPedia maintenance) these values: String value = "dbpedia.org/resource/Adriano_Celentano";; String object = "Adriano";' the query is executed correctly in Java Code, while in Virtuoso Endpoint I get: 'The web-site you are currently trying to access is under maintenance at this time. We are sorry for any inconvenience this has caused.' – Musich87 Jul 09 '14 at 14:04
  • 1
    Did you run that query earlier which might have let an upstrem proxy cache the results? I *do* get the behavior that you're describing. If I run the query with Adriano Celentano and Adriano, I get results, but if I use a different string, e.g., "Celen" instead of "Adriano", I still get the 502. I think you're just getting lucky with an already cached query result. – Joshua Taylor Jul 09 '14 at 14:12
  • Just out of curiosity, Java has the caching mechanisms? I do not have anything set. – Musich87 Jul 09 '14 at 14:17
  • I don't know if Java does, but I wouldn't expect it to use any in this case. I expect that DBpedia, which serves up lots of requests every day probably has some caching to reduce the load on servers that actually find results for SPARQL queries. Why make it search the data twice if the same question arrives twice? Why not just have a (reverse) proxy in front send same result twice? – Joshua Taylor Jul 09 '14 at 14:20
  • I see you're getting some downvotes, and I've cancelled one out by upvoting. I think this should probably get closed because it won't ultimately be reproducible, but given the strange behavior of the caching, I think this may be useful to future readers. It would be good to mention *in the question* that you still get results to some queries, so it doesn't **appear** that all queries are getting rejected (even though that's probably a result of some caching). – Joshua Taylor Jul 09 '14 at 14:25
  • Actually, now that I think of it, you might be able to do something to make the query ask for fresh (i.e., non-cached) results, in which case, you might be able to make those other queries fail, too. I expect that there's no way of guaranteeing that the reverse proxy honors that request, but it's something you could try. You could also just try running the query in some way where you can see the headers, which will probably indicate whether the result was cached or not. – Joshua Taylor Jul 09 '14 at 14:36
  • I don't know how I can running it. How I can see the headers? – Musich87 Jul 09 '14 at 14:38
  • You could use something like `wget -S`, I suppose, but you'd still need to figure out exactly what query Java is sending. – Joshua Taylor Jul 09 '14 at 14:44
  • The DBPedia's site is online now and I don't get this error. – Musich87 Jul 09 '14 at 15:01

1 Answers1

2

If you have a problem when trying to run a query against DBpedia, one of the most important debugging techniques that you must try is printing the query, copying it, and pasting it into the web-based endpoint. In this case, if you copy and paste the following query into the endpoint, you get the following message that explains the 502 error:

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

The web-site you are currently trying to access is under maintenance at this time. We are sorry for any inconvenience this has caused.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • 1
    That's interesting. Did you run that query earlier? Is it possible that the results are cached? What if you try running a query that you haven't run before? – Joshua Taylor Jul 09 '14 at 14:04
  • Maybe you're right. I tried to run a query with values ​​never used as "http://dbpedia.org/resource/The_Freddie" and "Freddie" and I get same error. – Musich87 Jul 09 '14 at 14:07