问题
I am having trouble executing SPARQL queries against dbpedia.org using Jena.
The queries are of the form:
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX p: <http://dbpedia.org/property/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?album ?name ?dateofrelease
WHERE {
?album p:artist <http://dbpedia.org/resource/SomeArtist> .
?album rdf:type <http://dbpedia.org/ontology/Album> .
?album rdf:type <http://schema.org/MusicAlbum> .
?album p:name ?name .
?album <http://dbpedia.org/ontology/releaseDate> ?dateofrelease .
FILTER(xsd:dateTime(?dateofrelease) >= '2009-01-01T00:00:00Z'^^xsd:dateTime)
} LIMIT 5
where http://www.dbpedia.org/resource/SomeArtist is a valid artist URI, e.g. http://dbpedia.org/resource/Wilco, and URL-encoded properly before sent.
The queries are executed with the following standard code:
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
ResultSet results = queryExecution.execSelect();
The program is doing about 30 queries on the same form, but some of them "hangs" for about a minute or two before Jena throws a
com.hp.hpl.jena.sparql.resultset.ResultSetException: Not an ResultSet result
If I catch the exception and go on, some queries hang and some returns a result set quickly with either 0 or more results. Doing this several times, it's random what queries that returns or "hangs". Using the SPARQL DBpedia with a identical query sometimes works, sometimes hangs in the same way in the web browser.
Am I constructing the query wrong, making it in some way time consuming for dbpedia.org so that the query timeout at the sever? I'm quite new to the Semantic Web and Jena, but I thought initially my query not could be very time consuming since I'm using a absolute URI for the object part in the
?album p:artist <http://www.dbpedia.org/resource/SomeArtist>
statement.
Is there some number of requests from-one-source/per-time-unit limit to dbpedia.org that I'm not aware of?
(Using Jena 2.6.4)
回答1:
I can confirm that the query is slow.
I tried a few variations that might effect the speed, but it didn't help. I can't see any obvious reason why that type of query would be particularly slow, sorry.
One alternative, to get more consistent response times would be to download the DBPedia dump, grep out the predicates that you're interested in, and load them into a local triplestore, e.g. Jena.
来源:https://stackoverflow.com/questions/8261510/timeout-query-hangs-while-executing-sparql-query-to-dbpedia-from-jena