Search code examples
sparqldbpedia

What is the correct SPARQL version for this query?


I'm trying to run a query on DBPedia.org via SPARQL. Basically, here's what I want to do:

  • Get a list of DBPedia resource links

WHERE

  • foaf:name (http://xmlns.com/foaf/0.1/name) is equal to PARAMETER1
  • Or dbpprop:companyName (http://dbpedia.org/property/companyName) is equal to PARAMETER1
  • Or dbpprop:name (http://dbpedia.org/property/name) is equal to PARAMETER1

AND

  • rdf:type (http://www.w3.org/1999/02/22-rdf-syntax-ns#type) is equal to PARAMETER2
  • Or dbpedia-owl:type (http://dbpedia.org/ontology/type) is equal to PARAMETER2

I've tried doing this myself, but utterly failed to get any successful results.

Any help will be appreciated - thanks!

Edit: Here's a query that I've been working on:

SELECT ?s
WHERE {
    {
      ?s <http://xmlns.com/foaf/0.1/name> "Google Inc." .
    } UNION {
      ?s <http://dbpedia.org/property/companyName> "Google Inc." .
    } UNION {
      ?s <http://dbpedia.org/property/name> "Google Inc." .
    }

    {
      ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Company> .
    } UNION {
      ?s <http://dbpedia.org/ontology/type> <http://dbpedia.org/resource/Public_company> .
    }
}

Solution

  • You almost had it, the only problem is that property values in DBPedia use language tags and your query looks for names with plain literal values. This query works for me:

    SELECT DISTINCT ?s
    WHERE {
        {
          ?s <http://xmlns.com/foaf/0.1/name> "Google Inc."@en .
        } UNION {
          ?s <http://dbpedia.org/property/companyName> "Google Inc."@en .
        } UNION {
          ?s <http://dbpedia.org/property/name> "Google Inc."@en .
        }
    
        {
          ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/ontology/Company> .
        } UNION {
          ?s <http://dbpedia.org/ontology/type> <http://dbpedia.org/resource/Public_company> .
        }
    }
    

    Note that I added a DISTINCT to eliminate duplicate answers that arise when a resource has multiple values, e.g. for foaf:name and dbpprop:companyName.