How can I get a list of all organisations from DBpedia?
By "organisation", I mean a entity of any type that is either a organisation or any subclass of organisation.
I found the question How to get all companies from DBPedia? but this doesn't work in the current DBpedia SPARQL web version and I wasn't able to adapt the query.
To simply get all resources that are an instance of dbo:Organization or its subclass:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?org { ?org a/rdfs:subClassOf* dbo:Organisation . }
However, as the question you linked shows, DBpedia has a cap on how many results are returned. So, as in the answer to said question, you can use a subquery with LIMIT and OFFSET to get all the results in chunks:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?org {
SELECT DISTINCT ?org {
?org a/rdfs:subClassOf* dbo:Organisation .
} ORDER BY ?org
}
LIMIT 10000 OFFSET 0
This would get you the first 10000 results. To get the next 10000, just add 10000 to the offset: LIMIT 10000 OFFSET 10000. Then, the next 10000 with OFFSET 20000, and so on.
You can get all organisations with a query like this, giving you English label and Wikipedia page for those resources that have it:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX o: <http://dbpedia.org/ontology/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT ?orgURI ?orgName ?Wikipedia_page
WHERE {
?orgURI a o:Organisation .
OPTIONAL { ?orgURI rdfs:label ?orgName .
FILTER (lang(?orgName) = "en") }
OPTIONAL { ?orgURI ^foaf:primaryTopic ?Wikipedia_page }
}
ORDER BY ?orgName
This will currently return 350033 results for those resources that are classified as http://dbpedia.org/ontology/Organisation.
To get also the members of subclasses of http://dbpedia.org/ontology/Organisation, you can change the first pattern by turning the property into a property path going though zero or more rdfs:subClassOf:
?orgURI a/rdfs:subClassOf* o:Organisation
Related
I am trying to get children of persons. Some persons have children listed in "dbo:child", others have them listed as "is dbo:parent of"
Here are examples of the two types
https://dbpedia.org/page/Elizabeth_II
https://dbpedia.org/page/George_V
For the first one I can pull child records off as follows:
SELECT * WHERE {
<http://dbpedia.org/resource/Elizabeth_II>
dbo:child?child
}
For the second it's a bit harder as I think I have to find other records which point to George_V. I'm struggling to find anything that works, this is the best I can come up with
SELECT *
WHERE
{
?person a dbo:Person ;
dbo:parent [dbo:Person dbr:George_V]
}
limit 10
What's the best way to do this? Is there a way I can combine the two approaches?
Here's an example that solves the problem. Note, you have to look at the data for familial properties (relationship types) and then explore regarding data quality.
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
SELECT DISTINCT ?royal ?ancestor
WHERE {
{
<http://dbpedia.org/resource/Charles,_Prince_of_Wales>
<http://dbpedia.org/property/father>+ ?ancestor .
}
UNION
{
<http://dbpedia.org/resource/Charles,_Prince_of_Wales>
<http://dbpedia.org/property/mother>+ ?ancestor .
}
BIND ( <http://dbpedia.org/resource/Charles,_Prince_of_Wales> as ?royal )
}
Live DBpedia Query Solution Link.
Alternatively, which is closer to your original property preference (i.e., dbo:parent), here is another property-paths based example.
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/property/>
SELECT DISTINCT ?royal ?ancestor ?ancestorName
WHERE {
<http://dbpedia.org/resource/Elizabeth_II>
dbo:parent* ?ancestor .
?ancestor
foaf:name ?ancestorName .
FILTER (LANG(?ancestorName) = "en")
BIND ( <http://dbpedia.org/resource/Elizabeth_II> as ?royal )
}
Live Query Results Link.
We are working on a new DBpedia release that should have increased quality regarding this kind of information.
Finally, a tweak to some earlier suggestions (posted as comments).
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT DISTINCT ?royal ?child
WHERE {
dbr:George_V dbo:child+|^dbo:parent+ ?child .
BIND ( dbr:George_V AS ?royal )
}
Live DBpedia Query Link.
I want to get provenance data in DBpedia and here's the sample query:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?novel
WHERE {
?novel rdf:type dbo:Novel
} LIMIT 1000 OFFSET 0
This query returns list of novels' resource. How can I get provenance data for each resource, if it's possible?
For example In Ballast to the White Sea originated from Source A, Source A originated from Source B, Source B is originated from Source C, and so on.
You can only use current provenance data existing in the dataset which is declared by prov:wasDerivedFrom property. It gives info about the source(wikipedia page) triples are extracted from. So you can pose such a query:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX prov: <https://www.w3.org/ns/prov#>
SELECT DISTINCT ?novel ?prov
WHERE {
?novel rdf:type dbo:Novel.
?novel prov:wasDerivedFrom ?prov
} LIMIT 1000 OFFSET 0
I would like to get all Cities of India from DBpedia database.
I tried many stackoverflow solutions but till now i have not got my required output.
How to fetch all Cities of Country using SPARQL.
Might be (for sure) incomplete since data in DBpedia is based on mappings from Wikipedia (here only the infoboxes):
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
SELECT ?s WHERE {
?s a dbo:City ;
dbo:country dbr:India
}
Or you can try to use the Wikipedia categories:
PREFIX dbc: <http://dbpedia.org/resource/Category:>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT DISTINCT ?s WHERE {
?s dct:subject/skos:broader* dbc:Cities_and_towns_in_India
}
I got solution to get Cities of Country. For Example if we want to fetch cities of India then use dbr:India in your Query
SELECT DISTINCT ?placeName WHERE {
?placeName a yago:City108524735 ; dbo:country dbr:India
}
Thanks #AKSW for your help.
I need to get all awarded movies on 80th Award Ceremony
I tried to write SPARQL query:
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix dbpedia-owl: <http://dbpedia.org/ontology/>
prefix movie: <http://data.linkedmdb.org/resource/movie/>
prefix award: <http://data.linkedmdb.org/page/film_awards_ceremony/180/>
select distinct ?film ?award where {
{ ?film a movie:film.
?award a movie:film_awards_ceremony.
} union
{ ?film a dbpedia-owl:Film }
?film rdfs:label ?label .
}
But the result is full movies list.
I found the data I need also here: https://www.freebase.com/m/02pgky2
How to combine (union) these entities in a right way ?
If is not possible - How to get the result from freebase using SPARQL and dbpedia.org?
On this site, for example, take the first SPARQL query and make something very similar:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX p: <http://dbpedia.org/property/>
SELECT *
WHERE {
?name p:name <http://dbpedia.org/resource/Olivier_Theyskens> .
}
Try to execute it: here
And I get no results. However, modify the query to the following:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX p: <http://dbpedia.org/property/>
SELECT *
WHERE {
?name p:name ?otherthing.
}
And I get results, even though they're not the results I want.
Why doesn't the first query work -- what am I doing wrong? :/
In this case, I think it's because you're ordering your query statement backwards.
The DBpedia resource (<http://dbpedia.org/resource/Olivier_Theyskens>) is the Entity or Subject (?s), the property (p:name) is the Attribute or Predicate (?p), and the value of that property (?name) is the Value or Object (?o).
SPARQL expects all statements to be { ?s ?p ?o }, but yours seems to be written as { ?o ?p ?s }...
To sum up, if you try this query --
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX p: <http://dbpedia.org/property/>
SELECT *
WHERE
{
<http://dbpedia.org/resource/Olivier_Theyskens> p:name ?name .
}
-- you'll get the results I think you want.
The problem with your first query is that p:name links to Literal and you try to match a URI.
If you want your first query to work you have to to use the property http://dbpedia.org/ontology/artist that links to the URI and not the literal:
SELECT *
WHERE {
?s <http://dbpedia.org/ontology/artist> <http://dbpedia.org/resource/The_Velvet_Underground> .
}
Notice the different name space for the property <http://dbpedia.org/ontology/artist> this namespace contains ontology instead of property - ontology is the one used for object properties.