2
votes

I'm querying DBpedia types in SPARQL (http://dbpedia.org/sparql) by resource's label

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX : <http://dbpedia.org/resource/>
PREFIX ru: <http://ru.dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX dbo: <http://dbpedia.org/ontology/>

SELECT ?type ?superType WHERE { {
  ?res rdfs:label "HarryPotter"@en.
} UNION {
  ?redir dbo:wikiPageRedirects ?res .
  ?redir rdfs:label "HarryPotter"@en .
}
?res rdf:type ?type .
OPTIONAL {
  ?type rdfs:subClassOf ?superType .
}
}

It works fine.

But what if I know the exact resource - http://dbpedia.org/page/Harry_Potter? I tried something like:

?res a :Harry_Potter.

But it does not work.

How to query DBpedia types and supertypes if I know the resource URI? I can't figure out which property or operator I should use (e.g., rdfs:Resource, a, etc., which do not work)

2

2 Answers

4
votes

When you write

?res a :Harry_Potter.

It doesn't work, because this means "a resource, which is of type :Harry_Potter". It is equivalent to

?res rdf:type :Harry_Potter.

:Harry_Potter identifies a resource and not the type, thus it should be used in place of ?res.

Also I think you mean Harry_Potter_(character), because that is the actual identifier and not redirect.

You query would be as simple as

SELECT ?type ?superType WHERE 
{ 
  # give me ?type of the resource
  <http://dbpedia.org/resource/Harry_Potter_(character)> rdf:type ?type .

  # give me ?superTypes of ?type
  OPTIONAL {
   ?type rdfs:subClassOf ?superType .
  }
}
0
votes

You can just put the URI as the subject in there WHERE conditions.

SELECT ?title, ?releaseDate
WHERE {
  <http://dbpedia.org/resource/Super_Mario_Bros._3> dbp:title  ?title .
  <http://dbpedia.org/resource/Super_Mario_Bros._3> dbo:releaseDate ?releaseDate .
}