检索最具体的实例类 [英] retrieving most specific classes of instances

查看:104
本文介绍了检索最具体的实例类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过SPARQL查询定义资源(来自DBpedia)?我想在(概念)聚类方法中显示TBox和ABox之类的东西 语义网:问题和应用(幻灯片10-11).例如,对于DBpedia资源 Stephen King ,我希望拥有:

Is it possible to have a definition of an resource (from DBpedia) with a SPARQL query? I want to have something like the TBox and ABox that are shown in (Conceptual) Clustering methods for the Semantic Web: issues and applications (slides 10–11). For example, for DBpedia resource Stephen King, I would like to have:

Stephen_King:人⊓作家⊓男性⊓ …(最具体的课程)

Stephen_King : Person ⊓ Writer ⊓ Male ⊓ … (most specific classes)

推荐答案

您可以使用类似以下的查询来询问Stephen King是实例的类,而没有Stephen King也是实例的子类.这似乎与最具体的类"的思想很好地吻合.但是,由于(据我所知)DBpedia SPARQL端点没有附加推理程序,因此可能可以推断出子类关系,但这些子类关系未明确显示在数据中.

You can use a query like the following to ask for the classes of which Stephen King is an instance which have no subclasses of which Stephen King is also an instance. This seems to align well with the idea of "most specific classes." However, since (as far as I know) there's no reasoner attached to the DBpedia SPARQL endpoint, there may be subclass relationships that could be inferred but which aren't explicitly present in the data.

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

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

Actually, since every class is an rdfs:subClassOf itself, you might want to add another line to that query to exclude the case where ?subtype and ?type are the same:

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

如果您实际上想要像那些幻灯片中显示的那样的结果字符串,则可以使用values将变量绑定到dbr:Stephen_King,然后使用一些分组和字符串连接以获得更好看的外观(某种) :

If you actually want a result string like the one shown in those slides, you could use values to bind a variable to dbr:Stephen_King, and then use some grouping and string concatenation to get something nicer looking (sort of):

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

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆