简体   繁体   English

使用耶拿检索猫头鹰文件数据

[英]retrieve owl file data using Jena

I have the following owl file and want to retrieve the related data to a given class. 我有以下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>

For example I wanted to retrieve the subClassOf which should be DOID_11 without success using the following code: 例如,我想使用以下代码来检索subClassOf,该子类应为DOID_11而不成功:

//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 
 }

I get just "DOID_0001" instead of "DOID_0001" and "DOID_11". 我只得到“ DOID_0001”,而不是“ DOID_0001”和“ DOID_11”。 I need also to get all of the other information such as "" and " 我还需要获取所有其他信息,例如“”和“

No, you are wrong. 不,你错了。 The statement in your ontology is 本体中的陈述是

DOID_0001 rdfs:subClassOf DOID_11

That means, DOID_11 is the superclass of DOID_0001 not vice versa. 这意味着, DOID_11是超DOID_0001而不是相反。 And if you ask for all subclasses of DOID_0001 , it's indeed only the class itself as trivial inference. 而且,如果您请求DOID_0001所有子类,则实际上只是类本身是微不足道的推断。

Update 更新资料

Statements for each class can be retrieved via 可以通过以下方式检索每个类的语句

    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);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM