I'm trying to query DBPedia using SPARQL only to find company information such as a description, and a logo.
I'm rather lost with devising the SPARQL Query to do this.
SELECT DISTINCT ?subject
?employees
?homepage
WHERE
{
?subject rdf:type <http://dbpedia.org/class/yago/Company108058098> .
?subject dbpedia2:numEmployees ?employees
FILTER ( xsd:integer(?employees) >= 50000 ) .
?subject foaf:homepage ?homepage .
}
ORDER BY DESC(xsd:integer(?employees))
LIMIT 20
I have come across the above query, which finds companies with over 50,000 emplayoees, but I don't understand such things as the rdf type being "http://dbpedia.org/class/yago/Company108058098"
Well all I want to know is given a company name, how can I return a unique ID, logo and description? I just want 3 pieces of data back, which I can then store in my database.
To get all companies one have to use LIMIT and OFFSET because usually public endpoints limits number of results per query. Based on @Joshua answer I wrote a small script that can be run to get all companies from public dbpedia endpoint. Here is the gist: https://gist.github.com/szydan/e801fa687587d9eb0f6a
One can also modify the query and use it to get other entities.
The reason for
rdf:type <http://dbpedia.org/class/yago/Company108058098>
in a query like the following is because (presumably), that's a class whose instances are companies. Asking for instances of the class is a way of asking for companies.SPARQL results
It's the same principle that lets us select Persons with:
SPARQL results
As to your specific query, a typically good way to query DBpedia data is to start by looking at the data manually and finding the types of values you're interested in. For instance, you might look at Apple, Inc., whose DBpedia resource is
For the kinds of information that you're looking for, important properties seem to be:
You can simply use the resource IRI as the unique identifier. Given all this, you can write a query like the following. It has multiple results, though, because there are multiple possible logos, but so it goes.
SPARQL results
It would be nice to be able to use
as well, but the endpoint says in that case that the estimated time is too great:
I'm not sure how it estimates the time, but you can use some
optionals
and somevalues
to work around it (but be sure to putdistinct
into theselect
):Note: At time of writing, DBpedia's endpoint is very sluggish and under maintenance, so I'm not sure yet whether this last permutation actually hits the estimated time cutoff or not. I think that it will go through, though.