3

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

2 Answers 2

4

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.

3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.