On Thu, May 16, 2013 at 10:41 AM, Ed Swing <[email protected]> wrote:
> I am trying to create a duplicate of an ontology model to test whether 
> inserting particular triples results in a valid ontology. However, I am 
> seeing invalid results appear in the duplicate ontology model when its valid 
> in the original ontology model. Here's the snippet of Java code:
>
>         OntModel model = (various code to load it)
>
>         OntModel tmpModel =
>             ModelFactory.createOntologyModel(model.getSpecification(), model);
>         ValidityReport rept = model.validate();
>         System.out
>             .println("Model Good: " + (rept.isClean() && rept.isValid()));
>         rept = tmpModel.validate();
>         System.out.println("Duplicate Good: "
>             + (rept.isClean() && rept.isValid()));
>
> From what I understand, the createOntologyModel should be creating a 
> duplicate of the existing ontology model. However, I am getting the following 
> result:
> Model Good: true
> Duplicate Good: false
>
> What could be causing this behavior? Is this the proper way to create a 
> duplicate ontology model?

What exactly do you mean by duplicate?  Do you want a distinct
ontology model that has the *same* base model?  Or an ontology model
with a distinct base model that contains the same triples?  I haven't
used validity reports, and you don't mention what OntModelSpec you're
using, nor what kinds of data are in your models, so I don't know what
might be causing the issue in your case.  However, here's an example
that shows a distinction between the model and tmpModel.  While both
model1 and model2 in this example are valid and clean, they don't have
the same base models.  I don't know whether that should end up causing
a problem or not, but it's something to consider.

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


public class Duplicates {
        public static void main(String[] args) {
                OntModel model1 = ModelFactory.createOntologyModel(
OntModelSpec.OWL_DL_MEM_RULE_INF );
                OntModel model2 = ModelFactory.createOntologyModel(
model1.getSpecification(), model1 );
                
                System.out.println( "Base1: "+model1.getBaseModel() );
                System.out.println( "Base2: "+model2.getBaseModel() );
                
                ValidityReport report1 = model1.validate();
                ValidityReport report2 = model2.validate();
                
                for ( ValidityReport report : new ValidityReport[] { report1, 
report2 } ) {
                        System.out.println( "Valid: "+report.isValid() );
                        System.out.println( "Clean: "+report.isClean() );
                }
        }
}

I think that for just creating a model that is like another
(especially if they're inference models), you might do something like
this:

// create another model with the same OntModelSpec.
model2 = ModelFactory.createOntologyModel( model1.getSpecification() ) :
// Add all the triples from model1's base model (so you're not adding
the inferred triples)
// to model2.
model2.add( model1.getBaseModel() );

If model1 has submodels, then you might have to do more adding than
just the base model, of course.

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

Reply via email to