OK - thanks. This solves the problem.
-----Original Message-----
From: Dave Reynolds [mailto:[email protected]]
Sent: Tuesday, August 13, 2013 11:37 AM
To: [email protected]
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:[email protected]]
> Sent: Tuesday, August 13, 2013 11:04 AM
> To: [email protected]
> 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
>
>
>