耶拿api获取ObjectProperty的范围 [英] jena api get range of ObjectProperty

查看:94
本文介绍了耶拿api获取ObjectProperty的范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有OWL文件,可以浏览它并浏览类和属性,但无法检索到正确的ObjectProperty范围. 这是我的OWL文件的一部分:

I've and OWL file and I can explore it and navigate through classes and properties but I can't retrieve correct range of ObjectProperty. This is part of my OWL file:

<owl:ObjectProperty rdf:about="&aat;aat2209_located_in">
        <rdfs:label xml:lang="en">located in</rdfs:label>
        <rdfs:label xml:lang="it">si trova in</rdfs:label>
        <rdfs:comment xml:lang="en">The property defines a relationship between places or places and things</rdfs:comment>
        <rdfs:comment xml:lang="it">La proprietà definisce la relazione tra luoghi o tra luoghi e cose</rdfs:comment>
        <rdfs:domain>
            <owl:Class>
                <owl:unionOf rdf:parseType="Collection">
                    <rdf:Description rdf:about="&dbpedia-owl;Artwork"/>
                    <rdf:Description rdf:about="&dbpedia-owl;Cave"/>
                </owl:unionOf>
            </owl:Class>
        </rdfs:domain>
        <rdfs:range>
            <owl:Class>
                <owl:unionOf rdf:parseType="Collection">
                    <rdf:Description rdf:about="&lodmt;ArchaeologicalSite"/>
                    <rdf:Description rdf:about="&dbpedia-owl;Building"/>
                </owl:unionOf>
            </owl:Class>
        </rdfs:range>
    </owl:ObjectProperty>

这是我探索OWL文件的代码的一部分

And this is part of my code to explore OWL file

...    
OntModel inf = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
            InputStream in =getClass().getResourceAsStream("/"+DATA_IRI);
            inf.read(in, "");
            OntClass obj = inf.getOntClass(uri);
            ExtendedIterator<OntProperty> propIter = obj.listDeclaredProperties(false);
            if(propIter.hasNext()){
                while (propIter.hasNext()) {
                    Set<PropertyModel> properties = new HashSet<PropertyModel>();
                    final OntProperty ontProperty = (OntProperty) propIter.next();
                    ExtendedIterator<? extends OntProperty> eqProp = ontProperty.listEquivalentProperties();
                    if(eqProp.hasNext()){
                        while (eqProp.hasNext()) {
                            OntProperty property = (OntProperty) eqProp.next();
                            PropertyModel propModel = new PropertyModel();
                            propModel.setLabel(property.getLocalName());
                            propModel.setUri(property.getURI());
                            propModel.setRange(property.getRange().getLocalName());
                            properties.add(propModel);
                        }
                    }
    ...

每次我打电话给property.getRange(),我都会得到以下结果: http://www. w3.org/2002/07/owl#Thing .

Everytime I call property.getRange() I've this result: http://www.w3.org/2002/07/owl#Thing.

有人帮我吗?

推荐答案

如果您提供完整但最少的数据以供使用,那就容易得多.在这种情况下,我将您的数据修改为以下数据,这是完整的,因为它是可加载的RDF文档,而最小的是,它仅包含对象属性声明和范围公理.

It's ever so much easier if you provide complete but minimal data to work with. In this case, I've modified your data to be the following, which is complete in that it's a loadable RDF document, and minimal in that it only contains the object property declaration and the range axiom.

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:ObjectProperty rdf:about="http://stackoverflow.com/q/24250198/1281433/aat2209_located_in">
        <rdfs:range>
            <owl:Class>
                <owl:unionOf rdf:parseType="Collection">
                    <rdf:Description rdf:about="http://stackoverflow.com/q/24250198/1281433/ArchaeologicalSite"/>
                    <rdf:Description rdf:about="http://stackoverflow.com/q/24250198/1281433/Building"/>
                </owl:unionOf>
            </owl:Class>
        </rdfs:range>
    </owl:ObjectProperty>
</rdf:RDF>

以下代码将其加载并显示该属性的范围:

The following code loads it and shows the range(s) of the property:

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntProperty;
import com.hp.hpl.jena.ontology.OntResource;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;

public class RangeExample {
    public static void main(String[] args) {
        OntModel model = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_RULE_MEM_INF );
        model.read( "..../data.owl" );
        OntProperty locatedIn = model.getOntProperty( "http://stackoverflow.com/q/24250198/1281433/aat2209_located_in" );
        ExtendedIterator<? extends OntResource> ranges = locatedIn.listRange();
        while ( ranges.hasNext() ) { 
            System.out.println( ranges.next() );
        }
    }
}

对我来说输出是

http://www.w3.org/2002/07/owl#Thing
-3e020093:146a7247e66:-7ffb
http://www.w3.org/2000/01/rdf-schema#Resource

owl:Thing和rdfs:Resource在那里,因为只要您拥有x located_in y,就可以确保y是owl:Thing和rdfs:Resource,因为located_in是对象属性.另一个-3e020093:146a7247e66:-7ffb是RDF空白节点的标识符,它是OWL联合类表达式.

owl:Thing and rdfs:Resource are there because anytime you have x located_in y, you can be sure that y is an owl:Thing and an rdfs:Resource, since located_in is an object property. The other one, -3e020093:146a7247e66:-7ffb, is the identitifier of the RDF blank node that is the OWL union class expression.

根据以下评论,听起来似乎需要更多讨论.

Based on the following comment, it sounds like a bit more discussion is needed.

我获得了相同的结果,但是我将获得ArchaeologicalSite和Building.

I obtain same result, but I would obtain ArchaeologicalSite and Building as result.

您询问了声明的特定对象属性的范围.在OWL中,属性p的范围是任何D类,例如" if p(x,y), then D(y)".也就是说,以RDF术语来说,如果属性p的D为范围,那么只要存在三元组x p y,那么您还可以推断出三元组y rdf:type D.这是规则:

You asked for the range(s) of a particular object property that you declared. In OWL, a range of a property p is any class D such that "if p(x,y), then D(y)". That is, in RDF terms, if you a property p's has D as a range, then whenever there is a triple x p y, then you can also infer the triple y rdf:type D. This is the rule:

x p y     p rdfs:range D
-----------------------
   y rdf:type D

您要询问的范围是联合类.您的课程规则的实例如下:

The range that you're asking about is a union class. An instance of the rule for your class would be like:

x located_in y     located_in rdfs:range (ArchaeologicalSite OR Building)
-------------------------------------------------------------------------
     y rdf:type (ArchaeologicalSite OR Building)

推断

y rdf:type ArchaeologicalSite

或那个

y rdf:type Building

因为这是比x located_in y中更多的信息.以此类推,请考虑以下示例:

because that's more information than you have in x located_in y. For analogy, consider this example:

  1. 您可以在开胃菜中喝汤或沙拉. (hasAppetizer的范围是汤或沙拉".)
  2. 您的开胃菜有一些未知的x.

从这些中,我可以推断出x是汤还是色拉,但是我不能推断出哪个是特定的.因此,汤或色拉"是一系列的开胃菜,但是汤和色拉都不是单独的.

From those, I can infer that x is either soup or salad, but I can't infer which particular one. Thus "soup or salad" is a range of hasAppetizer, but neither soup nor salad alone is.

这篇关于耶拿api获取ObjectProperty的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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