使用 Jena 检索 owl 文件数据
retrieve owl file data using Jena
我有以下 owl 文件,想将相关数据检索到给定的 class。
<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
}
我只得到 "DOID_0001" 而不是 "DOID_0001" 和 "DOID_11"。我还需要获取所有其他信息,例如“”和“
不,你错了。您的 ontology 中的语句是
DOID_0001 rdfs:subClassOf DOID_11
这意味着,DOID_11
是 DOID_0001
的超 class,反之亦然。如果你要求 DOID_0001
的所有子 class,它确实只是 class 本身作为微不足道的推论。
更新
每个 class 的语句可以通过
检索
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);
}
我有以下 owl 文件,想将相关数据检索到给定的 class。
<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
}
我只得到 "DOID_0001" 而不是 "DOID_0001" 和 "DOID_11"。我还需要获取所有其他信息,例如“”和“
不,你错了。您的 ontology 中的语句是
DOID_0001 rdfs:subClassOf DOID_11
这意味着,DOID_11
是 DOID_0001
的超 class,反之亦然。如果你要求 DOID_0001
的所有子 class,它确实只是 class 本身作为微不足道的推论。
更新
每个 class 的语句可以通过
检索 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);
}