Nikko
Nikko

Reputation: 1286

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:

WHERE

AND

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

Upvotes: 3

Views: 855

Answers (2)

Joshua Taylor
Joshua Taylor

Reputation: 85813

This can be written much more cleanly using values. You can use values to specify the properties that might identify the name. Additionally, Google doesn't have a resource value for dbpprop:type (at least not anymore); it's better to stick with rdf:type and dbpedia-owl:Company. That means your query can become:

select distinct ?s where {
  values ?name { foaf:name dbpprop:companyName dbpprop:name }
  ?s a dbpedia-owl:Company ;
     ?name "Google Inc."@en .
}

SPARQL results

Upvotes: 3

Alex
Alex

Reputation: 13941

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.

Upvotes: 4

Related Questions