个人创建的 Jena 在写入文件时没有 class

Individual created Jena has no class when written in file

我的 java 程序正在读取医疗数据并将它们翻译成语义,然后我将其保存为 RDF 文件以导出它们。但是来自特定 class 的一个人始终存在于文件中,但某些属性和它的 class 丢失。

我试过更改导出格式,我已经仔细检查了所有 IRI。所有这一切都不成功。

我添加了一些代码来检查 class 和属性,然后在 RDF 文件中写入模型,一切似乎都是正确的。

创建 ontology 的代码:

    public static Individual createIndiv(String name, Resource ressource) {                 // Create an Individual
        if (populateModel==null) {populateModel = ModelFactory.createOntologyModel();}
        if (name==null || ressource==null) {
            logger.error("Creating Individual named "+name+" with classs "+ressource.getLocalName());
            return null;
        } else {
            logger.debug("Creating Individual named "+name+" with classs "+ressource.getLocalName());
            System.out.println(ressource);
            Individual ind = populateModel.createIndividual(racineURI+name, ressource);
            return ind;
        }
    }

        Individual imagingStudy = createIndiv(generateName("imaging_study_TEST"), model.getResource("http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#imaging_study"));    

写作前要检查的测试:

        System.out.println("Test Final :");
        System.out.println("RDF Type :"+imagingStudy.getRDFType());
        StmtIterator propertiesIter = imagingStudy.listProperties();
        Statement p;
        while (propertiesIter.hasNext()) {
            p = propertiesIter.next();
            System.out.println(p.asTriple());
        }

编写模型的代码:

    public void writingRDF(String pathOut) throws FileNotFoundException  {                                                              // Write the RDF 
        logger.info("Writing RDF file in "+pathOut);        

        FileOutputStream sortie = new FileOutputStream(pathOut);
        OntologyPopulator.populateModel.write(sortie, "RDF/XML", null);                 

        logger.info("Writing RDF file Sucessfull");
        OntologyPopulator.populateModel = ModelFactory.createOntologyModel();
    }

一个简短的 RDF 文件:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:j.0="http://purl.obolibrary.org/obo/"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:j.1="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
  <owl:ObjectProperty rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#part_of_study"/>
  <owl:ObjectProperty rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#is_about_procedure"/>
  <owl:ObjectProperty rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#has_protocol"/>
  <owl:ObjectProperty rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#used_as_instrument_in"/>
  <owl:ObjectProperty rdf:about="http://purl.obolibrary.org/obo/BFO_0000052"/>
  <owl:ObjectProperty rdf:about="http://purl.obolibrary.org/obo/BFO_0000087"/>
  <owl:ObjectProperty rdf:about="http://purl.obolibrary.org/obo/BFO_0000132"/>
  <owl:ObjectProperty rdf:about="http://purl.obolibrary.org/obo/BFO_0000054"/>
  <owl:DatatypeProperty rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#years"/>
  <owl:DatatypeProperty rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#has_id"/>
  <owl:DatatypeProperty rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#has_manufacturer_name"/>
  <owl:DatatypeProperty rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#has_description"/>
  <owl:DatatypeProperty rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#has_name"/>
  <owl:DatatypeProperty rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#has_DICOM_study_instance_UID"/>
  <owl:DatatypeProperty rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#has_DICOM_series_instance_UID"/>
  <owl:DatatypeProperty rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#has_beginning_time"/>
  <owl:DatatypeProperty rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#has_beginning_date"/>
  <owl:DatatypeProperty rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#has_model_name"/>
  <j.1:age_of_patient_undergoing_medical_procedure rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#age_of_patient_undergoing_medical_procedure_1cf4387d-b276-4f86-8e6d-52eb48833afd">
    <j.1:is_about_procedure>
      <rdf:Description rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#imaging_study_TEST_ec26ee5a-c016-4b20-9c90-cce7315ea2c7">
        <j.1:part_of_study>
          <j.1:clinical_research_study rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#clinical_research_study_755523_subtask2.1.2"/>
        </j.1:part_of_study>
      </rdf:Description>
    </j.1:is_about_procedure>
    <j.1:years rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal"
    >36</j.1:years>
  </j.1:age_of_patient_undergoing_medical_procedure>
  <j.1:patient rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#Patient_4c7681a8-176b-4940-abbd-27fb9df399f7">
    <j.0:BFO_0000054>
      <j.1:SPECT_data_acquisition rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#SPECT_data_acquisition_c8bd9ca2-70c1-4cd5-b52b-2295db407922">
        <j.1:has_DICOM_series_instance_UID>1.3.12.2.1107.5.6.1.9225.30500109020320314446800000119</j.1:has_DICOM_series_instance_UID>
        <j.1:has_beginning_time>073900.000000</j.1:has_beginning_time>
        <j.1:has_beginning_date>20090211</j.1:has_beginning_date>
        <j.1:has_id>1000</j.1:has_id>
        <j.0:BFO_0000132 rdf:resource="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#imaging_study_TEST_ec26ee5a-c016-4b20-9c90-cce7315ea2c7"/>
        <j.1:has_protocol>
          <j.1:NM_acquisition_protocol rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#NM_acquisition_protocol_950491e0-2b97-4c5a-89d6-044852ead542">
            <j.1:has_description>Spect 131-I</j.1:has_description>
            <j.1:has_name>7312.0.21354437@</j.1:has_name>
          </j.1:NM_acquisition_protocol>
        </j.1:has_protocol>
      </j.1:SPECT_data_acquisition>
    </j.0:BFO_0000054>
    <j.0:BFO_0000054 rdf:resource="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#imaging_study_TEST_ec26ee5a-c016-4b20-9c90-cce7315ea2c7"/>
  </j.1:patient>
  <j.1:SPECT_scanner rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#SPECT_scanner_39a89288-4f79-49c7-ac18-f59dec9786bf">
    <j.0:BFO_0000087>
      <j.1:image_acquisition_role rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#image_acquisition_role_28318df2-49ec-45a4-a59e-233fc371e729">
        <j.0:BFO_0000054 rdf:resource="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#SPECT_data_acquisition_c8bd9ca2-70c1-4cd5-b52b-2295db407922"/>
      </j.1:image_acquisition_role>
    </j.0:BFO_0000087>
    <j.1:has_model_name>IP2</j.1:has_model_name>
    <j.1:has_manufacturer_name>SIEMENS NM</j.1:has_manufacturer_name>
    <j.1:used_as_instrument_in rdf:resource="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#SPECT_data_acquisition_c8bd9ca2-70c1-4cd5-b52b-2295db407922"/>
  </j.1:SPECT_scanner>
  <rdf:Description rdf:about="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#role_of_responsible_organization_e147d526-332d-40df-8df8-80a63e0b4a22">
    <j.0:BFO_0000052 rdf:resource="http://medicis.univ-rennes1.fr/ontologies/ontospm/OntoMEDIRAD.owl#institution_700f9e9c-9cb6-461f-b7d6-42a995583523"/>
  </rdf:Description>
  <j.0:PATO_0000383 rdf:about="http://purl.obolibrary.org/obo/PATO_0000383"/>
</rdf:RDF>

测试中看到的属性(没关系) 1 class 4 个属性

Protégé 中的 Imaging_Study 个体 没有 class 只有 2 个属性

感谢您的帮助

我找到了解决方案

用于创建其他个体的函数中有一行代码,正在删除模型并创建新模型。

感谢您的回答