在类层次结构中查找共同的超类和路径长度 [英] finding common superclass and length of path in class hierarchies

查看:87
本文介绍了在类层次结构中查找共同的超类和路径长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有来自DBpedia的两个班,A和B.如何计算每个类到一个公共超类C的距离(边数),以及如何找到这个公共超类?

I have two classes, A and B, from DBpedia. How can I calculate the distance (number of edges) from each class to a common superclass C, and how can I find this common superclass?

推荐答案

您可以执行此操作,但首先应注意以下几点:

You can do this, but a couple of things should be noted first:

  1. 两个类可能有许多共同的超类,而不一定只有一个.这意味着可能没有唯一的最专业的通用超类.
  2. 如果某个类C是A和B的超类,那么C的每个超类也是 A和B的超类.
  3. D类可能是C由多个路径组成的超类,如果您要计算长度,可能会造成一些困难.例如

  1. Two classes may have lots of superclasses in common, not necessarily just one. This means that there may not be a unique most specialized common superclass.
  2. If some class C is a superclass of A and B, then every superclass of C is also a superclass of A and B.
  3. A class D might be a superclass of C by multiple paths, which can cause some difficulties if you're trying to compute length. E.g.,

Computer Hardware
  Monitors
    Flatscreen Monitors
      Dell Flatscreen Monitors  *
  Dell Hardware
    Dell Flatscreen Monitors    *

在此层次结构中,Dell Flatscreen Monitors是计算机硬件的子类,其长度为2(DFM→ DH→ CH),长度为3(DFM→ FM→ M→ CH) .很好,但是如果您要计算从DFM到CH的另一个子类的长度,应该使用哪个?

In this hierarchy, Dell Flatscreen Monitors is a subclass of Computer Hardware by a path of length 2 (DFM → DH → CH) and by a path of length 3 (DFM → FM → M →CH). That's fine, but if you're computing a length from DFM to another subclass of CH, which of those should you use?

假设您可以解决这些问题所需的细节,这并不难.我认为,逐步建立此查询是最简单的.首先,使用类似的查询,您可以获取一个类的超类以及每个超类的路径长度.这确实假定存在从子类到超类的唯一路径.如果有多个路径,我认为报告的长度将是不同路径的总和.我不确定您如何解决这个问题.

Assuming that you can work out the details that you need to address those issues, this isn't too hard. It's easiest, in my opinion, to build up this query step by step. First, using a query like this, you can get the superclasses of a class, and the length of the path to each of the superclasses. This does presume that there is a unique path from the subclass to the superclass. If there are multiple paths, I think the length reported will be the sum of the different paths. I'm not sure how you could get around this.

select ?sub ?super (count(?mid) as ?length) where {
  values ?sub { dbpedia-owl:Person } 
  ?sub rdfs:subClassOf* ?mid .
  ?mid rdfs:subClassOf+ ?super .
}
group by ?sub ?super

现在的诀窍是对两个子类都使用这种方法,然后使用类似的查询,根据它们共有的超类将结果联接起来:

Now the trick is to use this approach for both the subclasses, and then join the results based on the superclasses that they have in common, using a query like this:

select * 
{
  values (?a ?b) { (dbpedia-owl:Person dbpedia-owl:SportsTeam) }

  { select ?a ?super (count(?mid) as ?aLength) { 
      ?a rdfs:subClassOf* ?mid .
      ?mid rdfs:subClassOf+ ?super .
    }
    group by ?a ?super
  }
  { select ?b ?super (count(?mid) as ?bLength) { 
      ?b rdfs:subClassOf* ?mid .
      ?mid rdfs:subClassOf+ ?super .
    }
    group by ?b ?super
  }
}

该查询仍会找到 all 通用超类的路径长度,而不仅仅是最特定的超类,并且它仍未将?a?super的长​​度以及?super以获得完整的路径长度.不过,这只是一些算术运算.您可以按长度排序这些结果,然后将结果限制为仅一个,以便获得最短的结果.正如我所指出的那样,可能没有唯一的最特定的通用子类,但是最短的结果将是最特定的通用子类中的一个.

That query still finds the path lengths for all the common superclasses, not just most specific ones, and it's still not adding the length from ?a to ?super and the length from ?b to ?super to get the full path length. That's just a bit of arithmetic though. You can order these results by the length, and then limit to just one result so that you're getting the shortest one. As I pointed out, there might not be a unique most specific common subclasses, but the result with the shortest length will be one of the most specific common subclasses.

select ?a ?b ?super (?aLength + ?bLength as ?length)
{
  values (?a ?b) { (dbpedia-owl:Person dbpedia-owl:SportsTeam) }

  { select ?a ?super (count(?mid) as ?aLength) { 
      ?a rdfs:subClassOf* ?mid .
      ?mid rdfs:subClassOf+ ?super .
    }
    group by ?a ?super
  }
  { select ?b ?super (count(?mid) as ?bLength) { 
      ?b rdfs:subClassOf* ?mid .
      ?mid rdfs:subClassOf+ ?super .
    }
    group by ?b ?super
  }
}
order by ?length
limit 1

查看全文

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