我正在尝试编写一个加载输入类子类的方法。此代码在 OWL API 3.1.x(Pizza.owl) 编写的 RDF 文件中运行良好,但现在它不适用于由 OWL API 3.4.x 版本生成的文件。
下面是我写的代码:
public ArrayList<String> getSubClassOf(String parentClass)
{
String seq = "";
tempList.clear();
tempClass = factory.getOWLClass(":" + parentClass, pm);
s = reasoner.getSubClasses(tempClass, false);
i = s.iterator();
while(i.hasNext()){
seq = i.next().toString();
if(!seq.contains("Nothing"))
tempList.add(seq.substring(seq.indexOf("#")+1,seq.indexOf(">")));
}
return tempList;
}
这是 OWL API 3.4.2 生成的 owl 文件:
<!DOCTYPE Ontology [
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY xml "http://www.w3.org/XML/1998/namespace" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>
<Ontology xmlns="http://www.w3.org/2002/07/owl#"
xml:base="http://localhost/CA/SmartHome/SmartHome_1113"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
ontologyIRI="http://localhost/CA/SmartHome/SmartHome_1113">
<Prefix name="" IRI="http://localhost/CA/SmartHome/SmartHome_1113.owl#"/>
<Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/>
<Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
<Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/>
<Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/>
<Declaration>
<Class IRI="#Adult"/>
</Declaration>
<Declaration>
<Class IRI="#Person"/>
</Declaration>
<SubClassOf>
<Class IRI="#Adult"/>
<Class IRI="#Person"/>
</SubClassOf>
</Ontology>
这是一个非常简单的本体,由 2 个类组成,而 Adult 是 Person 的子类