You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Ed Swing <Ed...@sas.com> on 2013/08/13 16:41:07 UTC

Imports and properties?

Apparently, properties are not imported when an ontology is imported - not even the subclass relationship. To test this, I have created two simple ontologies. First, the base (imported) ontology:

<!DOCTYPE rdf:RDF [
    <!ENTITY xsd  "http://www.w3.org/2001/XMLSchema#" >
    <!ENTITY owl  "http://www.w3.org/2002/07/owl#" >
    <!ENTITY rdf  "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>


<rdf:RDF xmlns="http://luminary.unx.sas.com/test#"
       xml:base="http://luminary.unx.sas.com/test#"
       xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
       xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#">

       <owl:Ontology rdf:about="TestBase">
              <rdfs:comment>Test Base Ontology</rdfs:comment>
              <rdfs:label>Test Base Ontology</rdfs:label>
       </owl:Ontology>

       <owl:Class rdf:ID="Person" />
       <owl:Class rdf:ID="Teacher">
           <rdfs:subClassOf rdf:resource="#Person" />
       </owl:Class>
</rdf:RDF>

Next, the importing ontology:

<!DOCTYPE rdf:RDF [
    <!ENTITY xsd  "http://www.w3.org/2001/XMLSchema#" >
    <!ENTITY owl  "http://www.w3.org/2002/07/owl#" >
    <!ENTITY rdf  "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
    <!ENTITY tst  "http://luminary.unx.sas.com/test#" >
]>


<rdf:RDF xmlns="http://luminary.unx.sas.com/import#"
       xml:base="http://luminary.unx.sas.com/import#"
       xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
       xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
       xmlns:tst="http://luminary.unx.sas.com/test#">

       <owl:Ontology rdf:about="TestImport">
              <rdfs:comment>Test Import Ontology</rdfs:comment>
              <rdfs:label>Test Import Ontology</rdfs:label>
              <owl:imports rdf:resource="http://luminary.unx.sas.com/luminary/testbase.owl"/>
       </owl:Ontology>

       <owl:Class rdf:ID="Administrator">
           <rdfs:subClassOf rdf:resource="&tst;Person" />
       </owl:Class>
</rdf:RDF>

Finally, here is the Java class I wrote to test this:

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.vocabulary.RDFS;

public class SubclassTest {

    public static void main(String[] args) throws IOException {
        OntModel model =
            ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
        FileInputStream inStream =
            new FileInputStream("resources/testimport.owl");
        model.read(inStream, null);
        inStream.close();
        for (Iterator<OntClass> clsIter = model.listClasses(); clsIter
            .hasNext();) {
            OntClass cls = clsIter.next();
            System.out.println("CLS: " + cls.getURI());
            for (StmtIterator stIter =
                model.getBaseModel().listStatements(cls, RDFS.subClassOf,
                    (RDFNode) null); stIter.hasNext();) {
                Statement stmt = stIter.next();
                RDFNode obj = stmt.getObject();
                if (obj.isURIResource()) {
                    OntClass par = model.getOntClass(obj.toString());
                    System.out.println("  Parent: " + par.getURI());
                }
            }
        }
    }
}

The output from the class shows the following (I've trimmed the www.w3.org<http://www.w3.org> classes from this for brevity):

CLS: http://luminary.unx.sas.com/import#Administrator
  Parent: http://luminary.unx.sas.com/test#Person
CLS: http://luminary.unx.sas.com/test#Teacher
CLS: http://luminary.unx.sas.com/test#Person

Clearly, the Teacher is a subclass of Person, as it is defined in the base ontology. However, this relationship does not appear. When an ontology is imported, it is supposed to import all definitions and statements. However, this is clearly not the case.

Edward Swing
Applied Research Technologist
Vision Systems + Technology, Inc., a SAS Company
6021 University Boulevard * Suite 360 * Ellicott City * Maryland * 21043
Tel: 410.418.5555 Ext: 919 * Fax: 410.418.8580
Email: Ed.Swing@vsticorp.com<ma...@vsticorp.com>
Web: http://www.vsticorp.com<http://www.vsticorp.com/>


RE: Imports and properties?

Posted by Ed Swing <Ed...@sas.com>.
OK - thanks. This solves the problem.

-----Original Message-----
From: Dave Reynolds [mailto:dave.e.reynolds@gmail.com] 
Sent: Tuesday, August 13, 2013 11:37 AM
To: users@jena.apache.org
Subject: Re: Imports and properties?

On 13/08/13 16:13, Ed Swing wrote:
> The imported ontology is not publicly accessible, but it is on the specified URL on my corporate intranet. It is obviously imported since Teacher is in the list of classes. However, the relationship between Teacher and Person isn't.
>
> The issue has nothing to do with the OntDocumentManager, since the testbase.owl isn't a local file. The issue is easy enough to duplicate though.

Ah, looking more closely your problem is here:

for (StmtIterator stIter =
              model.getBaseModel().listStatements(cls, RDFS.subClassOf,
              (RDFNode) null); stIter.hasNext();) {

That ".getBaseModel()" is forcing the subClassOf check to just look at the base model, i.e. the model without any imports. Change that to:

for (StmtIterator stIter =
              model.listStatements(cls, RDFS.subClassOf,
              (RDFNode) null); stIter.hasNext();) {

and I get:

CLS: http://luminary.unx.sas.com/import#Administrator
   Parent: http://luminary.unx.sas.com/test#Person
CLS: http://luminary.unx.sas.com/test#Teacher
   Parent: http://luminary.unx.sas.com/test#Person
CLS: http://luminary.unx.sas.com/test#Person

[Using an OWL_MEM configuration to avoid the obscuring inferences.]

Dave


>
> -----Original Message-----
> From: Dave Reynolds [mailto:dave.e.reynolds@gmail.com]
> Sent: Tuesday, August 13, 2013 11:04 AM
> To: users@jena.apache.org
> Subject: Re: Imports and properties?
>
> On 13/08/13 15:41, Ed Swing wrote:
>> Apparently, properties are not imported when an ontology is imported - not even the subclass relationship. To test this, I have created two simple ontologies. First, the base (imported) ontology:
>>
>> <!DOCTYPE rdf:RDF [
>>       <!ENTITY xsd  "http://www.w3.org/2001/XMLSchema#" >
>>       <!ENTITY owl  "http://www.w3.org/2002/07/owl#" >
>>       <!ENTITY rdf  "http://www.w3.org/1999/02/22-rdf-syntax-ns#" > 
>> ]>
>>
>>
>> <rdf:RDF xmlns="http://luminary.unx.sas.com/test#"
>>          xml:base="http://luminary.unx.sas.com/test#"
>>          xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>>          xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
>> xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
>>
>>          <owl:Ontology rdf:about="TestBase">
>>                 <rdfs:comment>Test Base Ontology</rdfs:comment>
>>                 <rdfs:label>Test Base Ontology</rdfs:label>
>>          </owl:Ontology>
>>
>>          <owl:Class rdf:ID="Person" />
>>          <owl:Class rdf:ID="Teacher">
>>              <rdfs:subClassOf rdf:resource="#Person" />
>>          </owl:Class>
>> </rdf:RDF>
>>
>> Next, the importing ontology:
>>
>> <!DOCTYPE rdf:RDF [
>>       <!ENTITY xsd  "http://www.w3.org/2001/XMLSchema#" >
>>       <!ENTITY owl  "http://www.w3.org/2002/07/owl#" >
>>       <!ENTITY rdf  "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
>>       <!ENTITY tst  "http://luminary.unx.sas.com/test#" > ]>
>>
>>
>> <rdf:RDF xmlns="http://luminary.unx.sas.com/import#"
>>          xml:base="http://luminary.unx.sas.com/import#"
>>          xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>>          xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
>>          xmlns:tst="http://luminary.unx.sas.com/test#">
>>
>>          <owl:Ontology rdf:about="TestImport">
>>                 <rdfs:comment>Test Import Ontology</rdfs:comment>
>>                 <rdfs:label>Test Import Ontology</rdfs:label>
>>                 <owl:imports rdf:resource="http://luminary.unx.sas.com/luminary/testbase.owl"/>
>>          </owl:Ontology>
>>
>>          <owl:Class rdf:ID="Administrator">
>>              <rdfs:subClassOf rdf:resource="&tst;Person" />
>>          </owl:Class>
>> </rdf:RDF>
>>
>> Finally, here is the Java class I wrote to test this:
>>
>> import java.io.FileInputStream;
>> import java.io.IOException;
>> import java.util.Iterator;
>> import com.hp.hpl.jena.ontology.OntClass;
>> import com.hp.hpl.jena.ontology.OntModel;
>> import com.hp.hpl.jena.ontology.OntModelSpec;
>> import com.hp.hpl.jena.rdf.model.*;
>> import com.hp.hpl.jena.vocabulary.RDFS;
>>
>> public class SubclassTest {
>>
>>       public static void main(String[] args) throws IOException {
>>           OntModel model =
>>               ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
>>           FileInputStream inStream =
>>               new FileInputStream("resources/testimport.owl");
>>           model.read(inStream, null);
>>           inStream.close();
>>           for (Iterator<OntClass> clsIter = model.listClasses(); clsIter
>>               .hasNext();) {
>>               OntClass cls = clsIter.next();
>>               System.out.println("CLS: " + cls.getURI());
>>               for (StmtIterator stIter =
>>                   model.getBaseModel().listStatements(cls, RDFS.subClassOf,
>>                       (RDFNode) null); stIter.hasNext();) {
>>                   Statement stmt = stIter.next();
>>                   RDFNode obj = stmt.getObject();
>>                   if (obj.isURIResource()) {
>>                       OntClass par = model.getOntClass(obj.toString());
>>                       System.out.println("  Parent: " + par.getURI());
>>                   }
>>               }
>>           }
>>       }
>> }
>>
>> The output from the class shows the following (I've trimmed the www.w3.org<http://www.w3.org> classes from this for brevity):
>
> [Aside: for testing import processing it would be simpler to work
> without inference so you can see the wood for the trees.]
>
>> CLS: http://luminary.unx.sas.com/import#Administrator
>>     Parent: http://luminary.unx.sas.com/test#Person
>> CLS: http://luminary.unx.sas.com/test#Teacher
>> CLS: http://luminary.unx.sas.com/test#Person
>>
>> Clearly, the Teacher is a subclass of Person, as it is defined in the base ontology. However, this relationship does not appear. When an ontology is imported, it is supposed to import all definitions and statements. However, this is clearly not the case.
>
> How are you expecting the imported document to be located?
>
> The import URL is given as:
>
>      http://luminary.unx.sas.com/luminary/testbase.owl
>
> but that URL gives a 404 for me.
>
> To map a URL onto a local file you need either an ont-policy.rdf file or
> need to programatically configure an OntDocumentManager, as described in:
>
>     http://jena.apache.org/documentation/ontology/
>
> Your code doesn't include any OntDocumentManager set up so presumably
> you are relying on an ont-policy document, in which case the problem may
> be in the mapping file itself or the file might not be being found in
> your execution environment.
>
> Dave
>
>
>




Re: Imports and properties?

Posted by Dave Reynolds <da...@gmail.com>.
On 13/08/13 16:13, Ed Swing wrote:
> The imported ontology is not publicly accessible, but it is on the specified URL on my corporate intranet. It is obviously imported since Teacher is in the list of classes. However, the relationship between Teacher and Person isn't.
>
> The issue has nothing to do with the OntDocumentManager, since the testbase.owl isn't a local file. The issue is easy enough to duplicate though.

Ah, looking more closely your problem is here:

for (StmtIterator stIter =
              model.getBaseModel().listStatements(cls, RDFS.subClassOf,
              (RDFNode) null); stIter.hasNext();) {

That ".getBaseModel()" is forcing the subClassOf check to just look at 
the base model, i.e. the model without any imports. Change that to:

for (StmtIterator stIter =
              model.listStatements(cls, RDFS.subClassOf,
              (RDFNode) null); stIter.hasNext();) {

and I get:

CLS: http://luminary.unx.sas.com/import#Administrator
   Parent: http://luminary.unx.sas.com/test#Person
CLS: http://luminary.unx.sas.com/test#Teacher
   Parent: http://luminary.unx.sas.com/test#Person
CLS: http://luminary.unx.sas.com/test#Person

[Using an OWL_MEM configuration to avoid the obscuring inferences.]

Dave


>
> -----Original Message-----
> From: Dave Reynolds [mailto:dave.e.reynolds@gmail.com]
> Sent: Tuesday, August 13, 2013 11:04 AM
> To: users@jena.apache.org
> Subject: Re: Imports and properties?
>
> On 13/08/13 15:41, Ed Swing wrote:
>> Apparently, properties are not imported when an ontology is imported - not even the subclass relationship. To test this, I have created two simple ontologies. First, the base (imported) ontology:
>>
>> <!DOCTYPE rdf:RDF [
>>       <!ENTITY xsd  "http://www.w3.org/2001/XMLSchema#" >
>>       <!ENTITY owl  "http://www.w3.org/2002/07/owl#" >
>>       <!ENTITY rdf  "http://www.w3.org/1999/02/22-rdf-syntax-ns#" > ]>
>>
>>
>> <rdf:RDF xmlns="http://luminary.unx.sas.com/test#"
>>          xml:base="http://luminary.unx.sas.com/test#"
>>          xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>>          xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
>>
>>          <owl:Ontology rdf:about="TestBase">
>>                 <rdfs:comment>Test Base Ontology</rdfs:comment>
>>                 <rdfs:label>Test Base Ontology</rdfs:label>
>>          </owl:Ontology>
>>
>>          <owl:Class rdf:ID="Person" />
>>          <owl:Class rdf:ID="Teacher">
>>              <rdfs:subClassOf rdf:resource="#Person" />
>>          </owl:Class>
>> </rdf:RDF>
>>
>> Next, the importing ontology:
>>
>> <!DOCTYPE rdf:RDF [
>>       <!ENTITY xsd  "http://www.w3.org/2001/XMLSchema#" >
>>       <!ENTITY owl  "http://www.w3.org/2002/07/owl#" >
>>       <!ENTITY rdf  "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
>>       <!ENTITY tst  "http://luminary.unx.sas.com/test#" >
>> ]>
>>
>>
>> <rdf:RDF xmlns="http://luminary.unx.sas.com/import#"
>>          xml:base="http://luminary.unx.sas.com/import#"
>>          xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>>          xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
>>          xmlns:tst="http://luminary.unx.sas.com/test#">
>>
>>          <owl:Ontology rdf:about="TestImport">
>>                 <rdfs:comment>Test Import Ontology</rdfs:comment>
>>                 <rdfs:label>Test Import Ontology</rdfs:label>
>>                 <owl:imports rdf:resource="http://luminary.unx.sas.com/luminary/testbase.owl"/>
>>          </owl:Ontology>
>>
>>          <owl:Class rdf:ID="Administrator">
>>              <rdfs:subClassOf rdf:resource="&tst;Person" />
>>          </owl:Class>
>> </rdf:RDF>
>>
>> Finally, here is the Java class I wrote to test this:
>>
>> import java.io.FileInputStream;
>> import java.io.IOException;
>> import java.util.Iterator;
>> import com.hp.hpl.jena.ontology.OntClass;
>> import com.hp.hpl.jena.ontology.OntModel;
>> import com.hp.hpl.jena.ontology.OntModelSpec;
>> import com.hp.hpl.jena.rdf.model.*;
>> import com.hp.hpl.jena.vocabulary.RDFS;
>>
>> public class SubclassTest {
>>
>>       public static void main(String[] args) throws IOException {
>>           OntModel model =
>>               ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
>>           FileInputStream inStream =
>>               new FileInputStream("resources/testimport.owl");
>>           model.read(inStream, null);
>>           inStream.close();
>>           for (Iterator<OntClass> clsIter = model.listClasses(); clsIter
>>               .hasNext();) {
>>               OntClass cls = clsIter.next();
>>               System.out.println("CLS: " + cls.getURI());
>>               for (StmtIterator stIter =
>>                   model.getBaseModel().listStatements(cls, RDFS.subClassOf,
>>                       (RDFNode) null); stIter.hasNext();) {
>>                   Statement stmt = stIter.next();
>>                   RDFNode obj = stmt.getObject();
>>                   if (obj.isURIResource()) {
>>                       OntClass par = model.getOntClass(obj.toString());
>>                       System.out.println("  Parent: " + par.getURI());
>>                   }
>>               }
>>           }
>>       }
>> }
>>
>> The output from the class shows the following (I've trimmed the www.w3.org<http://www.w3.org> classes from this for brevity):
>
> [Aside: for testing import processing it would be simpler to work
> without inference so you can see the wood for the trees.]
>
>> CLS: http://luminary.unx.sas.com/import#Administrator
>>     Parent: http://luminary.unx.sas.com/test#Person
>> CLS: http://luminary.unx.sas.com/test#Teacher
>> CLS: http://luminary.unx.sas.com/test#Person
>>
>> Clearly, the Teacher is a subclass of Person, as it is defined in the base ontology. However, this relationship does not appear. When an ontology is imported, it is supposed to import all definitions and statements. However, this is clearly not the case.
>
> How are you expecting the imported document to be located?
>
> The import URL is given as:
>
>      http://luminary.unx.sas.com/luminary/testbase.owl
>
> but that URL gives a 404 for me.
>
> To map a URL onto a local file you need either an ont-policy.rdf file or
> need to programatically configure an OntDocumentManager, as described in:
>
>     http://jena.apache.org/documentation/ontology/
>
> Your code doesn't include any OntDocumentManager set up so presumably
> you are relying on an ont-policy document, in which case the problem may
> be in the mapping file itself or the file might not be being found in
> your execution environment.
>
> Dave
>
>
>


RE: Imports and properties?

Posted by Ed Swing <Ed...@sas.com>.
The imported ontology is not publicly accessible, but it is on the specified URL on my corporate intranet. It is obviously imported since Teacher is in the list of classes. However, the relationship between Teacher and Person isn't.

The issue has nothing to do with the OntDocumentManager, since the testbase.owl isn't a local file. The issue is easy enough to duplicate though.

-----Original Message-----
From: Dave Reynolds [mailto:dave.e.reynolds@gmail.com] 
Sent: Tuesday, August 13, 2013 11:04 AM
To: users@jena.apache.org
Subject: Re: Imports and properties?

On 13/08/13 15:41, Ed Swing wrote:
> Apparently, properties are not imported when an ontology is imported - not even the subclass relationship. To test this, I have created two simple ontologies. First, the base (imported) ontology:
>
> <!DOCTYPE rdf:RDF [
>      <!ENTITY xsd  "http://www.w3.org/2001/XMLSchema#" >
>      <!ENTITY owl  "http://www.w3.org/2002/07/owl#" >
>      <!ENTITY rdf  "http://www.w3.org/1999/02/22-rdf-syntax-ns#" > ]>
>
>
> <rdf:RDF xmlns="http://luminary.unx.sas.com/test#"
>         xml:base="http://luminary.unx.sas.com/test#"
>         xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
>
>         <owl:Ontology rdf:about="TestBase">
>                <rdfs:comment>Test Base Ontology</rdfs:comment>
>                <rdfs:label>Test Base Ontology</rdfs:label>
>         </owl:Ontology>
>
>         <owl:Class rdf:ID="Person" />
>         <owl:Class rdf:ID="Teacher">
>             <rdfs:subClassOf rdf:resource="#Person" />
>         </owl:Class>
> </rdf:RDF>
>
> Next, the importing ontology:
>
> <!DOCTYPE rdf:RDF [
>      <!ENTITY xsd  "http://www.w3.org/2001/XMLSchema#" >
>      <!ENTITY owl  "http://www.w3.org/2002/07/owl#" >
>      <!ENTITY rdf  "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
>      <!ENTITY tst  "http://luminary.unx.sas.com/test#" >
> ]>
>
>
> <rdf:RDF xmlns="http://luminary.unx.sas.com/import#"
>         xml:base="http://luminary.unx.sas.com/import#"
>         xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
>         xmlns:tst="http://luminary.unx.sas.com/test#">
>
>         <owl:Ontology rdf:about="TestImport">
>                <rdfs:comment>Test Import Ontology</rdfs:comment>
>                <rdfs:label>Test Import Ontology</rdfs:label>
>                <owl:imports rdf:resource="http://luminary.unx.sas.com/luminary/testbase.owl"/>
>         </owl:Ontology>
>
>         <owl:Class rdf:ID="Administrator">
>             <rdfs:subClassOf rdf:resource="&tst;Person" />
>         </owl:Class>
> </rdf:RDF>
>
> Finally, here is the Java class I wrote to test this:
>
> import java.io.FileInputStream;
> import java.io.IOException;
> import java.util.Iterator;
> import com.hp.hpl.jena.ontology.OntClass;
> import com.hp.hpl.jena.ontology.OntModel;
> import com.hp.hpl.jena.ontology.OntModelSpec;
> import com.hp.hpl.jena.rdf.model.*;
> import com.hp.hpl.jena.vocabulary.RDFS;
>
> public class SubclassTest {
>
>      public static void main(String[] args) throws IOException {
>          OntModel model =
>              ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
>          FileInputStream inStream =
>              new FileInputStream("resources/testimport.owl");
>          model.read(inStream, null);
>          inStream.close();
>          for (Iterator<OntClass> clsIter = model.listClasses(); clsIter
>              .hasNext();) {
>              OntClass cls = clsIter.next();
>              System.out.println("CLS: " + cls.getURI());
>              for (StmtIterator stIter =
>                  model.getBaseModel().listStatements(cls, RDFS.subClassOf,
>                      (RDFNode) null); stIter.hasNext();) {
>                  Statement stmt = stIter.next();
>                  RDFNode obj = stmt.getObject();
>                  if (obj.isURIResource()) {
>                      OntClass par = model.getOntClass(obj.toString());
>                      System.out.println("  Parent: " + par.getURI());
>                  }
>              }
>          }
>      }
> }
>
> The output from the class shows the following (I've trimmed the www.w3.org<http://www.w3.org> classes from this for brevity):

[Aside: for testing import processing it would be simpler to work 
without inference so you can see the wood for the trees.]

> CLS: http://luminary.unx.sas.com/import#Administrator
>    Parent: http://luminary.unx.sas.com/test#Person
> CLS: http://luminary.unx.sas.com/test#Teacher
> CLS: http://luminary.unx.sas.com/test#Person
>
> Clearly, the Teacher is a subclass of Person, as it is defined in the base ontology. However, this relationship does not appear. When an ontology is imported, it is supposed to import all definitions and statements. However, this is clearly not the case.

How are you expecting the imported document to be located?

The import URL is given as:

    http://luminary.unx.sas.com/luminary/testbase.owl

but that URL gives a 404 for me.

To map a URL onto a local file you need either an ont-policy.rdf file or 
need to programatically configure an OntDocumentManager, as described in:

   http://jena.apache.org/documentation/ontology/

Your code doesn't include any OntDocumentManager set up so presumably 
you are relying on an ont-policy document, in which case the problem may 
be in the mapping file itself or the file might not be being found in 
your execution environment.

Dave




Re: Imports and properties?

Posted by Dave Reynolds <da...@gmail.com>.
On 13/08/13 15:41, Ed Swing wrote:
> Apparently, properties are not imported when an ontology is imported - not even the subclass relationship. To test this, I have created two simple ontologies. First, the base (imported) ontology:
>
> <!DOCTYPE rdf:RDF [
>      <!ENTITY xsd  "http://www.w3.org/2001/XMLSchema#" >
>      <!ENTITY owl  "http://www.w3.org/2002/07/owl#" >
>      <!ENTITY rdf  "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
> ]>
>
>
> <rdf:RDF xmlns="http://luminary.unx.sas.com/test#"
>         xml:base="http://luminary.unx.sas.com/test#"
>         xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
>
>         <owl:Ontology rdf:about="TestBase">
>                <rdfs:comment>Test Base Ontology</rdfs:comment>
>                <rdfs:label>Test Base Ontology</rdfs:label>
>         </owl:Ontology>
>
>         <owl:Class rdf:ID="Person" />
>         <owl:Class rdf:ID="Teacher">
>             <rdfs:subClassOf rdf:resource="#Person" />
>         </owl:Class>
> </rdf:RDF>
>
> Next, the importing ontology:
>
> <!DOCTYPE rdf:RDF [
>      <!ENTITY xsd  "http://www.w3.org/2001/XMLSchema#" >
>      <!ENTITY owl  "http://www.w3.org/2002/07/owl#" >
>      <!ENTITY rdf  "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
>      <!ENTITY tst  "http://luminary.unx.sas.com/test#" >
> ]>
>
>
> <rdf:RDF xmlns="http://luminary.unx.sas.com/import#"
>         xml:base="http://luminary.unx.sas.com/import#"
>         xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
>         xmlns:tst="http://luminary.unx.sas.com/test#">
>
>         <owl:Ontology rdf:about="TestImport">
>                <rdfs:comment>Test Import Ontology</rdfs:comment>
>                <rdfs:label>Test Import Ontology</rdfs:label>
>                <owl:imports rdf:resource="http://luminary.unx.sas.com/luminary/testbase.owl"/>
>         </owl:Ontology>
>
>         <owl:Class rdf:ID="Administrator">
>             <rdfs:subClassOf rdf:resource="&tst;Person" />
>         </owl:Class>
> </rdf:RDF>
>
> Finally, here is the Java class I wrote to test this:
>
> import java.io.FileInputStream;
> import java.io.IOException;
> import java.util.Iterator;
> import com.hp.hpl.jena.ontology.OntClass;
> import com.hp.hpl.jena.ontology.OntModel;
> import com.hp.hpl.jena.ontology.OntModelSpec;
> import com.hp.hpl.jena.rdf.model.*;
> import com.hp.hpl.jena.vocabulary.RDFS;
>
> public class SubclassTest {
>
>      public static void main(String[] args) throws IOException {
>          OntModel model =
>              ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF);
>          FileInputStream inStream =
>              new FileInputStream("resources/testimport.owl");
>          model.read(inStream, null);
>          inStream.close();
>          for (Iterator<OntClass> clsIter = model.listClasses(); clsIter
>              .hasNext();) {
>              OntClass cls = clsIter.next();
>              System.out.println("CLS: " + cls.getURI());
>              for (StmtIterator stIter =
>                  model.getBaseModel().listStatements(cls, RDFS.subClassOf,
>                      (RDFNode) null); stIter.hasNext();) {
>                  Statement stmt = stIter.next();
>                  RDFNode obj = stmt.getObject();
>                  if (obj.isURIResource()) {
>                      OntClass par = model.getOntClass(obj.toString());
>                      System.out.println("  Parent: " + par.getURI());
>                  }
>              }
>          }
>      }
> }
>
> The output from the class shows the following (I've trimmed the www.w3.org<http://www.w3.org> classes from this for brevity):

[Aside: for testing import processing it would be simpler to work 
without inference so you can see the wood for the trees.]

> CLS: http://luminary.unx.sas.com/import#Administrator
>    Parent: http://luminary.unx.sas.com/test#Person
> CLS: http://luminary.unx.sas.com/test#Teacher
> CLS: http://luminary.unx.sas.com/test#Person
>
> Clearly, the Teacher is a subclass of Person, as it is defined in the base ontology. However, this relationship does not appear. When an ontology is imported, it is supposed to import all definitions and statements. However, this is clearly not the case.

How are you expecting the imported document to be located?

The import URL is given as:

    http://luminary.unx.sas.com/luminary/testbase.owl

but that URL gives a 404 for me.

To map a URL onto a local file you need either an ont-policy.rdf file or 
need to programatically configure an OntDocumentManager, as described in:

   http://jena.apache.org/documentation/ontology/

Your code doesn't include any OntDocumentManager set up so presumably 
you are relying on an ont-policy document, in which case the problem may 
be in the mapping file itself or the file might not be being found in 
your execution environment.

Dave