Java 对象属性限制-jena

Java 对象属性限制-jena,java,api,jena,Java,Api,Jena,如何确定Jena中类的对象属性限制 我一直在尝试通过使用以下内容来确定类是否具有对象限制: if (essaClasse.isRestriction()) { System.out.println( "Restriction on property " + essaClasse.asRestriction().getOnProperty()

如何确定Jena中类的对象属性限制

我一直在尝试通过使用以下内容来确定类是否具有对象限制:

         if (essaClasse.isRestriction()) 
                    {
                        System.out.println( "Restriction on property " + 
                        essaClasse.asRestriction().getOnProperty() );
                    }
         else 
                    {
                        System.out.println( "There is not restriction"  );
                    }
但我得到了:“没有限制”

owl文件有一个类(UserModel),该类具有以下限制:

<owl:Class rdf:about="&geosim2;UserModel">
     <rdfs:label xml:lang="en">UserModel</rdfs:label>
     <rdfs:subClassOf rdf:resource="&geosim2;Model"/>
     <rdfs:subClassOf>
         <owl:Restriction>
            <owl:onProperty rdf:resource="&geosim2;hasPeople"/>
            <owl:minCardinality   rdf:datatype="&xsd;nonNegativeInteger">1</owl:minCardinality>
        </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
        <owl:Restriction>
            <owl:onProperty rdf:resource="&geosim2;hasPhysicalPlace"/>
            <owl:minCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:minCardinality>
        </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:isDefinedBy rdf:datatype="&xsd;string">http://dit.upm.es/~perez/geosim/0.1.3/ns.owl#</rdfs:isDefinedBy>
    <rdfs:comment xml:lang="en">An instance of this class models a user simulation model.</rdfs:comment>
</owl:Class>

用户模型
1.
1.
http://dit.upm.es/~perez/geosim/0.1.3/ns.owl#
此类的实例为用户仿真模型建模。

如果我们看一下的实现,我们会发现它需要能够在基础图中找到一个特定的三元组,以便确定它确实在一个限制上。具体来说,它查找
?实例rdf:type?obj
,其中
?obj
由您的配置文件指定

让我们假设您有一个猫头鹰配置文件。然后指定,为了被解释为
限制
,所讨论的资源需要类型为

您的本体中确实有这种类型的对象,但您的代码示例不会公开您是否引用它们。如果在代码示例中,您的
essaClasse
正在引用
:&geosim2;UserModel
,则您的代码正是它应该做的<代码>&geosim2;UserModel不是一个限制,但它是rdfs的子类

TL;医生:

您需要列出感兴趣的类的超类(使用),然后确定这些是否是限制。这将为您提供对类的限制

在可能无法编译的代码中(在我脑海中写下):

final extendede迭代器超类=esseClasse.ListSuperclass();
while(超类.hasNext()){
final OntClass aParent=superClass.next();
if(aParent.isRestriction()){
//做有趣的事
}
否则{
//做其他有趣的事情
}
}

您的代码是如何设置essaClasse的?
final ExtendedIterator<OntClass> superClass = esseClasse.listSuperClasses();
while( superClass.hasNext() ) {
    final OntClass aParent = superClass.next();
    if( aParent.isRestriction() ) {
        // Do interesting things
    }
    else {
        // Do other interesting things
    }
}