[英]How to retrieve properties that were instantiated by owl class instance in OWL API?
Using the OWL API, I'm trying to check whether a sub-class has actually instantiated the object properties that set it apart from those it inherits from the parent class. 使用OWL API,我试图检查子类是否实际上实例化了将其属性与从父类继承的对象属性区分开的对象属性。
Is there a way to get the properties an instance has defined? 有没有办法获取实例定义的属性? My current approach is attempting to get the instances of an OWLClass as follows:
我当前的方法是尝试获取OWLClass的实例,如下所示:
// OWLClass o_class <---valid OWLClass object (e.g. City, Capital, etc)
Set<OWLNamedIndividual> o_instances = reasoner.getInstances(o_class, true).getFlattened();
for (OWLNamedIndividual> inst : o_instances) {
//get set of properties defined by each instance
}
I've tried a few different methods, to no avail. 我尝试了几种不同的方法,但没有成功。
inst.getObjectPropertiesInSignature()
returns nothing. inst.getObjectPropertiesInSignature()
返回任何内容。 An sample of one of the OWL files I'm using is shown below: 下面显示了我正在使用的OWL文件之一的示例:
<owl:Class rdf:ID="City">
<owl:Restriction>
<owl:onProperty>
<owl:ObjectProperty rdf:about="#hasAccommodation"/>
</owl:onProperty>
<owl:someValuesFrom rdf:resource="#LuxuryHotel"/>
</owl:Restriction>
</owl:Class>
<owl:Class rdf:ID="Capital">
<rdfs:subClassOf>
<owl:Restriction>
<owl:someValuesFrom rdf:resource="#Museums"/>
<owl:onProperty>
<owl:ObjectProperty rdf:about="#hasActivity"/>
</owl:onProperty>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf rdf:resource="#City"/>
</owl:Class>
<Capital rdf:ID="Canberra">
<hasAccommodation rdf:resource="#FourSeasons"/>
</Capital>
<Capital rdf:ID="Sydney">
<hasAccommodation rdf:resource="#FourSeasons"/>
<hasActivity rdf:resource="#CoolMuseum"/>
</Capital>
In the example above, I'd like to be able to detect that Canberra
doesn't use the property hasActivity
, while Sydney
does. 在上面的示例中,我希望能够检测到
Canberra
没有使用hasActivity
属性,而Sydney
却使用了。 I'm not sure how to properly obtain those properties and compare them. 我不确定如何正确获取这些属性并进行比较。 For brevity, I excluded the lines for the FourSeasons and Museum stuff.
为简洁起见,我排除了FourSeasons和Museum的内容。 I hope I've explained this decently enough.
我希望我已经足够恰当地解释了这一点。
Use the getObjectPropertyValues(OWLOntology ontology)
method which is provided by the OWLIndividual Interface. 使用OWLIndividual接口提供的
getObjectPropertyValues(OWLOntology ontology)
方法。 It will return a Map with ObjectPropertyExpression
as key and a Set of OWLIndivdual
as value. 它将返回一个Map,其
ObjectPropertyExpression
作为键,而一组OWLIndivdual
作为值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.