我有以下owl文件,想要将相关数据检索到给定的类。
<owl:Class rdf:about="http://purl.obolibrary.org/obo/DOID_0001">
<rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/DOID_11"/>
<obo:IAO_11 rdf:datatype="http://www.w3.org/2001/XMLSchema#string">A def def def def.</obo:IAO_0000115>
<oboInOwl:hasDbXref rdf:datatype="http://www.w3.org/2001/XMLSchema#string">AA:006394</oboInOwl:hasDbXref>
<oboInOwl:hasExactSynonym rdf:datatype="http://www.w3.org/2001/XMLSchema#string">abcde</oboInOwl:hasExactSynonym>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ABCDEFG</rdfs:label>
</owl:Class>
例如,我想使用以下代码检索应该是DOID_11的subClassOf而不成功:
//create the reasoning model using the base
OntModel inf = ModelFactory.createOntologyModel();
// use the FileManager to find the input file
InputStream in = FileManager.get().open(inputFileName);
if ( in == null) {
throw new IllegalArgumentException("File: " + inputFileName + " not found");
}
inf.read( in , "");
ExtendedIterator <? > classes = inf.listClasses();
while (classes.hasNext()) {
OntClass essaClasse = (OntClass) classes.next();
System.out.println("Classe: " + essaClasse.getLocalName());
for (Iterator <? > i = essaClasse.listSubClasses(); i.hasNext();) {
OntClass c = (OntClass) i.next();
System.out.print(" " + c.getLocalName() + "\n");
} // end for
}
我只是&#34; DOID_0001&#34;而不是&#34; DOID_0001&#34;和&#34; DOID_11&#34;。我还需要获取所有其他信息,例如&#34;&#34;和&#34;
答案 0 :(得分:0)
不,你错了。你的本体论中的陈述是
DOID_0001 rdfs:subClassOf DOID_11
这意味着,DOID_11
是DOID_0001
的超类,反之亦然。如果你要求DOID_0001
的所有子类,它确实只是将类本身作为微不足道的推理。
可以通过
检索每个班级的语句 StmtIterator stmtIterator = inf.listStatements(essaClasse, null, (RDFNode) null);
while(stmtIterator.hasNext()) {
Statement st = stmtIterator.next();
Property p = st.getPredicate();
RDFNode o = st.getObject();
System.out.println(p + ":" + o);
}