【问题标题】:How to query DBpedia SPARQL by resource uri?如何通过资源 uri 查询 DBpedia SPARQL?
【发布时间】:2026-02-01 23:15:03
【问题描述】:

我正在按资源标签查询 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 等,它们不起作用)

【问题讨论】:

    标签: sparql dbpedia


    【解决方案1】:

    当你写作时

    ?res a :Harry_Potter.
    

    它不起作用,因为这意味着“资源,类型为 :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 .
      }
    }
    

    【讨论】:

      【解决方案2】:

      您可以将 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 .
      }
      

      【讨论】: