【问题标题】:retrieving most specific classes of instances检索最具体的实例类
【发布时间】:2013-11-07 02:51:07
【问题描述】:

是否可以使用 SPARQL 查询定义资源(来自 DBpedia)?我想要像(Conceptual) Clustering methods for the Semantic Web: issues and applications (slides 10–11) 中显示的 TBox 和 ABox 之类的东西。例如,对于 DBpedia 资源Stephen King,我想拥有:

Stephen_King : 人物 ⊓作家 ⊓男⊓ …(最具体的类)

【问题讨论】:

    标签: sparql owl dbpedia description-logic


    【解决方案1】:

    您可以使用类似以下的查询来询问斯蒂芬金是实例的类,哪些类没有斯蒂芬金也是实例的子类。这似乎与“最具体的类”的概念非常吻合。但是,由于(据我所知)没有附加到 DBpedia SPARQL 端点的推理器,因此可能存在可以推断但未明确存在于数据中的子类关系。

    select distinct ?type where { 
       dbr:Stephen_King a ?type .
      filter not exists { 
        ?subtype ^a  dbr:Stephen_King ;
                 rdfs:subClassOf ?type .
      }
    }
    

    SPARQL results

    实际上,由于每个类本身都是一个rdfs:subClassOf,您可能希望在该查询中添加另一行以排除?subtype?type 相同的情况:

    select distinct ?type where { 
       dbr:Stephen_King a ?type .
      filter not exists { 
        ?subtype ^a  dbr:Stephen_King ;
                 rdfs:subClassOf ?type .
        filter ( ?subtype != ?type )
      }
    }
    

    SPARQL results

    如果你真的想要一个像幻灯片中显示的结果字符串,你可以使用values 将一个变量绑定到dbr:Stephen_King,然后使用一些分组和字符串连接来获得更好看的东西(有点) :

    select
      (concat( ?person, " =\n", group_concat(?type; separator=" AND\n")) as ?sentence)
    where { 
      values ?person {  dbr:Stephen_King }
      ?type ^a ?person .
      filter not exists { 
        ?subtype ^a ?person ;
                 rdfs:subClassOf ?type .
        filter ( ?subtype != ?type )
      }
    }
    group by ?person
    

    SPARQL results

    http://dbpedia.org/resource/Stephen_King =
    http://dbpedia.org/class/yago/AuthorsOfBooksAboutWritingFiction AND
    http://dbpedia.org/ontology/Writer AND
    http://schema.org/Person AND
    http://xmlns.com/foaf/0.1/Person AND
    http://dbpedia.org/class/yago/AmericanSchoolteachers AND
    http://dbpedia.org/class/yago/LivingPeople AND
    http://dbpedia.org/class/yago/PeopleFromBangor,Maine AND
    http://dbpedia.org/class/yago/PeopleFromPortland,Maine AND
    http://dbpedia.org/class/yago/PeopleFromSarasota,Florida AND
    http://dbpedia.org/class/yago/PeopleSelf-identifyingAsAlcoholics AND
    http://umbel.org/umbel/rc/Artist AND
    http://umbel.org/umbel/rc/Writer AND
    http://dbpedia.org/class/yago/20th-centuryNovelists AND
    http://dbpedia.org/class/yago/21st-centuryNovelists AND
    http://dbpedia.org/class/yago/AmericanHorrorWriters AND
    http://dbpedia.org/class/yago/AmericanNovelists AND
    http://dbpedia.org/class/yago/AmericanShortStoryWriters AND
    http://dbpedia.org/class/yago/CthulhuMythosWriters AND
    http://dbpedia.org/class/yago/HorrorWriters AND
    http://dbpedia.org/class/yago/WritersFromMaine AND
    http://dbpedia.org/class/yago/PeopleFromDurham,Maine AND
    http://dbpedia.org/class/yago/PeopleFromLisbon,Maine AND
    http://dbpedia.org/class/yago/PostmodernWriters
    

    【讨论】:

    • @BlockER 是的,DBpedia 更改了在其公共端点中预定义的命名空间。我已经回答了很多基于 DBpedia 的 SPARQL 查询,以至于我无法真正回去修复它们。我认为对于这些,您只需要将 dbpedia: 替换为 dbr:。或者定义 dbpedia: 前缀。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多