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.
Related
I have a list of artstyles in graphDB, i am trying to use the SERVICE function to get their labels from Wikidata with this query:
PREFIX gp: <http://www.semanticweb.org/kandd/group76/final_project#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?movement ?label
WHERE{
?artist gp:hasArtStyle ?movement.
SERVICE <https://query.wikidata.org/sparql>{
?movement rdfs:label ?label .
FILTER (langMatches( lang(?label), "EN" ) )
}
}
note that gp is a namespace that only exists in my graph, not anywhere on the internet and also note that ?movement contains a list of valid Wikidata URIs such as http://www.wikidata.org/entity/Q186030
yet still the response I get is:
Error 500: error
Query evaluation error: org.eclipse.rdf4j.query.QueryEvaluationException: org.eclipse.rdf4j.query.QueryEvaluationException: java.io.IOException: Unkown record type: 83 (HTTP status 500)
What am I doing wrong?
Remember that you query is handled from the inside to the outside, meaning that the service part is handled first, and then the part where you use your own specific property.
Currently, your query on WikiData is very general. You ask for everything that has a rdfs:label, and then filter on all the English labels it returns.
Given this, my guess is that you query simply times out. Instead, I would try something like this:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT *
WHERE{
SERVICE <https://query.wikidata.org/sparql>{
?artist wdt:P101 wd:Q186030 ; #Field of Work is contemporary art
wdt:P31 wd:Q5 ; #instance of Human
rdfs:label ?name . #get the label
FILTER (langmatches(lang(?name), "en"))
}
}
If I try this in GraphDB, it returns 156 results.
I am querying an ontology on the Bioportal endpoint. The ontology (NIF) is stored as a graph, so I put it in the FROM clause as the endpoint instructed.
SELECT DISTINCT ?p
FROM <http://bioportal.bioontology.org/ontologies/NIF>
WHERE{
?p a rdf:Property
}
limit 100
However, as can be seen below, the results came back showing few properties related to NIF and others to a different ontology called SKOS (Simple Knowledge Organization System).
In the Bioportal documentation it is said it maps some properties to SKOS properties, so I thought maybe the results are fine.
However, I had to test if I am querying the correct graph. So I used the below code to count the number of nodes since I know the NIF has around 3.6 million triples!
SELECT (count (*) as ?nodes)
FROM <http://bioportal.bioontology.org/ontologies/NIF>
WHERE{
?s ?p ?o
}
This resulted in 7984 nodes with and without the FROM clause! So I guessed I should be using the "count" incorrectly!
So I wonder how I should make sure that I am just querying the NIF ontology. Also, how to count its nodes?
Thanks :)
Try using SERVICE keyword.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT (count (*) as ?nodes)
WHERE
{
SERVICE <http://bioportal.bioontology.org/ontologies/NIF>
{
?s ?p ?o
}
}
If this fails, possibly the service you are connecting is not correct or up.
Try below example which connects to DBpedia:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT (count (*) as ?nodes)
WHERE
{
SERVICE <http://DBpedia.org/sparql>
{
?s ?p ?o
}
}
By the way I can;t access URL http://bioportal.bioontology.org/ontologies/NIF. Seems to be unavailable or down.
I'm new to sparql and I'm trying to understand how to get the resources I need for building a query. I started trying to get all the politicians that ruled a city or a country, and at the moment I could do just the following:
I started by following the links in snorql (in the prefixes) and looking for an entity by adding "politician" at the end. I found one :
PREFIX : <http://dbpedia.org/resource/>
So I wrote http://dbpedia.org/resource/Politician and the resource does exist. I tryed to use it in this way:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbpedia: <http://dbpedia.org/resource/>
SELECT ?thing WHERE {
?thing a :Politician .
?thing dbo:birthPlace dbpedia:Italy.
}
LIMIT 50
Run in virtuoso.
Even if I remove the second line of the SELECT, I have no results. But if I change the first line with: ?thing a dbo:Person. or even if I remove it, I get the people born in Italy. But not just the politicians. A second problem is I don't need the politicians that were born but ruled that place. How or where can I find that kind of "relations/descriptors"? Now I am just googling and copy-pasting some existing examples, but I would like to understand how to look for more specific things.
Thanks in advance
Your first query isn't working because Politician is not part of the default (:) namespace, but instead it is present in DBpedia Ontology namespace (dbo).
So, your query should be:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbpedia: <http://dbpedia.org/resource/>
SELECT ?thing WHERE {
?thing a dbo:Politician .
?thing dbo:birthPlace dbpedia:Italy.
}
LIMIT 50
To list all politician who ruled Italy you would need to know which is the predicate for "ruled". Once you have it you can construct a query.
To list all predicates present in the database you can write something like this
SELECT DISTINCT(?b) WHERE {
?a ?b ?c.
}
And it will list all predicates.
I would recommend you to browse through one or two politician and see the predicates they have to check if one works for you.
Why does this SPARQL query return no data?
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dbpedia: <http://dbpedia.org/resource/>
SELECT *
WHERE {
<http://dbpedia.org/resource/Louis,_Prince_of_Condé_(1530–1569)> dbpedia-owl:abstract ?abstract
}
LIMIT 1
If you look at the DBpedia page, it shows the person has an abstract. Is it to do with the brackets in the URL? If so, how can I get round this?
This URI does not lead to the same result as the DBpedia page - for what ever reason. You can see this with
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dbpedia: <http://dbpedia.org/resource/>
SELECT *
WHERE {
<http://dbpedia.org/resource/Louis,_Prince_of_Condé_(1530–1569)> ?p ?o
}
LIMIT 100
But it has an owl:sameAs relation to
http://dbpedia.org/resource/Louis,_Prince_of_Cond%C3%A9_(1530%E2%80%931569)
That means if you use this URI in your query, it should work as expected. But you should indeed apply a FILTER on the language, e.g. 'en' for English abstracts.
As AKSW mentions, the resource actually doesn't have many properties, but is connected to the "canonical" version by an owl:sameAs link. You can keep using the IRI that you're using now, follow owl:sameAs in either direction to any of its equal resources (let's call them ?s), and then ask for the abstract of ?s. (And then it's not a bad idea to filter by language, if that's applicable.) You can do this with a query like this (note that the current DBpedia endpoint uses dbo:, now, not the older dbpedia-owl:):
select ?abstract where {
<http://dbpedia.org/resource/Louis,_Prince_of_Condé_(1530–1569)> (owl:sameAs|^owl:sameAs)* ?s .
?s dbo:abstract ?abstract .
filter langMatches(lang(?abstract),'en')
}
It does not have dbpedia-owl:abstract predicate. If you list its predicates you find the following properties:
http://www.w3.org/2002/07/owl#sameAs
http://xmlns.com/foaf/0.1/name
http://purl.org/dc/elements/1.1/description
http://dbpedia.org/ontology/alias
http://dbpedia.org/ontology/birthYear
http://dbpedia.org/ontology/deathYear
http://dbpedia.org/ontology/viafId
http://dbpedia.org/ontology/deathPlace
http://dbpedia.org/ontology/deathDate
http://dbpedia.org/ontology/birthPlace
http://dbpedia.org/ontology/birthDate
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.