This SPARQL statement works:
PREFIX s: <http://dbpedia.org/resource/Del_Mar,_California>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT * WHERE {
OPTIONAL { s: dbp:officialName ?officialName . }
OPTIONAL { s: dbp:name ?foaf_name . }
#-- ... [ about 20 more lines like the above ] ...
} LIMIT 2;
But some cities have redirect. For instance, Pacific_Beach,_California redirects to Pacific_Beach,_San_Diego. How can I handle this?
I've read Joshua Taylor's answer to Retrieving dbpedia-owl:type value of resource with dbpedia-owl:wikiPageRedirect value?, and I wonder if my s: prefix is messing me up here? I can't seem to implement his solution of:
select ?type where {
dbpedia:Cupertino dbpedia-owl:wikiPageRedirects*/dbpedia-owl:type ?type
}
Some other resources suggest using a union:
sparql using wikiPageRedirects
Using SPARQL to find the right DBpedia URI
Reading the Wikibooks chapter, XQuery/DBpedia with SPARQL - Football teams leaves me even more confused.
I am trying to learn this stuff, but I do have an immediate need to "just make it work". A solution and some links to read would be appreciated!
Pacific Beach, San Diego doesn't redirect to anything, but it is the redirect target of a number of resources:
is dbo:wikiPageRedirects of
dbr:Pacific_Beach,_CA
dbr:Pacific_Beach,_California
dbr:Pacific_Beach,_San_Diego,_CA
dbr:Pacific_Beach,_San_Diego,_California
dbr:Pacific_Beach,_San_Diego_California
That means that a modified version of your query should work just fine:
PREFIX s: <http://dbpedia.org/resource/Pacific_Beach,_San_Diego>
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT * WHERE {
OPTIONAL { s: dbp:officialName ?officialName . }
OPTIONAL { s: dbp:name ?foaf_name . }
#-- ... [ about 20 more lines like the above ] ...
} LIMIT 2
SPARQL results
Note that using prefix to abbreviate a single IRI is sort of unusual. It would be more common to use a values block to bind a specific variable, that you can use in the rest of your query. That is, I would write that query as:
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT * WHERE {
values ?s { <http://dbpedia.org/resource/Pacific_Beach,_San_Diego> }
OPTIONAL { ?s dbp:officialName ?officialName . }
OPTIONAL { ?s dbp:name ?foaf_name . }
#-- ... [ about 20 more lines like the above ] ...
} LIMIT 2;
That has the advantage that if you want to search values for additional cities, you can just add them to the list of values. Now, if you want to add a value that redirects to something else, that's not a problem. You'd just want to add a non-optional pattern that helps you follow to the redirect targets:
SELECT * WHERE {
values ?x { <http://dbpedia.org/resource/Pacific_Beach,_California> }
?x dbo:wikiPageRedirects* ?s .
OPTIONAL { ?s dbp:officialName ?officialName . }
OPTIONAL { ?s dbp:name ?foaf_name . }
#-- ... [ about 20 more lines like the above ] ...
} LIMIT 2
SPARQL results
As a final note, do be careful that if you're copying and pasting URIs from the browser that you make sure to use the right URI in the query. When you visit a DBpedia resource, e.g., http://dbpedia.org/resource/foo in the browser, you're redirected to the human readable form http://dbpedia.org/page/foo in the browser. That's just a quirk of DBpedia. (Really, they should use content-type negotiation and just return an HTML document for the former when a web browser is making the request.)
I'd suggest taking another look at "this answer from Joshua Taylor". One of the suggestions is to use SPARQL to inspect the data. So try this query:
SELECT * WHERE {
<http://dbpedia.org/resource/Pacific_Beach,_California> ?p ?o
}
This give you all of the data available for the URI <http://dbpedia.org/resource/Pacific_Beach,_San_Diego>. Note that in this case it does not include a dbpedia-owl:wikiPageRedirects property. It appears that the redirect is internal to the DBPedia browser and not included in the DBPedia data.
Using the aforementioned query will help you find what is actually in the data (nothing very interesting in this case).
Related
I am trying to extract the manufacturer section of this dbpedia page http://dbpedia.org/page/Diageo. However my SPARQL query returns nothing. Yet I can return most other values on the page, such as keyPersons which has the exact same layout.
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT ?label
WHERE { <http://dbpedia.org/resource/Diageo>
dbpedia-owl:keyPerson ?label }
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT ?label
WHERE { <http://dbpedia.org/resource/Diageo>
dbpedia-owl:manufacturer ?label }
Any ideas?
In DBpedia, an entity page displays statements in which an entity may be not only a subject, but also an object. In the latter case, respective property appears as "is ... of".
Conversely, the page you have linked to says that dbr:Diageo is dbo:manufacturer of dbr:Johnnie_Walker etc. This means that dbr:Johnnie_Walker dbo:manufacturer dbr:Diageo holds, not that dbr:Diageo dbo:manufacturer dbr:Johnnie_Walker does.
By the way, rdfs:range of dbo:manufacturer is dbo:Organization.
Thus, you should looking for triples that match reversed pattern:
SELECT * WHERE { ?variable dbo:manufacturer ?dbr:Diageo . }
Or, using property paths:
SELECT * WHERE { dbr:Diageo ^dbo:manufacturer ?variable . }
Try it on DBpedia
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
Hello everybody i'm using a SPARQL query to retrieve properties and values of a specified resource. For example if i ask for Barry White, i obtain: birth place, associatedBand, recordLabels and so on.
Instead for any instance such as "Hammerfall", i obtain only this results:
Query results
But i want properties and values as shown in this page: Correct results.
My query is:
PREFIX db: <http://dbpedia.org/resource/>
PREFIX prop: <http://dbpedia.org/property/>
PREFIX onto: <http://dbpedia.org/ontology/>
SELECT ?property ?value
WHERE { db:Hammerfall?property ?value }
Anyone can tell me how to access to the correct resource and obtain corrects properties and values in every case?
select ?p ?o { dbpedia:HammerFall ?p ?o }
SPARQL results
The particular prefix doesn't matter; I just used dbpedia: because it's predefined on the endpoint as http://dbpedia.org/resource/, just like your db:. The issue is that HammerFall has a majuscule F in the middle, but your query uses a miniscule f.
As an alternative, since the results for Hammerfall (with a miniscule f) do include
http://dbpedia.org/ontology/wikiPageRedirects http://dbpedia.org/resource/HammerFall
you could use a property path to follow any wikiPageRedirects paths:
select ?p ?v {
dbpedia:Hammerfall dbpedia-owl:wikiPageRedirects* ?hammerfall .
?hammerfall ?p ?v
}
SPARQL results
See Retrieving dbpedia-owl:type value of resource with dbpedia-owl:wikiPageRedirect value? for more about that approach.
I need a Sparql query to recover the Type of a specific DBpedia resource. Eg.:
pt.DBpedia resource: http://pt.dbpedia.org/resource/Argentina
Expected type: Country (as can be seen at http://pt.dbpedia.org/page/Argentina)
Using pt.DBpedia Sparql Virtuoso Interface (http://pt.dbpedia.org/sparql) I have the query below:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?l ?t where {
?l rdfs:label "Argentina"#pt .
?l rdf:type ?t .
}
But it is not recovering anything, just print the variable names. The virtuoso answer.
Actually I do not need to recover the label (?l) too.
Anyone can fix it, or help me to define the correct query?
http in graph name
I'm not sure how you generated your query string, but when I copy and paste your query into the endpoint and run it, I get results, and the resulting URL looks like:
http://pt.dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fpt.dbpedia.org&sho...
However, the link in your question is:
http://pt.dbpedia.org/sparql?default-graph-uri=pt.dbpedia.org%2F&should-sponge...
If you look carefully, you'll see that the default-graph-uri parameters are different:
yours: pt.dbpedia.org%2F
mine: http%3A%2F%2Fpt.dbpedia.org
I'm not sure how you got a URL like the one you did, but it's not right; the default-graph-uri needs to be http://pt.dbpedia.org, not pt.dbpedia.org/.
The query is fine
When I run the query you've provided at the endpoint you've linked to, I get the results that I'd expect. It's worth noting that the label here is the literal "Argentina"#pt, and that what you've called ?l is the individual, not the label. The individual ?l has the label "Argentina"#pt.
We can simplify your query a bit, using ?i instead of ?l (to suggest individual):
select ?i ?type where {
?i rdfs:label "Argentina"#pt ;
a ?type .
}
When I run this at the Portuguese endpoint, I get these results:
If you don't want the individual in the results, you don't have to select it:
select ?type where {
?i rdfs:label "Argentina"#pt ;
a ?type .
}
or even:
select ?type where {
[ rdfs:label "Argentina"#pt ; a ?type ]
}
If you know the identifier of the resource, and don't need to retrieve it by using its label, you can even just do:
select ?type where {
dbpedia-pt:Argentina a ?type
}
type
==========================================
http://www.w3.org/2002/07/owl#Thing
http://www.opengis.net/gml/_Feature
http://dbpedia.org/ontology/Place
http://dbpedia.org/ontology/PopulatedPlace
http://dbpedia.org/ontology/Country
http://schema.org/Place
http://schema.org/Country
Why this SPARQL not returning any value
PREFIX ontology: <http://dbpedia.org/ontology/>
SELECT ?Abstract
WHERE
{
<http://dbpedia.org/resource/Cologne> <http://dbpedia.org/ontology/wikiPageRedirects> ?page .
?page <http://dbpedia.org/ontology/abstract> ?Abstract.
FILTER (lang(?Abstract)='en')
}
Two reasons. Firstly, there are no redirects of Cologne, but there are redirects to it. So:
PREFIX ontology: <http://dbpedia.org/ontology/>
SELECT *
WHERE
{
<http://dbpedia.org/resource/Cologne>
<http://dbpedia.org/ontology/wikiPageRedirects> ?page .
}
returns nothing, whereas:
PREFIX ontology: <http://dbpedia.org/ontology/>
SELECT *
WHERE
{
?page
<http://dbpedia.org/ontology/wikiPageRedirects>
<http://dbpedia.org/resource/Cologne> .
}
does work.
Secondly none of these redirects appears to have an abstract. Cologne itself does, so you could just use that:
PREFIX ontology: <http://dbpedia.org/ontology/>
SELECT ?Abstract
WHERE
{
<http://dbpedia.org/resource/Cologne>
<http://dbpedia.org/ontology/abstract> ?Abstract.
FILTER (lang(?Abstract)='en')
}
It does not return any value because nothing matches your query. If you dereference the URI for Cologne, you can see that there is no wikiPageRedirects property. dbpedia:Cologne does not redirects to anything, but many resources redirect to dbpedia:Cologne. However, the resources that redirect to Cologne do not have an abstract. In fact, this is quite normal: in Wikipedia, you cannot edit a page that redirects to another one, as you are necessarily redirected to the other. So when dbpedia extracts data from Wikipedia, of course there is nothing about the redirected pages.