Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all organisations from DBPedia?

Tags:

sparql

dbpedia

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.

like image 526
Josef says Reinstate Monica Avatar asked Feb 07 '23 04:02

Josef says Reinstate Monica


1 Answers

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.

like image 99
evsheino Avatar answered Mar 07 '23 09:03

evsheino