On Thu, Apr 25, 2013 at 2:24 PM, Ian Dickinson <[email protected]> wrote:
> On 25/04/13 18:27, Joshua TAYLOR wrote:
>>
>> On Thu, Apr 25, 2013 at 11:46 AM, David Jordan <[email protected]>
>> wrote:
>>>
>>> I am writing a little performance benchmark test to ascertain the
>>> overhead in determining whether a given update is a valid. It was
>>> recommended before on this forum that the best way to do this
>>> efficiently is create a new OntModel A, have it import the
>>> associated ontology, then perform the few updates in this new
>>> OntModel A, and then call A.validate().isValid().
>>>
>>> Is an imported model simply a submodel, added by just calling the
>>> add method? I don’t see any specific method for importing a model,
>>> but some documentation suggests that a submodel is an imported
>>> model.
>>
>>
>> OntModels can have submodels, which are added with
>> OntModel#addSubModel [1].  However, OWL ontologies can also import
>> other ontologies via owl:imports, and this is a different concept
>> than OntModel and submodels.
>
> Not really. Sub-models are what OntModel uses to keep track of imports. An
> ontology with imported ontologies is a composite document, sub-models are
> the composite pattern analogue of that for OntModels.
>
> If you read an ontology into an OntModel, and that ontology owl:imports
> another ontology, the import will end up in a sub-model. Or you can add a
> sub-model directly using the Java API. Either way, you end up with the same
> composite model structure.

Sorry, I should have been clearer about what I meant by "different
concept."  The way that Jena OntModels handle owl:imports makes use of
submodels, but use of submodels alone doesn't imply that an
owl:imports relationship is being established.  If you have two
OntModels, o1, and o2, and add o2 as a submodel of o1, and then write
out o1, you won't have the imports relation between the two
ontologies.  To get that, one must actually get the Ontology object
from the OntModel and use Ontology#addImport, as in the following code
and output.  Sorry for any confusion. //JT

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.Ontology;
import com.hp.hpl.jena.rdf.model.ModelFactory;


public class OntSubModels {

        public static void main( String[] args ) {
                OntModel o1 = ModelFactory.createOntologyModel( 
OntModelSpec.OWL_DL_MEM );
                OntModel o2 = ModelFactory.createOntologyModel( 
OntModelSpec.OWL_DL_MEM );
                
                Ontology ont1 = o1.createOntology( "http://example.com/o1"; );
                Ontology ont2 = o2.createOntology( "http://example.com/o2"; );
                
                o1.addSubModel( o2 );
                
                o1.write( System.out, "N3" );
                System.out.println( "===" );
                o1.writeAll( System.out, "N3", null );
                
                OntModel o3 = ModelFactory.createOntologyModel( 
OntModelSpec.OWL_DL_MEM );
                Ontology ont3 = o3.createOntology( "http://example.com/o3"; );
                
                ont3.addImport( ont1 );
                ont3.addImport( ont2 );
                
                System.out.println( "===" );
                o3.write( System.out, "N3" );
        }
}

which produces as output

@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<http://example.com/o1>
      a       owl:Ontology .
===
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<http://example.com/o2>
      a       owl:Ontology .

<http://example.com/o1>
      a       owl:Ontology .
===
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:     <http://www.w3.org/2002/07/owl#> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<http://example.com/o3>
      a       owl:Ontology ;
      owl:imports <http://example.com/o2> , <http://example.com/o1> .



-- 
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/

Reply via email to