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

如何通过资源uri查询DBpedia SPARQL?,sparql,dbpedia,Sparql,Dbpedia,我正在通过资源的标签查询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-synta

我正在通过资源的标签查询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 .
}
}
但它不起作用

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

当您编写

?res a :Harry_Potter.
它不起作用,因为这意味着“一种资源,属于类型:哈利·波特”。相当于

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

我想你的意思是哈利波特(角色),因为那是实际的标识符,而不是重定向

您的查询将非常简单

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 .
  }
}
选择?类型?超类型,其中
{ 
#给我?资源的类型
类型?类型。
#给我一个超类型的
可选的{
?类型rdfs:子类?超类型。
}
}
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 .
  }
}