9 Replies Latest reply on Oct 22, 2010 2:31 PM by 799283

    How to handle ontology imports?

    799283
      Hi there,

      since my last two questions have been so fruitfully answered, I thought I'll try again. :)

      I have to load an OWL file (called ontology1 from now on) into the semantic store (11g+Semantic Technologies), which imports a heavy OWL file of 20MB (ontology2 from now on) itself. This ontology was created using Protege.

      What I have done is I created a ont-policy.rdf file to resolve the namespace of the imported OWL. I then read the policy file, followed by the OWL file containing ontology1. Basically, the responsible Java code looks like this:

      =======JAVA START==============
      model = ModelOracleSem.createOracleSemModel(oracle, dbModelName);

      InputStream policyFileInputStream = FileManager.get().open(ontologyPolicyFileName);
      model.read(policyFileInputStream, null);

      InputStream ontologyFileInputStream = FileManager.get().open(ontologyFileName);
      model.read(ontologyFileInputStream, null);
      =======JAVA END==============


      =======ONT-POLICY.RDF START==============
      <OntologySpec>
      <!-- local version of the FoodWeb ontology Properties.owl -->
      <publicURI rdf:resource="http://www.demo.org/ontologies/2010/importOwl.owl" />
      <altURL rdf:resource="file:///C:/demo/importedOwl.owl" />
      <language rdf:resource="http://www.w3.org/2002/07/owl" />
      <prefix rdf:datatype="&xsd;string">prop</prefix>
      </OntologySpec>
      =======ONT-POLICY.RDF END==============

      Unfortunately, no statements from the imported OWL seem to be put into the db tables.

      Can anyone give me a rundown on how to handle imports and get all of it into the db please?

      TIA,

      Damian
        • 1. Re: How to handle ontology imports?
          alwu-Oracle
          Hi,

          Did you use owl:imports?

          Please see section 7.2 of http://www.w3.org/TR/owl-ref/

          Thanks,

          Zhe Wu
          • 2. Re: How to handle ontology imports?
            799283
            Yes of course. It is an owl import, as done by protege.
            • 3. Re: How to handle ontology imports?
              alwu-Oracle
              Hi,

              Let's see if this example helps.


              InputStream in = FileManager.get().open("./test.owl" );

              OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
              ontModel.read(in, null);


              Oracle oracle = new Oracle(szJdbcURL, szUser, szPasswd);
              Model model = ModelOracleSem.createOracleSemModel(oracle, szModelName);
              model.add(ontModel);
              OutputStream os = new FileOutputStream("./test.nt");
              model.write(os, "N-TRIPLE");
              os.close();


              In the following test.owl file, owl:imports is used to import a remote owl ontology on the web.

              % cat test.owl
              <rdf:RDF
              xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
              xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
              xmlns:owl="http://www.w3.org/2002/07/owl#"
              >
              <owl:Ontology rdf:about="http://my.com/test">
              <owl:imports rdf:resource="http://attempto.ifi.uzh.ch/site/docs/OWL_to_ACE/foaf.owl"/>
              </owl:Ontology>
              </rdf:RDF>


              After running the above code snippet, the output file has 500+ triples.

              % wc -l test.nt
              563 test.nt

              NOTE that if there are many triples in the remote ontology, you need to use addInBulk method.

              Thanks,

              Zhe Wu
              1 person found this helpful
              • 4. Re: How to handle ontology imports?
                799283
                Thanks zhe wu!

                I will try it first thing in the morning. And yes the imported file is over 20mb in size. Can you please detail on the addinbulk method?

                Best,
                Damian
                • 5. Re: How to handle ontology imports?
                  alwu-Oracle
                  Please search for addInBulk in
                  http://download.oracle.com/docs/cd/E11882_01/appdev.112/e11828/sem_jena.htm

                  Cheers,

                  Zhe Wu
                  • 6. Re: How to handle ontology imports?
                    799283
                    Zhe Wu,

                    thanks for the code example. The importing works fine, the written files contains the imported tripples! I will now try to mend my code using snippets from your code :)

                    Thanks again, I'll keep you updated.

                    Best,
                    Damian
                    • 7. Re: How to handle ontology imports?
                      799283
                      Hi,

                      I have spent quite some time trying the import of the ontology. Unfortunately, it will just not work...

                      As soon as I switch the import statement to a ontology which is only found in a local file (using the mapping in ont-policy), all I get in the "test.nt" is this import statement, NOT the imported statements.

                      "<http://www.demo.org/ont1.owl> <http://www.w3.org/2002/07/owl#imports> <http://www.demo.org/importedOnt.owl> ."


                      Does anyone know how I can make Jena resolve the import and include the statements?

                      Best,
                      Damian
                      • 8. Re: How to handle ontology imports?
                        alwu-Oracle
                        Hi,

                        If the ontology is stored in a local file (say /tmp/hello.owl), then you can use something like

                        <http://www.demo.org/ont1.owl> <http://www.w3.org/2002/07/owl#imports> <file:///tmp/hello.owl>

                        Does this help?

                        Thanks,

                        Zhe Wu
                        • 9. Re: How to handle ontology imports?
                          799283
                          Hey all,

                          first: Sorry for the late reply, I somehow thought that I had already given feedback.

                          I got it working. To keep a long story short: It looks like something has gone wrong during the last update/patching of our 11g instance. Turned out, that something was strangely wrong with it (Our dba said - I am not so firm with DB administration).

                          I only found out, because I had the possibility to test with another 11g instance by chance - and everything worked fine.

                          So, problem solved. Thanks again for every helpful comment!!!!

                          Best regards,
                          Damian