Search code examples
rdfsparqlwikipediadbpedia

Using SPARQL to query DBPedia Company Information


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.


Solution

  • 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.

    select * { ?s rdf:type <http://dbpedia.org/class/yago/Company108058098> }
    limit 10
    

    SPARQL results

    It's the same principle that lets us select Persons with:

    select * { ?s a dbpedia-owl:Person }
    limit 10
    

    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.

    select ?iri ?logo ?description {
      ?iri a dbpedia-owl:Company ;
           dbpedia-owl:abstract ?description ;
           rdfs:label "Apple Inc."@en ;
           foaf:depiction|dbpedia-owl:thumbnail ?logo .
      filter( langMatches(lang(?description),"en") )
    }
    

    SPARQL results

    It would be nice to be able to use

    foaf:name|rdfs:label "Apple In."@en
    

    as well, but the endpoint says in that case that the estimated time is too great:

    Virtuoso 42000 Error The estimated execution time 9320 (sec) exceeds the limit of 3000 (sec).

    I'm not sure how it estimates the time, but you can use some optionals and some values to work around it (but be sure to put distinct into the select):

    select distinct ?iri ?logo ?description {
      values ?hasLogo { foaf:depiction dbpedia-owl:thumbnail }
      values ?hasName { foaf:name rdfs:label }
      ?iri a dbpedia-owl:Company ;
           dbpedia-owl:abstract ?description ;
           ?hasLName "Apple Inc."@en ;
           ?hasLogo ?logo .
      filter( langMatches(lang(?description),"en") )
    }
    

    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.