我有一个使用 Protégé 3.4 设计的简单本体。我已经介绍了一些“必要且充分”的条件,比如在 Table 类的定义中:
http://postimage.org/image/f37xliqad/
忘记第一个条件,第三个更容易理解:)
生成的OWL代码是:
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:protege="http://protege.stanford.edu/plugins/owl/protege#"
xmlns:xsp="http://www.owl-ontologies.com/2005/08/07/xsp.owl#"
xmlns:assert="http://www.owl-ontologies.com/assert.owl#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:sqwrl="http://sqwrl.stanford.edu/ontologies/built-ins/3.4/sqwrl.owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:swrl="http://www.w3.org/2003/11/swrl#"
xmlns:swrlb="http://www.w3.org/2003/11/swrlb#"
xmlns="http://www.owl-ontologies.com/Ontology1317586695.owl#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:swrla="http://swrl.stanford.edu/ontologies/3.3/swrla.owl#"
xml:base="http://www.owl-ontologies.com/Ontology1317586695.owl">
<owl:Ontology rdf:about="">
<owl:imports rdf:resource="http://swrl.stanford.edu/ontologies/3.3/swrla.owl"/>
<owl:imports rdf:resource="http://sqwrl.stanford.edu/ontologies/built-ins/3.4/sqwrl.owl"/>
</owl:Ontology>
...
<owl:Class rdf:ID="Table">
<owl:disjointWith>
<owl:Class rdf:ID="Chair"/>
</owl:disjointWith>
<owl:equivalentClass>
<owl:Class>
<owl:intersectionOf rdf:parseType="Resource">
<rdf:first>
<owl:Restriction>
<owl:onProperty>
<owl:ObjectProperty rdf:ID="has_coarseArea"/>
</owl:onProperty>
<owl:someValuesFrom>
<owl:Class>
<owl:unionOf rdf:parseType="Collection">
<owl:Class rdf:about="#MMAround09"/>
<owl:Class rdf:about="#MMAround1"/>
<owl:Class rdf:about="#MMAround12"/>
<owl:Class rdf:about="#MMAround15"/>
<owl:Class rdf:about="#MMAround2"/>
</owl:unionOf>
</owl:Class>
</owl:someValuesFrom>
</owl:Restriction>
</rdf:first>
<rdf:rest rdf:parseType="Resource">
<rdf:first>
<owl:Restriction>
<owl:someValuesFrom>
<owl:Class>
<owl:unionOf rdf:parseType="Collection">
<owl:Class rdf:about="#MMAround07"/>
<owl:Class rdf:about="#MMAround08"/>
</owl:unionOf>
</owl:Class>
</owl:someValuesFrom>
<owl:onProperty>
<owl:ObjectProperty rdf:ID="has_coarseCentroidHeight"/>
</owl:onProperty>
</owl:Restriction>
</rdf:first>
<rdf:rest>
<rdf:List>
<rdf:first>
<owl:Restriction>
<owl:someValuesFrom>
<owl:Class rdf:about="#Horizontal"/>
</owl:someValuesFrom>
<owl:onProperty>
<owl:ObjectProperty rdf:about="#has_orientation"/>
</owl:onProperty>
</owl:Restriction>
</rdf:first>
<rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
</rdf:List>
</rdf:rest>
</rdf:rest>
</owl:intersectionOf>
</owl:Class>
</owl:equivalentClass>
<rdfs:subClassOf>
<owl:Class rdf:ID="Furniture"/>
</rdfs:subClassOf>
</owl:Class>
如果我理解得很好,这些条件被解释为限制,并作为 Table 类的超类进行管理。
所以,如果我用 Jena 加载我的本体和类表:
1. String NS = "http://www.owl-ontologies.com/Ontology1317586695.owl#";
2. OntModel model = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
3. model.read(OWL_FILE_NAME);
4. OntClass Table = model.getOntClass( NS + "Table" );
NS 变量具有正确的值,因为表 OntClass 已正确加载。然后,在执行以下代码时,应该到达第 10 行,但不是:
5. for (Iterator<OntClass> supers = Table.listSuperClasses(true); supers.hasNext(); ) {
6. OntClass superClass = supers.next();
7.
8. if (superClass.isRestriction())
9. {
10. System.out.println("Restriction found");
11. }
12. }
我也试过 Table.listEquivalentClasses() 没有成功。
知道我在路上失去了什么吗?
更新
测试由 Ian 很好地实现并在此处共享的代码:https ://gist.github.com/4065533 ,它工作正常。但改变
OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_MICRO_RULE_INF );
经过
OntModel m = ModelFactory.createOntologyModel( PelletReasonerFactory.THE_SPEC );
它停止工作。似乎 Pellet 不承认这些限制是该类的超类。