简体   繁体   English

OWL,Protege:从DefaultOWLObjectProperty值获取到个人的类

[英]OWL, Protege: Getting from a DefaultOWLObjectProperty value to the class of an individual

I'm trying to use the Stanford OWL API, and I find the documentation a bit unclear. 我正在尝试使用Stanford OWL API,但发现文档尚不清楚。 Using Java, I load an ontology which has been prepared by some user via Protégé, and get to a DefaultOWLObjectProperty . 使用Java,我加载了某个用户通过Protégé准备的本体,并进入DefaultOWLObjectProperty The value of that property is meant to be an individual in some class in the ontology. 该属性的值是要成为本体中某个类别中的一个个体。 How can I find the class? 我如何找到课程? Code snippet below: 下面的代码段:

OWLNamedClass cls = (OWLNamedClass) it.next();

Collection instances = cls.getInstances(false);
for (Iterator jt = instances.iterator(); jt.hasNext();) {
    OWLIndividual individual = (OWLIndividual) jt.next();
    Collection props = individual.getRDFProperties();
    for (Object prop : props) {
        DefaultOWLObjectProperty obj = (DefaultOWLObjectProperty) prop;
        Object val = individual.getPropertyValue(obj);
        DefaultRDFIndividual valInd = (DefaultRDFIndividual) val;
…
}

I'd like to get the class of valInd . 我想获得valInd的类。

There are two methods in OWLIndividual that will make this easier for you. OWLIndividual中有两种方法可以使您更轻松地进行操作。 Let's assume you've got your OWLOntology as ontology . 假设您拥有OWLOntology作为ontology Then, using getObjectPropertyValues(OWLOntology) , you can get a map that maps a property expression to the set of individuals that are related to individual by that property. 然后,使用getObjectPropertyValues(OWLOntology) ,可以获得一个映射,该映射将属性表达式映射到通过该属性与individual相关的个体集合。 You can iterate over the entries of that map, and then iterate over the set of individuals. 您可以遍历该映射的条目,然后遍历一组个人。 Then, for each of those individuals, you can use getTypes(OWLOntology) to get the set of OWLClassExpressions that are its types. 然后,对每个那些个人的,你可以使用getTypes(OWLOntology)获得的一组是它的类型OWLClassExpressions的。 (You get a set of these rather than a single type, because OWL individuals can, and usually do, have more than one type.) (您可以得到一组这些类型,而不是单个类型,因为OWL个人可以并且通常确实拥有不止一种类型。)

If you're just interested in the values of certain properties, then you can use the more specialized getObjectPropertyValues(OWLObjectPropertyExpression,OWLOntology) to get just the values of a specific property for an individual. 如果您只对某些属性的值感兴趣,则可以使用更专业的getObjectPropertyValues(OWLObjectPropertyExpression,OWLOntology)来获取单个特定属性的值。

In general, I'd suggest at least skimming over all the methods that the OWLIndividual interface provides, just to have a general awareness of what you can do with it. 通常,我建议至少略读OWLIndividual接口提供的所有方法,以使您对使用该接口可以做什么有一个一般的认识。 You don't need to memorize all the details, but when you are approaching a problem, you'll have at least a vague thought that "I think the interface has something like that…" and you'll know where to look. 你不需要记住所有的细节,但是当你接近一个问题,您至少有一个模糊的想法:“我认为,接口有类似的东西 ......”,你就会知道去哪里找。 This is good practice with any API or tool, not just the OWL API. 这是使用任何API或工具(不仅仅是OWL API)的良好做法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM