计算OWL本体中子类的深度 [英] Calculate the depth of subclass in the OWL ontology

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

问题描述

我正在寻找一个SPARQL查询,该查询可以返回OWL层次结构中指定子类的位置.我研究了几个示例,但我能达到的最佳结果是计算指定超类及其子类之间的相对路径(感谢Joshua泰勒).取而代之的是,我需要计算给定子类的绝对"深度.

I'm looking for a SPARQL query that could return the position of specified subclass in the OWL hierarchy. I have studied several examples but the best result I could ever reach is the computation the relative paths between the specified superclass and its subclasses (thanks to Joshua Taylor). Instead of that I need to calculate the "absolute" depth for a given subclass.

我的本​​体包含几个顶级类,每个顶级类后面都有一个单独的子类树.这是我的OWL的一部分(已通过rdfcat实用程序转换为TTL):

My ontology contains several top-level classes and every of them is followed with a separate tree of subclasses. Here is part of my OWL (converted to TTL with a rdfcat utility):

@prefix :      <http://www.semanticweb.org/administrator/ontologies/2014/7/untitled-ontology-9#> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .

:depression  a              owl:Class ;
    rdfs:subClassOf  :pit .

:pit    a                owl:Class ;
    rdfs:subClassOf  :on_the_road .

:on_the_road  a            owl:Class ;
    rdfs:subClassOf  :traffic_accident .

:traffic_accident  a  owl:Class .

在这种情况下,对于给定的depression类,我希望获得 3 pit-> 2 on_the_road-> 1 traffc_accident(顶级类)->0.

In this case for a given depression class I expect to get 3, pit -> 2, on_the_road -> 1, traffc_accident (a top-level class) -> 0.

推荐答案

相同的方法在这里适用于在层次结构中查找类的深度(当然,假设每个类都有一个到根的唯一路径).诀窍只是您首先需要找到层次结构的根.您可以使用以下查询来获得以下结果.

The same approach works here for finding the depth of a class in a hierarchy (assuming, of course, that each class has a unique path to a root). The trick is just that you first need to find the roots of the hierarchy. You can do that with the following query to get the following results.

prefix : <http://www.semanticweb.org/administrator/ontologies/2014/7/untitled-ontology-9#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select ?class (count(?mid)-1 as ?depth) {
  #-- Select root classes (classes that have no
  #-- superclasses other than themselves).
  {
    select ?root {
      ?root a owl:Class
      filter not exists {
        ?root rdfs:subClassOf ?superroot 
        filter ( ?root != ?superroot )
      }
    }
  }

  ?class rdfs:subClassOf* ?mid .
  ?mid rdfs:subClassOf* ?root .
}
group by ?class
order by ?depth

-----------------------------
| class             | depth |
=============================
| :traffic_accident | 0     |
| :on_the_road      | 1     |
| :pit              | 2     |
| :depression       | 3     |
-----------------------------

请注意,如果您有推理机,事情可能会有些复杂.如果您有推理机,那么每个类,包括您的根,都是owl:Thing的子类,因此实际上只有一个根,并且所有深度都将相差一个(从您在问题中提到的内容).您可以通过调整查询中用于查找?root值的过滤器来避免这种情况.

Note that things may be a bit more complicated if you've got a reasoner. If you've got a reasoner, then every class, including your roots, is a subclass of owl:Thing, so there will actually only be one root, and all the depths will be off by one (from what you've mentioned in the question). You can avoid that by adjusting the filters in the query that finds values for ?root.

这篇关于计算OWL本体中子类的深度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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