You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by David Jordan <Da...@sas.com> on 2013/04/25 17:46:36 UTC

OntModel.validate( ) question

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.

When the A.validate() is called, it is just going to validate model A, or will it also validate the submodel, which would include the potentially large associated ontology?

David Jordan
Senior Software Developer
SAS Institute Inc.
Health & Life Sciences, Research & Development
Bldg R ▪ Office 4467
600 Research Drive ▪ Cary, NC 27513
Tel: 919 531 1233 ▪ david.jordan@sas.com<ma...@sas.com>
www.sas.com<http://www.sas.com/>
SAS® … THE POWER TO KNOW®


Re: OntModel.validate( ) question

Posted by Ian Dickinson <ia...@epimorphics.com>.
On 25/04/13 20:00, David Jordan wrote:
> Excuse my pickiness...
> Your code would have been clearer as:
Copy paste error. I did say that I hacked up a quick example!

> checkValid( m0, "m0, before" );
> checkValid( m1, "m1, before" );
> m1.addSubModel( m0 );
> checkValid( m0, "m0, after" );
> checkValid( m1, "m1, after" );
>
> With the following output:
> Model m0, before isValid() => null
> Model m1, before isValid() => true
> Model m0, after isValid() => null
> Model m1, after isValid() => false
>
> So what does it mean for validate() to return a null?
It means that there is nothing to provide a report. OntModelSpec.OWL_MEM 
constructs an OntModel without a reasoner. I suppose that, in that case, 
OntModelSpec could return a default ValidationReport denoting "no 
validation because no reasoner", and if I was writing the code today I'd 
probably consider doing that. But instead it returns null, which has the 
same semantics, and I would hesitate to change the API without a good 
reason.

> You cannot tell from the documentation, it implies it always returns an instance of ValidityReport.
> If it can return null, the javadoc should state so with a reason why.
Jena is open source. Please feel free to submit a patch.

>  From your example, it appears that m0 is null because there is only a single statement,
> m0.add( c0, OWL.disjointWith, c1 );
m0 is never null. The validation report for m0 is null because it has no 
reasoner.

> In the first case, it is completely separate from m1
> and in the second case because m1 contains m0,
> so m1 knows about m0 but m0 does not know about m1.
> Is that correct?
I'm not sure I understand the question. Ignore m0 for the time being. To 
begin with, m1 is consistent because it contains an individual i with 
two classes, which is perfectly legal in RDF and OWL. Now we add a 
sub-model (or, if you prefer, import the ontology) which contains the 
axioms for the classes. The only axiom is that c0 and c1 are disjoint, 
which means that no individual can be a member of both classes. Since i 
is a counter-example, m1 is not consistent, hence fails validation.

The point of the example was that the axiom - c0 :disjointWith c1 - was 
in a sub-model of the model that validate() was called on, m1. So the 
answer to the question "does validate() consider all of the sub-models 
or only the base model" is clearly "it considers all of the sub-models".

Ian


RE: OntModel.validate( ) question

Posted by David Jordan <Da...@sas.com>.
Excuse my pickiness...
Your code would have been clearer as:
checkValid( m0, "m0, before" );
checkValid( m1, "m1, before" );
m1.addSubModel( m0 );
checkValid( m0, "m0, after" );
checkValid( m1, "m1, after" );

With the following output:
Model m0, before isValid() => null
Model m1, before isValid() => true
Model m0, after isValid() => null
Model m1, after isValid() => false

So what does it mean for validate() to return a null?
You cannot tell from the documentation, it implies it always returns an instance of ValidityReport.
If it can return null, the javadoc should state so with a reason why.

From your example, it appears that m0 is null because there is only a single statement,
m0.add( c0, OWL.disjointWith, c1 );
In the first case, it is completely separate from m1
and in the second case because m1 contains m0,
so m1 knows about m0 but m0 does not know about m1.
Is that correct?



-----Original Message-----
From: Ian Dickinson [mailto:ian@epimorphics.com] 
Sent: Thursday, April 25, 2013 2:24 PM
To: users@jena.apache.org
Subject: Re: OntModel.validate( ) question

On 25/04/13 18:27, Joshua TAYLOR wrote:
> On Thu, Apr 25, 2013 at 11:46 AM, David Jordan <Da...@sas.com>
> 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.

> To add an owl:imports to an ontology,
> use OntModel#getOntology to get the ontology object for the ontology 
> that the OntModel represents, and use Ontology#addImport to add the 
> import. If you go down this road, you'll might need to be aware of 
> OntDocumentManagers [2] and import processing (whether to load 
> imported ontologies and the like).
>
> [1]
> http://jena.apache.org/documentation/javadoc/jena/com/hp/hpl/jena/onto
> logy/OntModel.html#addSubModel(com.hp.hpl.jena.rdf.model.Model)
>
>
[2]
http://jena.apache.org/documentation/javadoc/jena/com/hp/hpl/jena/ontology/OntDocumentManager.html
>
>> When the A.validate() is called, it is just going to validate model 
>> A, or will it also validate the submodel, which would include the 
>> potentially large associated ontology?
Validation, and inferencing in general, will work on the whole model. To demonstrate this, I hacked up a quick gist:

https://gist.github.com/ephemerian/5461867

Before adding the sub-model, the base model is consistent. After adding a sub-model containing the disjointness axiom, the base model is not
consistent:

Model m0, before isValid() => null
Model m0, before isValid() => true
Model m0, after isValid() => null
Model m0, after isValid() => false


Ian


Re: OntModel.validate( ) question

Posted by Ian Dickinson <ia...@epimorphics.com>.
On 25/04/13 21:30, Joshua TAYLOR wrote:
> On Thu, Apr 25, 2013 at 2:24 PM, Ian Dickinson <ia...@epimorphics.com> wrote:
>> On 25/04/13 18:27, Joshua TAYLOR wrote:
>>>
>>> On Thu, Apr 25, 2013 at 11:46 AM, David Jordan <Da...@sas.com>
>>> 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.
Sorry, I see what you mean. Yes, that's exactly right.

Ian


Re: OntModel.validate( ) question

Posted by Joshua TAYLOR <jo...@gmail.com>.
On Thu, Apr 25, 2013 at 2:24 PM, Ian Dickinson <ia...@epimorphics.com> wrote:
> On 25/04/13 18:27, Joshua TAYLOR wrote:
>>
>> On Thu, Apr 25, 2013 at 11:46 AM, David Jordan <Da...@sas.com>
>> 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/

Re: OntModel.validate( ) question

Posted by Ian Dickinson <ia...@epimorphics.com>.
On 25/04/13 18:27, Joshua TAYLOR wrote:
> On Thu, Apr 25, 2013 at 11:46 AM, David Jordan <Da...@sas.com>
> 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.

> To add an owl:imports to an ontology,
> use OntModel#getOntology to get the ontology object for the ontology
> that the OntModel represents, and use Ontology#addImport to add the
> import. If you go down this road, you'll might need to be aware of
> OntDocumentManagers [2] and import processing (whether to load
> imported ontologies and the like).
>
> [1]
> http://jena.apache.org/documentation/javadoc/jena/com/hp/hpl/jena/ontology/OntModel.html#addSubModel(com.hp.hpl.jena.rdf.model.Model)
>
>
[2] 
http://jena.apache.org/documentation/javadoc/jena/com/hp/hpl/jena/ontology/OntDocumentManager.html
>
>> When the A.validate() is called, it is just going to validate model
>> A, or will it also validate the submodel, which would include the
>> potentially large associated ontology?
Validation, and inferencing in general, will work on the whole model. To 
demonstrate this, I hacked up a quick gist:

https://gist.github.com/ephemerian/5461867

Before adding the sub-model, the base model is consistent. After adding 
a sub-model containing the disjointness axiom, the base model is not 
consistent:

Model m0, before isValid() => null
Model m0, before isValid() => true
Model m0, after isValid() => null
Model m0, after isValid() => false


Ian

Re: OntModel.validate( ) question

Posted by Joshua TAYLOR <jo...@gmail.com>.
On Thu, Apr 25, 2013 at 11:46 AM, David Jordan <Da...@sas.com> 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.  To add an owl:imports to an ontology, use
OntModel#getOntology to get the ontology object for the ontology that
the OntModel represents, and use Ontology#addImport to add the import.
 If you go down this road, you'll might need to be aware of
OntDocumentManagers [2] and import processing (whether to load
imported ontologies and the like).

[1] http://jena.apache.org/documentation/javadoc/jena/com/hp/hpl/jena/ontology/OntModel.html#addSubModel(com.hp.hpl.jena.rdf.model.Model)
[2] http://jena.apache.org/documentation/javadoc/jena/com/hp/hpl/jena/ontology/OntDocumentManager.html

> When the A.validate() is called, it is just going to validate model A, or will it also validate the submodel, which would include the potentially large associated ontology?

I don't have an answer for this.
-- 
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/