On 16/05/13 19:36, Ed Swing wrote:
While I see the difference in the code, the distinction is not at all apparent
between
model2 = ModelFactory.createOntologyModel(model1.getSpecification(), model1);
and
model2 = ModelFactory.createOntologyModel( model1.getSpecification() ) :
model2.add( model1.getBaseModel() );
According to the Javadoc, the method createOntologyModel(OntModelSpec spec, Model base)
does the following: "Answer a new ontology model, constructed according to the given
ontology model specification, and starting with the ontology data in the given
model."
An OntModel is just a wrapper round a base model. It doesn't itself have
a separate copy of the base triples.
If you want to actually duplicate a model you need to create a new model
and add() the triples from the current one into it.
So it creates a new ontology model, using the given ontology specification
(which is the same as the old ontology model, e.g.,
OntModelSpec.OWL_DL_MEM_RULE_INF). It would start with the data from the given
model, so it should have the triples from the old model. In the second case
above, only the base triples from model1 are added initially, but since they
have the same inferencer, it should derive the same triples.
Not quite. The reasoners are incomplete there are triples that could be
derived which are not derived (due the the layering of the rules).
By adding one rule reasoner on top of another you are adding extra
layers and new inferences *may* be possible.
In any case, I don't understand why model1 would be valid and model2 invalid if
they have the same triples and same specification.
They don't necessarily have the same triples, see above.
Don't know why model2 is invalid. There are at least two possibilities:
(a) The ontology is actually invalid in a way which the incomplete rule
reasoner cannot discover but the extra "iteration" of the second layer
of rules does discover.
(b) A bug in the rules or rule engine which is leading to an incorrect
inference in the layered case.
[Layering is a pain, it's there to trade-off performance against
completeness but if I had my time over I would not use it again.]
Dave
________________________________________
From: Joshua TAYLOR [[email protected]]
Sent: Thursday, May 16, 2013 11:10 AM
To: [email protected]
Subject: Re: Creating duplicate model
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.out4
.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/