Hi Mario,
On 26/08/11 07:56, Mario Kofler wrote:
I have a general question about matching information between two
ontologies. Imagine I have two ontologies, while each of the
ontologies contains a specific concept. This concept, let's name it
Pizza, represents the same conceptual entity in the real world,
however the two ontologies give different views on this concept.
Hence, for example, in ontology A the concept has a relation
'Pizza hasBase PizzaBase'
and in the second ontology B the concept has a relation
'Pizza inventedBy Nation".
Now, what I need is a somehow "global view" of the Pizza, which
contains all the information about a specific pizza that is available
in both ontologies, hence for a specific individual "PizzaNeapolitana"
i want
"PizzaNeapolitana hasBase CrispyBase"
"PizzaNeapolitana inventedBy Neapolitans".
My question now is, how can i make sure in Jena, that
"PizzaNeapolitana" which is available two times (once in ontology A
and once in B) is treated as one individual in Jena, hence these
individuals in the two
ontologies denote one and the same individual in real world.
Actually, I think you need to be careful about what you want here. On
the one hand, you are talking about individuals (a Pizza is a thing that
has a base), and on the other hand you are talking about classes -
NeopolitanPizza is a type of (i.e. is a member of the class of) Pizzas.
Separate from how you manage that in Jena, if you write it naively
you'll have something like:
:NeopolitanPizza rdf:type :Pizza.
:Pizza :hasBase :thin.
Which states that :Pizza is an abstract concept (the set of all possible
pizzas) but that abstract concept has a thin bread base!
There are various ways to handle this. See:
http://www.w3.org/TR/swbp-classes-as-values/
Any of these approaches can be used in Jena, depending which approach
suits your needs.
Direct import of one ontology into the other is not possible, due to
reasoning constraints. There are too many classes and individuals in
either of these two ontologies as a direct import would make sense
(reasoning would take an extreme long time).
What I want to do is somehow "mask" that there are two individuals in
the both ontologies, and access the specific Pizza as one individual
as the two individuals are just two views of the same entity in real
world.
It sounds like you want a union of the two models, which will "just
work" if the shared concepts use the same URI. There are various ways to
do this in Jena. I've attached some sample code with one way of
approaching the problem, which hopefully will give you some clues. If
not, please post a more specific question.
Ian
--
____________________________________________________________
Ian Dickinson Epimorphics Ltd, Bristol, UK
mailto:[email protected] http://www.epimorphics.com
cell: +44-7786-850536 landline: +44-1275-399069
------------------------------------------------------------
Epimorphics Ltd. is a limited company registered in England
(no. 7016688). Registered address: Court Lodge, 105 High St,
Portishead, Bristol BS20 6PT, UK
package example;
import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.StmtIterator;
public class PizzaExample
{
public static void main( String[] args ) {
String nsA = "http://example.com/pizza#";
String nsB = "http://pretend-pizzas.com/pizza#";
// Ontology A contains general information about pizzas
OntModel a = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
OntClass pizzaClass = a.createClass( nsA + "Pizza" );
// Pizzas were invented by Ancient Rome
OntProperty inventedBy = a.createOntProperty( nsA + "inventedBy" );
Restriction r = a.createHasValueRestriction( null, inventedBy, a.createLiteral( "AncientRome" ) );
pizzaClass.addSuperClass( r );
// Ontology B contains some details of a particular pizza
OntModel b = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
// a particular instance of a Pizza
OntResource neoPizza = b.createOntResource( nsB + "neopolitanPizza" );
neoPizza.addRDFType( pizzaClass );
OntProperty hasBase = b.createOntProperty( nsB + "hasProperty" );
neoPizza.addProperty( hasBase, "thin" );
// we can just bring these together without inference
OntModel union1 = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM );
union1.addSubModel( a );
union1.addSubModel( b );
showIndividual( "First case, no inference: ", neoPizza, union1 );
// or with inference
OntModel union2 = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_MICRO_RULE_INF );
union2.addSubModel( a );
union2.addSubModel( b );
showIndividual( "Second case, with inference: ", neoPizza, union2 );
// or with inference and owl:sameAs
OntModel union3 = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_MICRO_RULE_INF );
union3.addSubModel( a );
union3.addSubModel( b );
Individual someOtherPizza = union3.createIndividual( nsA + "someOtherPizza", pizzaClass );
someOtherPizza.addSameAs( neoPizza );
showIndividual( "Third case, with inference and owl:sameAs: ", someOtherPizza, union3 );
}
private static void showIndividual( String msg, OntResource root, OntModel m ) {
System.out.println( msg );
for (StmtIterator i = root.inModel( m ).asResource().listProperties(); i.hasNext(); ) {
System.out.println( i.next() );
}
System.out.println( "[]." );
}
}