如何确定 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>
最佳答案
如果我们看一下 OntClass#isRestriction()
的实现,我们看到它需要能够在底层图中找到特定的三元组,以便确定它确实受到限制。具体来说,它会查找 ?instance rdf:type ?obj
,其中 ?obj
由您的配置文件指定。
让我们假设您正在使用 OWL 个人资料。然后OWLProfile#RESTRICTION()
指定,为了被解释为限制
,相关资源的类型需要为 owl:Restriction
.
您的本体中确实有该类型的对象,但您的代码示例并未公开您是否正在引用它们。如果在您的代码示例中,您的 essaClasse
正在引用 :&geosim2;UserModel
,那么您的代码就完全执行了它应该执行的操作。 &geosim2;UserModel
不是限制,但它是rdfs:subClassOf
东西是。
TL;博士:
您需要列出感兴趣的类的父类(super class)(使用 OntClass#listSuperClasses()
,然后确定这些是否是限制。然后,这将为您提供对您的类的限制。 p>
在可能无法编译的代码中(写在我的脑海中):
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
}
}
关于java - 对象属性限制 - jena,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23460934/