Sparql DBPedia not returning foaf:name query - sparql

I am using the Virtuoso SPARQL endpoint for DBpedia. I am having no issue running some test queries, but my issue is when I run on a query based on the foaf:name "literal" of an entity. Here is my code below:
prefix db: <http://dbpedia.org/resource/>
prefix dbo: <http://dbpedia.org/ontology/>
prefix foaf: <http://xlms.com/foaf/0.1/>
SELECT ?capital WHERE{
?state dbo:capital ?capital .
?state foaf:name "State of Alaska"#en .
}
My logic is that by ?state dbo:capital ?capital refers to the capital of a state within DBpedia owl ontology. ?state foaf:name "State of Alaska"#en should match the variable ?state up with the literal entity Alaska. I am having no issue when my queries are controlled by variables that are not foaf:name. I have looked up examples and can't see what the issue is with my syntax. Even when I edit the last line to --
?state a foaf:name "State of Alaska"#en .
-- the code continues to fail. I have looked up other examples and can't find my specific issue. It appears as if this code SHOULD return the capital for Alaska based on the foaf:name Literal.

I found the answer. The key is to not add this prefix at the top
prefix foaf: <http://xlms.com/foaf/0.1/>
That should be replaced with the correct foaf: prefix declaration:
prefix foaf: <http://xmlns.com/foaf/0.1/>
Or probably even skipped, since the foaf: prefix is predefined.
So the query below actually works:
SELECT ?capital WHERE {
?state dbo:capital ?capital .
?state foaf:name "State of Alabama"#en .
}

Related

SPARQL Federated Query Not Returning All Solutions

This is an evolution of this question.
Basically I am having trouble getting all the solutions to a SPARQL query from a remote endpoint. I have read through section 2.4 here because it seems to describe a situation almost identical to mine.
The idea is that I want to filter my results from DBPedia based on information in my local RDF graph. The query is here:
PREFIX ns1:
<http://www.semanticweb.org/caeleanb/ontologies/twittermap#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT *
WHERE {
?p ns1:displayName ?name .
SERVICE <http://dbpedia.org/sparql> {
?s rdfs:label ?name .
?s rdf:type foaf:Person .
}
}
And the only result I get is dbpedia:John_McCain (for ?s). I think this is because John McCain is the only match in the first 'x' results, but I can't figure out how to get the query to return all matches. For example, if I add a filter like:
SERVICE <http://dbpedia.org/sparql> {
?s rdfs:label ?name .
?s rdf:type foaf:Person .
FILTER(?name = "John McCain"#en || ?name = "Jamie Oliver"#en)
}
Then it correctly returns BOTH dbpedia:Jamie_Oliver and dbpedia:John_McCain. There are dozens of other matches like Jamie Oliver that do not come through unless I specifically add it to a Filter like this.
Can someone explain a way to extract the rest of the matches? Thanks.
It looks like the cause of this issue is that the SERVICE block is attempting to pull all foaf:Persons from DBPedia, and then filter them based on my local Stardog db. Since there is a 10,000 result limit when querying DBPedia, only matches which occur in that set of 10,000 arbitrary Persons will be found. To fix this, I wrote a script to put together a FILTER block containing every string name in my Stardog db and attached it to the SERVICE block to filter remotely and thereby avoid hitting the 10,000 result limit. It looks something like this:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX ns1: <http://www.semanticweb.org/caeleanb/ontologies/twittermap#>
CONSTRUCT{
?s rdf:type ns1:Person ;
ns1:Politician .
}
WHERE {
?s rdfs:label ?name .
?s rdf:type dbo:Politician .
FILTER(?name IN ("John McCain"#en, ...)
}

SPARQL query not returning any data

I am new to RDF, so it will be very nice if you can help me with this!
I am trying to query the subject of pickles called "Umeboshi"(It is japanese pickles) as follows:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX type: <http://dbpedia.org/class/yago/>
PREFIX prop: <http://dbpedia.org/property/>
PREFIX onto: <http://dbpedia.org/ontology/>
SELECT ?label ?subject
WHERE {
?Thing
rdfs:label ?label;
prop:subject?subject.
FILTER (?label = "Umeboshi")
}
This query doesn't give me any data.
As I don't know where to find available properties I am referring to the Umeboshi page on dbpedia http://live.dbpedia.org/page/Umeboshi.
Thank you very much for your help!
Two things I found:
In the page you give, the label is given in English, but in your query you omit the language.
subject has a different namespace. It is a dcterm concept and not a dbpedia property.
This leads to the following, changed query, which results in three bindings:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT ?label ?subject
WHERE {
?Thing
rdfs:label ?label;
dct:subject ?subject.
FILTER (?label = "Umeboshi"#en)
}

simple sparql query from dbpedia

I have a question about a SPARQL query that I'm trying to build from a tutorial. I want to generate triples that return a list of band members and the bands that they are in using a DBPedia endpoint.
my query
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?bandname where {
?person foaf:name ?name .
?band dbo:bandMember ?person .
?band dbo:genre dbpedia:Punk_rock .
?band dbp:name ?bandname .
}
I'm also using a [SPARQL query validator][2] to try to figure out my problem and it seems I'm using an incorrect prefix for "dbp:name ?bandname"I just want the triples returned in JSON if possible.
Once I can get this to run, I'd like to add another prefix, from GeoNames, to see the places associated with the bands, if possible (but that part is in the future). Any insights would be greatly appreciated!
There are some issues with your query.
The "name" property for a band has the following URI : http://dbpedia.org/property/name. It is a property, and not a resource, but you defined it as such in the prefixes. You shoud define it as follows :
PREFIX dbp: <http://dbpedia.org/property/>
I just had a quick check at what a band page has as properties, and saw that, apart from the dbo:bandMember one you are using, there is another property, currentMembers, that seems to retrieve more information. This seems logical though, in so far as dbo:bandMember only retrieves entities (members URIs), whereas dbp:currentMembers also retrieves literals. It depends on your use case here...
You use the dbpedia:prefix in your query, that does not seem to have been defined beforehand.
Here is the query I used to retrieve a list of bands associated with their members :
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?members ?bandName where {
?band dbo:genre dbr:Punk_rock .
?band dbp:currentMembers ?members.
?band foaf:name ?bandName
FILTER(langMatches(lang(?bandName), "en"))
}
The filter part allows us to avoid duplicates in case the literals are also defined in other languages.
But if you still want to use the dbo:bandMember property, this query also does the job :
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?personName ?bandName where {
?band dbo:bandMember ?person .
?person foaf:name ?personName .
?band dbo:genre dbr:Punk_rock .
?band foaf:name ?bandName
FILTER(langMatches(lang(?bandName), "en"))
FILTER(langMatches(lang(?personName), "en"))
}
Hope that helps !
The problem is with undefined prefix dbpedia. Also I think you have to replace dbp:name with foaf:name:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?bandname where {
?person foaf:name ?name .
?band dbo:bandMember ?person .
?band dbo:genre dbp:Punk_rock .
?band foaf:name ?bandname .
}
Alas, with SELECT you won't get triples, but just the names (or other stuff) in tabular results. Much like SQL. If you want triples, you need CONSTRUCT

Virtuoso 37000 Error SP030

why is showing this error, i see in the sparql query is correct, i don't see any mistake in prefix.
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX type: <http://dbpedia.org/class/yago/>
PREFIX prop: <http://dbpedia.org/property/>
SELECT ?country_name ?population
WHERE { ?country rdf:type dbpedia-owl:Country;
rdfs:label ?country_name ;
prop:populationEstimate ?population .
FILTER (?population > 2334456) .
FILTER ( lang(?country_name) = 'en')}
Error:
Virtuoso 37000 Error SP030: SPARQL compiler, line 1: Missing in PREFIX declaration at '<' before 'http:'
SPARQL query:
define sql:big-data-const 0 define input:default-graph-uri http://dbpedia.org PREFIX rdfs:
The query you've shown us might not be the same as the query you're actually running. First, the fact that the error message says "line 1" makes me wonder whether you've actually got the query run all onto one line. That can make it easy to get typo problems.
When I put your query into sparql.org's query validator, I do get a syntax error, because there's no prefix defined for rdf:. This is an error:
Line 7, column 18: Unresolved prefixed name: rdf:type
That said, the interactive web interface to the DBpedia endpoint includes some predefined namespace prefixes, and if you paste the query from the question into the web interface, it works just fine:
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX type: <http://dbpedia.org/class/yago/>
PREFIX prop: <http://dbpedia.org/property/>
SELECT ?country_name ?population
WHERE { ?country rdf:type dbpedia-owl:Country;
rdfs:label ?country_name ;
prop:populationEstimate ?population .
FILTER (?population > 2334456) .
FILTER ( lang(?country_name) = 'en')}
SPARQL results
I like to use the prefixes that DBpedia defines, since it makes copying and pasting easier, so I've used the prefix dbpprop: instead of prop:. I've also used langMatches instead of lang(…) = …, because it works with regional variants of languages, whereas the latter won't. I ended up with this query:
select ?country_name ?population where {
?country rdf:type dbpedia-owl:Country ;
rdfs:label ?country_name ;
dbpprop:populationEstimate ?population .
filter (?population > 2334456)
filter langMatches(lang(?country_name),'en')
}
SPARQL results

Get geographical coordinates of a particular place from DbPedia

I need to get the co-ordinates of some particular places from DbPedia. For the same I am using following snippet:
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT * WHERE {
?x foaf:name 'Mumbai'.
?x dbo:Place 'Mumbai'.
?x geo:lat ?lat .
?x geo:long ?long .
}
On running at http://dbpedia.org/sparql, it returns an empty page. I think I didn't put the name of place in the correct way. Can anyone help me to find the issue
Have a look at the N3/TTL serialization of the data for Mumbai. Note that the foaf:name value has a language tag: foaf:name "Mumbai"#en. You need to use "Mumbai"#en, with the language tag, in the query. Additionally, doing dbo:Place 'Mumbai' doesn't make any sense. You might instead want to ask for things which are dbpedia-owl:Places. You'd end up with a query like:
select * {
?mumbai a dbpedia-owl:Place ;
foaf:name "Mumbai"#en ;
geo:lat ?lat ;
geo:long ?long
}
SPARQL Results