timeout transaction when running a query on dbpedia - sparql

HI there is a query which was working untill yesterday :
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT(?film_link) ?film_abstract ?film_name ?wikipage
WHERE {
?film_link rdf:type <http://dbpedia.org/ontology/Film> .
?film_link rdfs:comment ?film_abstract
FILTER (langMatches( lang(?film_abstract), "EN")) .
?film_link foaf:name ?film_name .
?film_title foaf:page ?wikipage .
}
but today it is showing: Virtuoso 42000 Error The estimated execution time 99232592 (sec) exceeds the limit of 1500 (sec).
I have seen this error earlier also but when i ran such query again after some time it runs..
Could anyone explain the meaning of the error?

It means that Virtuoso's query planner (Virtuoso is the triplestore that DBPedia runs on) has estimated how long it would take to evaluate your query and it thinks it will take too long so it has refused to run the query.
I suspect the problem is the last triple pattern in your query:
?film_title foaf:page ?wikipage
You never use either of those variables before that point so what you've asked Virtuoso to do is cross product every possible triple with foaf:page in the predicate position with the results in the rest of your query.
If you change this to the following it should work fine:
?film_link foaf:page ?wikipage
I suspect this is what you meant to write anyway and this works for though it is still pretty slow because your query is pretty broad and FILTER clauses are often quite sluggish to evaluate.

Related

How to filter results by city?

I am using DBpedia to retrieve data on specific towns' POIs, for instance Barcelona. I've tried to find appropriate answers to my problems on Stack Overflow but almost all the answers provided did not work out for me, and given that I am new in SPARQL, I couldn't manage to figure out whether or not it was the syntax that was at fault or if there was something else. I am using the DBpedia SPARQL Endpoint available at the following address : http://dbpedia.org/sparql
I've tried to use some things such as ?citylabel or ?location, and to either use the FILTER command or directly fill a value for these classes. I've also tried a few other things, without satisfying results (and most of the times syntax errors that I could not resolve). These solutions have been, in most cases, applied and seemed to work just fine for people, so I do not understand what's going on.
BASE <http://www.dbpedia.org/resource/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia3: <http://dbpedia.org/ontology/>
SELECT (SAMPLE(?label) as ?activity_name)
(SAMPLE(?latitude) as ?activity_lat)
(SAMPLE(?longitude) as ?activity_lon)
(SAMPLE(?homepage) as ?URL)
(SAMPLE(?type) as ?activity_type)
(SAMPLE(?abstract) as ?descriptor)
WHERE
{ ?Museum a dbo:Museum ;
rdfs:label ?label ;
dbo:abstract ?abstract ;
dbo:type ?type ;
geo:lat ?latitude ;
geo:long ?longitude ;
foaf:homepage ?homepage .
}
GROUP BY ?Museum ?label
The results of this query are, I think, pretty much any museum that is known by DBpedia and categorized as such. What I'd like to have is a list of museums within Barcelona. Can somebody give me an rather in-depth answer so I can understand how it is working ? Thanks, in advance.

SPARQL Apache Jena - Execution Limit on queries in DBpedia?

I'm dealing with a problem that I can't execute the same query (see Example below) multiple times against DBpedia, because the execution freezes after like 4-5 queries.
The thing is, with the same Apache Jena Code, I can execute hundreds of same queries against Wikidata (see Example below) without a problem. The Apache Jena Code is literally standard code (see below). The result is just returned as a normal string value. I also tried variations here, but that's not the issue.
Apache Jena Code Snippet from the DBpedia query (Wikidata is basically the same except the createServiceRequest-Method uses https://query.wikidata.org/sparql)
Query query = queryFactory.create(**!!see Query Example below!!**);
QueryEngineHTTP queryEngine = QueryExecutionFactory.createServiceRequest("http://de.dbpedia.org/sparql",
query);
ResultSet results = queryEngine.execSelect();
for (; results.hasNext();) {
QuerySolution solution = results.nextSolution();
String stringElement = solution.getLiteral("item").toString();
stringArray.add(stringElement);
// stringArray is then returned simply with System.out.println
}
DBpedia Query:
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix dbpprop-de: <http://de.dbpedia.org/property/>
prefix dbpedia-de: <http://de.dbpedia.org/resource/>
SELECT DISTINCT ?item WHERE {
dbpedia-de:Deutschland dbpprop-de:hauptstadt ?y .
?y rdfs:label ?item
}
Wikidata Query:
prefix wdt: <http://www.wikidata.org/prop/direct/>
prefix wd: <http://www.wikidata.org/entity/>
prefix wikibase: <http://wikiba.se/ontology#>
prefix bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?itemLabel WHERE {
wd:Q183 wdt:P36 ?item .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "de" .
}
}
Is there some kind of Execution Limit on queries for users in DBpedia? I know there are limits on ResultSets, but that's not the issue here as i only get like one result per one query back. It would be really helpful as i couldn't find a similar problem. Thanks in advance.

Simple SPARQL query of foaf RDF not working

I'm new at semantic web, where I learn basics, but I'm stuck at the beginning.
After reading this link: http://www.cambridgesemantics.com/semantic-university/sparql-by-example, I try some examples by myself, but without success.
For example, using OpenLink Virtuoso SPARQL Query Editor http://demo.openlinksw.com/sparql, I put at Default Graph URI this http://njh.me/foaf.rdf and simple query
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
select ?name
where
{
?person foaf:name ?name .
}
to get name of a person who is owner of this RDF file. Also, if I put following query
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
select ?name
where
{
?OnlineAcount foaf:name ?name .
}
nothing is happening.
Where I make mistake?
The same situation is with https://ai.wu.ac.at/~polleres/foaf.rdf, http://richard.cyganiak.de/foaf.rdf for the first query.
Any help at the beginning of my semantic tour will be appreciated :)
Thanks in advance.
Below the query input pane, there's an option for Sponging. You need to select the option Retrieve remote RDF data for all missing source graphs. Then you'll get results. However, the file that you mentioned actually has lots of foaf:name triples, not just one for the creator of the file. You might try select ?person ?name to see what else is in that data.

Query on sindice SPARQL endpoint

I tried to make this query on http://sparql.sindice.com/
PREFIX rev: <http://purl.org/stuff/rev#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT *
WHERE
{
?thing rdfs:label ?name .
?thing rev:hasReview ?review .
filter regex(str(?name), "harlem", "i")
} LIMIT 10
And it returns 504 Gateway Time-out
The server didn't respond in time.
What i'm doing wrong?
Thanks.
You made a query that was too hard for the endpoint to answer in a timely fashion hence why you got a timeout response. Note that there website states the following:
all queries are time and resource limited. notice that this means that
sometime you will get incomplete or even no results. If this is
happening often for you or you really want to run more complex queries
please contact us
Your query essentially selects a vast swathe of data and then makes the engine run a regular expression over ever possible value which is extremely slow.
I believe Sindice use Virtuoso as their SPARQL implementation so you can cheat and use Virtuoso specific full text query extension like so:
PREFIX rev: <http://purl.org/stuff/rev#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT *
WHERE
{
?thing rdfs:label ?name .
?thing rev:hasReview ?review .
?name bif:contains "harlem" .
}
LIMIT 10
However this query also seems to timeout, if you can add more conditions to constrain your query further you will have more chance of getting results in a timely fashion.

"Timeout/query hangs" while executing SPARQL query to DBpedia from Jena

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)
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.