[英]Object Properties restrictions - jena
How can I determine the object properties restrictions for a class in Jena . 如何确定Jena中的类的对象属性限制。
I have been trying to determinate if a class has a object restriction by using something like this: 我一直在尝试通过使用类似这样的方法来确定一个类是否具有对象限制:
if (essaClasse.isRestriction())
{
System.out.println( "Restriction on property " +
essaClasse.asRestriction().getOnProperty() );
}
else
{
System.out.println( "There is not restriction" );
}
but I got : "There is not restriction" 但我得到:“没有限制”
The owl file has a class (UserModel) which has the following 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>
If we look at the implementation of OntClass#isRestriction()
, we see that it requires the ability to find a specific triple in the underlying graph in order to identify that it is, indeed, on a restriction. 如果我们看一下
OntClass#isRestriction()
,我们会发现它要求能够在基础图中找到特定的三元组,以便确定它确实在约束上。 Specifically, it looks for ?instance rdf:type ?obj
where ?obj
is specified by your profile. 具体来说,它将查找
?instance rdf:type ?obj
,其中?obj
由您的配置文件指定。
Let us assume that you have an OWL profile in play. 让我们假设您正在使用OWL个人资料。 Then
OWLProfile#RESTRICTION()
specifies that, in order to be interpreted as a Restriction
, the resource in question needs to of type owl:Restriction
. 然后
OWLProfile#RESTRICTION()
指定,为了将其解释为Restriction
,所讨论的资源需要为owl:Restriction
类型。
You do have objects in your ontology that are of that type, but your code example does not expose whether or not you are referencing them. 您的本体中确实有这种类型的对象,但是您的代码示例并未公开您是否在引用它们。 If, in your code example, your
essaClasse
is referencing :&geosim2;UserModel
, then your code is doing exactly what it should. 如果在您的代码示例中,
essaClasse
引用了:&geosim2;UserModel
,则您的代码正在执行应有的工作。 &geosim2;UserModel
is not a restriction, but it is rdfs:subClassOf
things which are . &geosim2;UserModel
不是限制,但它rdfs:subClassOf
东西是 。
TL;DR: TL; DR:
You need to list the super-classes of the class of interest (using OntClass#listSuperClasses()
, and then identify if those are restrictions. That will then give you the restrictions on your class. 您需要列出感兴趣的类的超类(使用
OntClass#listSuperClasses()
,然后确定这些类是否是限制,然后才能为您的类提供限制)。
In code that may not compile (written off the top of my head): 在可能无法编译的代码中(写在脑海中):
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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.