簡體   English   中英

使用耶拿檢索貓頭鷹文件數據

[英]retrieve owl file data using Jena

我有以下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>

例如,我想使用以下代碼來檢索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 
 }

我只得到“ DOID_0001”,而不是“ DOID_0001”和“ DOID_11”。 我還需要獲取所有其他信息,例如“”和“

不,你錯了。 本體中的陳述是

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM