如何通过资源uri查询DBpedia SPARQL?

How to query DBpedia SPARQL by resource uri?

我在 SPARQL (http://dbpedia.org/sparql) 中按资源标签查询 DBpedia 类型

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.

但是如果我知道确切的资源怎么办 - http://dbpedia.org/page/Harry_Potter?我试过类似的东西:

?res a :Harry_Potter.

但是不行。

如果我知道资源URI,如何查询DBpedia 类型和超类型?我不知道应该使用哪个 属性 或运算符(例如,rdfs:Resourcea 等,它们不起作用)

写的时候

?res a :Harry_Potter.

它不起作用,因为这意味着 "a resource, which is of type :Harry_Potter"。相当于

?res rdf:type :Harry_Potter.

:Harry_Potter 标识资源而不是类型,因此应该使用它来代替 ?res

另外我认为你的意思是 Harry_Potter_(character),因为那是实际的标识符而不是重定向。

您的查询会像

一样简单
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 .
  }
}

您可以将 URI 作为主题放在 WHERE 条件中。

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