/*
* Michel Héon PhD: Web sémantique et modélisation ontologique - Guide du développeur Java sous Eclipse
* This file is part of the book:
*
* Michel Héon
* Web sémantique et modélisation ontologique - Guide du développeur Java sous Eclipse
* 2014
* Editions ENI
* ISBN : 978-2-7460-8869-6
* EAN : 9782746088696
* France
*
* The contents of this file are subject to the LGPL License, Version 3.0.
*
* Copyright (C) 2014, Cotechnoe inc. http://www.cotechnoe.com, http://java-ws.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*
* Alternatively, the contents of this file may be used under the terms of the Apache License, Version 2.0
* in which case, the provisions of the Apache License Version 2.0 are applicable instead of those above.
*
* Copyright (C) 2014, Cotechnoe inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.java_ws.owlapi.exemple;
import static org.semanticweb.owlapi.vocab.OWLFacet.MAX_EXCLUSIVE;
import static org.semanticweb.owlapi.vocab.OWLFacet.MIN_INCLUSIVE;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.coode.owlapi.manchesterowlsyntax.ManchesterOWLSyntaxOntologyFormat;
import org.coode.owlapi.turtle.TurtleOntologyFormat;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.OWLXMLOntologyFormat;
import org.semanticweb.owlapi.io.StreamDocumentTarget;
import org.semanticweb.owlapi.model.AddAxiom;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLDataExactCardinality;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLDataPropertyExpression;
import org.semanticweb.owlapi.model.OWLDataRange;
import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom;
import org.semanticweb.owlapi.model.OWLDatatype;
import org.semanticweb.owlapi.model.OWLDifferentIndividualsAxiom;
import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom;
import org.semanticweb.owlapi.model.OWLEntity;
import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom;
import org.semanticweb.owlapi.model.OWLException;
import org.semanticweb.owlapi.model.OWLFacetRestriction;
import org.semanticweb.owlapi.model.OWLFunctionalDataPropertyAxiom;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLLiteral;
import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom;
import org.semanticweb.owlapi.model.OWLObjectCardinalityRestriction;
import org.semanticweb.owlapi.model.OWLObjectExactCardinality;
import org.semanticweb.owlapi.model.OWLObjectHasSelf;
import org.semanticweb.owlapi.model.OWLObjectHasValue;
import org.semanticweb.owlapi.model.OWLObjectIntersectionOf;
import org.semanticweb.owlapi.model.OWLObjectInverseOf;
import org.semanticweb.owlapi.model.OWLObjectOneOf;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLOntologyStorageException;
import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;
import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom;
import org.semanticweb.owlapi.model.PrefixManager;
import org.semanticweb.owlapi.reasoner.ConsoleProgressMonitor;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
import org.semanticweb.owlapi.reasoner.SimpleConfiguration;
import org.semanticweb.owlapi.util.DefaultPrefixManager;
import org.semanticweb.owlapi.util.InferredOntologyGenerator;
import org.semanticweb.owlapi.vocab.PrefixOWLOntologyFormat;
import com.clarkparsia.owlapi.explanation.PelletExplanation;
import com.clarkparsia.owlapi.explanation.io.manchester.ManchesterSyntaxExplanationRenderer;
import com.clarkparsia.pellet.owlapiv3.PelletReasoner;
import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory;
import com.java_ws.owlapi.exemple.util.JavawsHelper;
/** Auteur: Michel Héon PhD
* Cotechnoe http://www.cotechnoe.com
* Date: 15-jan-2014
*/
public class ChapVII_Demo {
@SuppressWarnings("unused")
/****************************************************************
****************************************************************
**
** Chapitre 7 Démonstrations
**
****************************************************************
****************************************************************/
public static void main(String[] args) throws UnsupportedOperationException, OWLException, IOException {
// Section 2.6
if (false) classeComplexe();
// Section 3
// Section 3.1.2
if (false) patronRestrictionExistentielle();
// Section 3.1.2 en Complément
if (false) restrictionExistentielle();
// Section 3.2.2
if (false) patronRestrictionUniverselle();
// Section 3.3.2
if (false) principeDeFermeture();
// Section 3.6.2
if (false) restrictionHasValue_HasSelf();
// Section 5.4
if (false) determinerTauxImpot();
// Section 6 Démonstration des modèles
if (false) demoPropriete();
System.out.println("-->FIN<--");
}
/****************************************************************
****************************************************************
**
** Section 2.6 Démonstration de l’usage de classes complexes
**
****************************************************************
****************************************************************/
public static void classeComplexe() throws OWLOntologyCreationException, OWLOntologyStorageException {
/***********************************************************
*
* ENTETE DU PROGRAMME
*
***********************************************************/
//
// Attribuer les dénominations: IRI et Préfix
//
String FAMILIES_IRI = "http://java-ws.com/ontologie/families";
PrefixOWLOntologyFormat familiesOntologyFormat = new TurtleOntologyFormat();
familiesOntologyFormat.setDefaultPrefix(FAMILIES_IRI + "#");
familiesOntologyFormat.setPrefix( "myFamily",FAMILIES_IRI + "#");
PrefixManager familiesPrefix = new DefaultPrefixManager(FAMILIES_IRI +"#");
//
// Instancier le gestionnaire, et les fabriques
//
IRI familiesIRI = IRI.create(FAMILIES_IRI);
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
//
// Instancier le gestionnaire, et les fabriques
//
OWLOntology familiesOntology = manager.createOntology(familiesIRI);
OWLOntology inferFamilyOntology = manager.createOntology();
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
/***********************************************************
*
* CORPS DU PROGRAMME (La description du modèle conceptuel)
*
***********************************************************/
PelletReasoner reasoner = (PelletReasoner) reasonerFactory.createNonBufferingReasoner(familiesOntology, config);
/*
* Construire l'ontologie
*/
OWLClass woman = factory.getOWLClass(":Woman", familiesPrefix);
OWLClass parent = factory.getOWLClass(":Parent", familiesPrefix);
OWLClass mother = factory.getOWLClass(":Mother", familiesPrefix);
OWLClass father = factory.getOWLClass(":Father", familiesPrefix);
OWLClass person = factory.getOWLClass(":Person", familiesPrefix);
OWLClass man = factory.getOWLClass(":Man", familiesPrefix);
OWLClass childlessPerson = factory.getOWLClass(":ChildlessPerson", familiesPrefix);
OWLClass grandFather = factory.getOWLClass(":GrandFather", familiesPrefix);
OWLIndividual jack = factory.getOWLNamedIndividual(":Jack", familiesPrefix);
OWLIndividual jane = factory.getOWLNamedIndividual(":Jane", familiesPrefix);
OWLIndividual mary = factory.getOWLNamedIndividual(":Mary", familiesPrefix);
OWLIndividual sophie = factory.getOWLNamedIndividual(":Sophie", familiesPrefix);
OWLIndividual john = factory.getOWLNamedIndividual(":John", familiesPrefix);
OWLIndividual jim = factory.getOWLNamedIndividual(":Jim", familiesPrefix);
OWLIndividual bill = factory.getOWLNamedIndividual(":Bill", familiesPrefix);
OWLIndividual steve = factory.getOWLNamedIndividual(":Steve", familiesPrefix);
OWLClassAssertionAxiom janeIsAMother = factory.getOWLClassAssertionAxiom(mother, jane);
OWLClassAssertionAxiom maryIsAParent = factory.getOWLClassAssertionAxiom(parent, mary);
OWLClassAssertionAxiom maryIsAWoman = factory.getOWLClassAssertionAxiom(woman, mary);
OWLClassAssertionAxiom sophieIsAWoman = factory.getOWLClassAssertionAxiom(woman, sophie);
OWLClassAssertionAxiom johnIsAParent = factory.getOWLClassAssertionAxiom(parent, john);
OWLClassAssertionAxiom johnIsAMan = factory.getOWLClassAssertionAxiom(man, john);
OWLClassAssertionAxiom jimIsAMan = factory.getOWLClassAssertionAxiom(man, jim);
OWLClassAssertionAxiom billIsAFather = factory.getOWLClassAssertionAxiom(father, bill);
OWLClassAssertionAxiom steveIsAFather = factory.getOWLClassAssertionAxiom(father, steve);
OWLClassAssertionAxiom steveIsAParent = factory.getOWLClassAssertionAxiom(parent, steve);
OWLSubClassOfAxiom womanKindOfPerson = factory.getOWLSubClassOfAxiom(woman, person);
OWLSubClassOfAxiom manKindOfPerson = factory.getOWLSubClassOfAxiom(man, person);
OWLClassAssertionAxiom jackPersonNotParent = factory.getOWLClassAssertionAxiom(factory.getOWLObjectIntersectionOf(person, factory.getOWLObjectComplementOf(parent)), jack);
OWLEquivalentClassesAxiom childlessPersonEquivPersonNotParent = factory.getOWLEquivalentClassesAxiom(childlessPerson, factory.getOWLObjectIntersectionOf(person, factory.getOWLObjectComplementOf(parent)));
OWLEquivalentClassesAxiom parentAxiom = factory.getOWLEquivalentClassesAxiom(parent, factory.getOWLObjectUnionOf(father, mother));
OWLEquivalentClassesAxiom motherAxiom = factory.getOWLEquivalentClassesAxiom(mother, factory.getOWLObjectIntersectionOf(woman, parent));
OWLEquivalentClassesAxiom fatherAxiom = factory.getOWLEquivalentClassesAxiom(father, factory.getOWLObjectIntersectionOf(man, parent));
OWLEquivalentClassesAxiom grandFatherAxiom = factory.getOWLEquivalentClassesAxiom(grandFather, factory.getOWLObjectIntersectionOf(parent, father));
/***********************************************************
*
* PIED DU PROGRAMME
*
***********************************************************/
// Ajouter les axiomes à l’ontologie
manager.addAxiom(familiesOntology, janeIsAMother);
manager.addAxiom(familiesOntology, maryIsAParent);
manager.addAxiom(familiesOntology, maryIsAWoman);
manager.addAxiom(familiesOntology, sophieIsAWoman);
manager.addAxiom(familiesOntology, johnIsAParent);
manager.addAxiom(familiesOntology, johnIsAMan);
manager.addAxiom(familiesOntology, jimIsAMan);
manager.addAxiom(familiesOntology, billIsAFather);
manager.addAxiom(familiesOntology, womanKindOfPerson);
manager.addAxiom(familiesOntology, manKindOfPerson);
manager.addAxiom(familiesOntology, parentAxiom);
manager.addAxiom(familiesOntology, fatherAxiom);
manager.addAxiom(familiesOntology, motherAxiom);
manager.addAxiom(familiesOntology, childlessPersonEquivPersonNotParent);
manager.addAxiom(familiesOntology, jackPersonNotParent);
manager.addAxiom(familiesOntology, steveIsAFather);
manager.addAxiom(familiesOntology, steveIsAParent);
manager.addAxiom(familiesOntology, grandFatherAxiom);
// Imprimer l’ontologie descriptive
JavawsHelper.printTurtle(manager,familiesOntology );
//Inférer l'ontologie descriptive
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner);
iog.fillOntology(manager, inferFamilyOntology);
// Imprimer l'ontologie inférée
manager.saveOntology(inferFamilyOntology, familiesOntologyFormat, new StreamDocumentTarget(System.out));
}
/****************************************************************
****************************************************************
**
** Section 3.1.2 Démonstration : l’ensemble des individus pour lesquelles
** il existe des valeurs associées à une propriété
**
****************************************************************
****************************************************************/
public static void restrictionExistentielle() throws OWLOntologyCreationException, OWLOntologyStorageException {
/***********************************************************
*
* ENTETE DU PROGRAMME
*
***********************************************************/
//
// Attribuer les dénominations: IRI et Préfix
//
String FAMILIES_IRI = "http://java-ws.com/ontologie/families";
PrefixOWLOntologyFormat familiesOntologyFormat = new TurtleOntologyFormat();
familiesOntologyFormat.setDefaultPrefix(FAMILIES_IRI + "#");
familiesOntologyFormat.setPrefix( "myFamily",FAMILIES_IRI + "#");
PrefixManager familiesPrefix = new DefaultPrefixManager(FAMILIES_IRI +"#");
//
// Instancier le gestionnaire, et les fabriques
//
IRI familiesIRI = IRI.create(FAMILIES_IRI);
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
//
// Instancier le gestionnaire, et les fabriques
//
OWLOntology familiesOntology = manager.createOntology(familiesIRI);
OWLOntology inferFamilyOntology = manager.createOntology();
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
/***********************************************************
*
* CORPS DU PROGRAMME (La description du modèle conceptuel)
*
***********************************************************/
PelletReasoner reasoner = (PelletReasoner) reasonerFactory.createNonBufferingReasoner(familiesOntology, config);
/*
* Construire l'ontologie
*/
OWLClass person = factory.getOWLClass(":Person", familiesPrefix);
OWLClass parent = factory.getOWLClass(":Parent", familiesPrefix);
OWLClass happyPerson = factory.getOWLClass(":HappyPerson", familiesPrefix);
OWLClass happy = factory.getOWLClass(":Happy", familiesPrefix);
OWLClass johnChildren = factory.getOWLClass(":JohnChildren", familiesPrefix);
OWLClass narcisticPerson = factory.getOWLClass(":NarcisticPerson", familiesPrefix);
OWLObjectProperty hasChild = factory.getOWLObjectProperty(":hasChild", familiesPrefix);
OWLObjectProperty loves = factory.getOWLObjectProperty(":loves", familiesPrefix);
OWLObjectProperty otherProp = factory.getOWLObjectProperty(":otherProp", familiesPrefix);
OWLIndividual john = factory.getOWLNamedIndividual(":John", familiesPrefix);
OWLIndividual paul = factory.getOWLNamedIndividual(":Paul", familiesPrefix);
OWLIndividual anyBody = factory.getOWLNamedIndividual(":anyBody", familiesPrefix);
OWLIndividual someBody = factory.getOWLNamedIndividual(":someBody", familiesPrefix);
OWLClassAssertionAxiom paulIsAPerson = factory.getOWLClassAssertionAxiom(person, paul);
OWLClassAssertionAxiom johnIsHappyPerson = factory.getOWLClassAssertionAxiom(happyPerson, john);
OWLObjectSomeValuesFrom someHasChildPerson = factory.getOWLObjectSomeValuesFrom(hasChild, person);
OWLObjectAllValuesFrom AllHasChildHappy = factory.getOWLObjectAllValuesFrom(hasChild, happy);
factory.getOWLObjectIntersectionOf(factory.getOWLObjectAllValuesFrom(hasChild, happyPerson),
factory.getOWLObjectSomeValuesFrom(hasChild, happyPerson));
OWLEquivalentClassesAxiom allHappyPersonHasChildHappyAxiom = factory.getOWLEquivalentClassesAxiom(happyPerson, AllHasChildHappy);
OWLEquivalentClassesAxiom johnChildrenaxiom = factory.getOWLEquivalentClassesAxiom(johnChildren, factory.getOWLObjectHasValue(hasChild, john));
OWLEquivalentClassesAxiom narcisticPersonAxiom = factory.getOWLEquivalentClassesAxiom(narcisticPerson, factory.getOWLObjectHasSelf(loves));
OWLEquivalentClassesAxiom someHasChildPersonAxiom = factory.getOWLEquivalentClassesAxiom(parent, someHasChildPerson);
OWLObjectPropertyAssertionAxiom johnHasChildPaul = factory.getOWLObjectPropertyAssertionAxiom(hasChild, john, paul);
/***********************************************************
*
* PIED DU PROGRAMME
*
***********************************************************/
// Ajouter les axiomes à l’ontologie
manager.addAxiom(familiesOntology, johnHasChildPaul);
manager.addAxiom(familiesOntology, someHasChildPersonAxiom);
manager.addAxiom(familiesOntology, johnIsHappyPerson);
manager.addAxiom(familiesOntology, paulIsAPerson);
manager.addAxiom(familiesOntology, allHappyPersonHasChildHappyAxiom);
manager.addAxiom(familiesOntology, factory.getOWLObjectPropertyAssertionAxiom(otherProp, someBody, anyBody));
manager.addAxiom(familiesOntology, factory.getOWLClassAssertionAxiom(happyPerson, someBody));
// Imprimer l’ontologie descriptive
JavawsHelper.printTurtle(manager,familiesOntology );
//Inférer l'ontologie descriptive
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner);
iog.fillOntology(manager, inferFamilyOntology);
// Imprimer l'ontologie inférée
manager.saveOntology(inferFamilyOntology, familiesOntologyFormat, new StreamDocumentTarget(System.out));
}
/****************************************************************
****************************************************************
**
** Section 3.1.2 Démonstration : l’ensemble des individus pour laquelle il existe des valeurs associées à une propriété
**
****************************************************************
****************************************************************/
public static void patronRestrictionExistentielle() throws OWLOntologyCreationException, OWLOntologyStorageException {
/***********************************************************
*
* ENTETE DU PROGRAMME
*
***********************************************************/
//
// Attribuer les dénominations: IRI et Préfix
//
String ONTO_IRI_NAME = "http://java-ws.com/ontologie/patron";
PrefixOWLOntologyFormat ontologyFormat = new TurtleOntologyFormat();
ontologyFormat.setDefaultPrefix(ONTO_IRI_NAME + "#");
ontologyFormat.setPrefix( "myFamily",ONTO_IRI_NAME + "#");
PrefixManager prefix = new DefaultPrefixManager(ONTO_IRI_NAME +"#");
//
// Instancier le gestionnaire, et les fabriques
//
IRI ontologyIRI = IRI.create(ONTO_IRI_NAME);
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
//
// Instancier le gestionnaire, et les fabriques
///
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLOntology inferOntology = manager.createOntology();
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
/***********************************************************
*
* CORPS DU PROGRAMME (La description du modèle conceptuel)
*
***********************************************************/
PelletReasoner reasoner = (PelletReasoner) reasonerFactory.createNonBufferingReasoner(ontology, config);
/*
* Construire l'ontologie
*/
OWLClass A = factory.getOWLClass(":A", prefix);
OWLClass B = factory.getOWLClass(":B", prefix);
OWLIndividual a = factory.getOWLNamedIndividual(":a", prefix);
OWLIndividual b = factory.getOWLNamedIndividual(":b", prefix);
OWLObjectProperty P = factory.getOWLObjectProperty(":p", prefix);
OWLObjectSomeValuesFrom someP_B = factory.getOWLObjectSomeValuesFrom(P, B);
OWLObjectPropertyAssertionAxiom aPb = factory.getOWLObjectPropertyAssertionAxiom(P, a, b);
OWLEquivalentClassesAxiom AEquivSomeP_B = factory.getOWLEquivalentClassesAxiom(A, someP_B);
OWLClassAssertionAxiom bIsAB = factory.getOWLClassAssertionAxiom(B, b );
/***********************************************************
*
* PIED DU PROGRAMME
*
***********************************************************/
// Ajouter les axiomes à l’ontologie
manager.addAxiom(ontology, aPb);
manager.addAxiom(ontology, AEquivSomeP_B);
manager.addAxiom(ontology, bIsAB);
// Imprimer l’ontologie descriptive
JavawsHelper.printTurtle(manager,ontology );
//Inférer l'ontologie descriptive
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner);
iog.fillOntology(manager, inferOntology);
// Imprimer l'ontologie inférée
manager.saveOntology(inferOntology, ontologyFormat, new StreamDocumentTarget(System.out));
}
/****************************************************************
****************************************************************
**
** Section 3.2.2 Démonstration : l’ensemble des individus pour toutes les valeurs associées à une propriété
**
****************************************************************
****************************************************************/
public static void patronRestrictionUniverselle() throws OWLOntologyCreationException, OWLOntologyStorageException {
/***********************************************************
*
* ENTETE DU PROGRAMME
*
***********************************************************/
//
// Attribuer les dénominations: IRI et Préfix
//
String ONTO_IRI_NAME = "http://java-ws.com/ontologie/patron";
PrefixOWLOntologyFormat ontologyFormat = new TurtleOntologyFormat();
ontologyFormat.setDefaultPrefix(ONTO_IRI_NAME + "#");
ontologyFormat.setPrefix( "myFamily",ONTO_IRI_NAME + "#");
PrefixManager prefix = new DefaultPrefixManager(ONTO_IRI_NAME +"#");
//
// Instancier le gestionnaire, et les fabriques
//
IRI ontologyIRI = IRI.create(ONTO_IRI_NAME);
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
//
// Instancier le gestionnaire, et les fabriques
///
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLOntology inferOntology = manager.createOntology();
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
/***********************************************************
*
* CORPS DU PROGRAMME (La description du modèle conceptuel)
*
***********************************************************/
PelletReasoner reasoner = (PelletReasoner) reasonerFactory.createNonBufferingReasoner(ontology, config);
/*
* Construire l'ontologie
*/
OWLClass A = factory.getOWLClass(":A", prefix);
OWLClass B = factory.getOWLClass(":B", prefix);
OWLIndividual a = factory.getOWLNamedIndividual(":a", prefix);
OWLIndividual b = factory.getOWLNamedIndividual(":b", prefix);
OWLObjectProperty P = factory.getOWLObjectProperty(":p", prefix);
OWLObjectAllValuesFrom allP_B = factory.getOWLObjectAllValuesFrom(P, B);
OWLObjectPropertyAssertionAxiom aPb = factory.getOWLObjectPropertyAssertionAxiom(P, a, b);
OWLClassAssertionAxiom aIsAAllP = factory.getOWLClassAssertionAxiom(allP_B, a );
OWLEquivalentClassesAxiom AEquivSomeP_B = factory.getOWLEquivalentClassesAxiom(A, allP_B);
/***********************************************************
*
* PIED DU PROGRAMME
*
***********************************************************/
// Ajouter les axiomes à l’ontologie
manager.addAxiom(ontology, aPb);
manager.addAxiom(ontology, AEquivSomeP_B);
manager.addAxiom(ontology, aIsAAllP);
// Imprimer l’ontologie descriptive
JavawsHelper.printTurtle(manager,ontology );
//Inférer l'ontologie descriptive
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner);
iog.fillOntology(manager, inferOntology);
// Imprimer l'ontologie inférée
manager.saveOntology(inferOntology, ontologyFormat, new StreamDocumentTarget(System.out));
}
/****************************************************************
****************************************************************
**
** Section 3.3.2 Démonstration de l’inférence que « John » est un « HappyParent »
**
****************************************************************
****************************************************************/
public static void principeDeFermeture() throws OWLOntologyCreationException, OWLOntologyStorageException {
/***********************************************************
*
* ENTETE DU PROGRAMME
*
***********************************************************/
//
// Attribuer les dénominations: IRI et Préfix
//
String ONTO_IRI_NAME = "http://java-ws.com/ontologie/families";
PrefixOWLOntologyFormat ontologyFormat = new TurtleOntologyFormat();
ontologyFormat.setDefaultPrefix(ONTO_IRI_NAME + "#");
ontologyFormat.setPrefix( "myFamily",ONTO_IRI_NAME + "#");
PrefixManager prefix = new DefaultPrefixManager(ONTO_IRI_NAME +"#");
//
// Instancier le gestionnaire, et les fabriques
//
IRI ontologyIRI = IRI.create(ONTO_IRI_NAME);
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
//
// Instancier le gestionnaire, et les fabriques
///
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLOntology inferOntology = manager.createOntology();
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
/***********************************************************
*
* CORPS DU PROGRAMME (La description du modèle conceptuel)
*
***********************************************************/
PelletReasoner reasoner = (PelletReasoner) reasonerFactory.createNonBufferingReasoner(ontology, config);
/*
* Construire l'ontologie
*/
OWLClass happyParent = factory.getOWLClass(IRI.create(ontologyIRI + "#HappyParent"));
OWLClass happyChildren = factory.getOWLClass(IRI.create(ontologyIRI + "#HappyChildren"));
OWLObjectProperty hasChild = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasChild"));
OWLObjectSomeValuesFrom someHasChild = factory.getOWLObjectSomeValuesFrom(hasChild, happyChildren);
OWLObjectAllValuesFrom allHasChild = factory.getOWLObjectAllValuesFrom(hasChild, happyChildren);
OWLObjectIntersectionOf someANDAllhappyChild = factory.getOWLObjectIntersectionOf(someHasChild, allHasChild);
OWLIndividual john = factory.getOWLNamedIndividual(":John", prefix);
OWLIndividual jack = factory.getOWLNamedIndividual(":Jack", prefix);
OWLIndividual paul = factory.getOWLNamedIndividual(":Paul", prefix);
OWLAxiom someANDAllAxiom = factory.getOWLEquivalentClassesAxiom(happyParent, someANDAllhappyChild);
OWLClassAssertionAxiom jackIsAAllHasChild = factory.getOWLClassAssertionAxiom(allHasChild, jack );
OWLClassAssertionAxiom johnIsAAllHasChild = factory.getOWLClassAssertionAxiom(allHasChild, john );
OWLObjectPropertyAssertionAxiom johnHAsChildPaul = factory.getOWLObjectPropertyAssertionAxiom(hasChild, john, paul);
/***********************************************************
*
* PIED DU PROGRAMME
*
***********************************************************/
// Ajouter les axiomes à l’ontologie
manager.addAxiom(ontology, jackIsAAllHasChild);
manager.addAxiom(ontology, johnIsAAllHasChild);
manager.addAxiom(ontology, johnHAsChildPaul);
manager.addAxiom(ontology, someANDAllAxiom);
// Imprimer l’ontologie descriptive
JavawsHelper.printTurtle(manager,ontology );
//Inférer l'ontologie descriptive
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner);
iog.fillOntology(manager, inferOntology);
// Imprimer l'ontologie inférée
manager.saveOntology(inferOntology, ontologyFormat, new StreamDocumentTarget(System.out));
}
/****************************************************************
****************************************************************
**
** Section XXX
**
****************************************************************
****************************************************************/
public static void restrictionHasValue_HasSelf() throws OWLOntologyCreationException, OWLOntologyStorageException {
/***********************************************************
*
* ENTETE DU PROGRAMME
*
***********************************************************/
//
// Attribuer les dénominations: IRI et Préfix
//
String ONTO_IRI_NAME = "http://java-ws.com/ontologie/families";
PrefixOWLOntologyFormat ontologyFormat = new TurtleOntologyFormat();
ontologyFormat.setDefaultPrefix(ONTO_IRI_NAME + "#");
ontologyFormat.setPrefix( "myFamily",ONTO_IRI_NAME + "#");
PrefixManager prefix = new DefaultPrefixManager(ONTO_IRI_NAME +"#");
//
// Instancier le gestionnaire, et les fabriques
//
IRI ontologyIRI = IRI.create(ONTO_IRI_NAME);
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
//
// Instancier le gestionnaire, et les fabriques
///
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLOntology inferOntology = manager.createOntology();
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
/***********************************************************
*
* CORPS DU PROGRAMME (La description du modèle conceptuel)
*
***********************************************************/
PelletReasoner reasoner = (PelletReasoner) reasonerFactory.createNonBufferingReasoner(ontology, config);
/*
* Construire l'ontologie
*/
OWLClass johnsChildren = factory.getOWLClass(":JohnsChildren", prefix);
OWLClass narcisticPerson = factory.getOWLClass(":NarcisticPerson", prefix);
OWLIndividual john = factory.getOWLNamedIndividual(":John", prefix);
OWLIndividual paul = factory.getOWLNamedIndividual(":Paul", prefix);
OWLObjectProperty loves = factory.getOWLObjectProperty(":loves", prefix);
OWLObjectProperty hasParent = factory.getOWLObjectProperty(":hasParent", prefix);
OWLObjectHasSelf hasSelfLoves = factory.getOWLObjectHasSelf(loves);
OWLObjectHasValue hasValueJohn = factory.getOWLObjectHasValue(hasParent, john);
OWLAxiom narcisticPersonAxiom = factory.getOWLEquivalentClassesAxiom(narcisticPerson, hasSelfLoves);
OWLAxiom johnsChildrenAxiom = factory.getOWLEquivalentClassesAxiom(johnsChildren, hasValueJohn);
OWLObjectPropertyAssertionAxiom paulHasParentJohn = factory.getOWLObjectPropertyAssertionAxiom(hasParent, paul, john);
OWLObjectPropertyAssertionAxiom paulLovePaul = factory.getOWLObjectPropertyAssertionAxiom(loves, paul, paul);
/***********************************************************
*
* PIED DU PROGRAMME
*
***********************************************************/
// Ajouter les axiomes à l’ontologie
manager.addAxiom(ontology, narcisticPersonAxiom);
manager.addAxiom(ontology, johnsChildrenAxiom);
manager.addAxiom(ontology, paulHasParentJohn);
manager.addAxiom(ontology, paulLovePaul);
// manager.addAxiom(ontology, xx);
// Imprimer l’ontologie descriptive
JavawsHelper.printTurtle(manager,ontology );
//Inférer l'ontologie descriptive
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner);
iog.fillOntology(manager, inferOntology);
// Imprimer l'ontologie inférée
manager.saveOntology(inferOntology, ontologyFormat, new StreamDocumentTarget(System.out));
}
/****************************************************************
****************************************************************
**
** Section 5.4 Démonstration : aiguillonner une décision
**
****************************************************************
****************************************************************/
public static void determinerTauxImpot() throws OWLOntologyCreationException, OWLOntologyStorageException {
/***********************************************************
*
* ENTETE DU PROGRAMME
*
***********************************************************/
//
// Attribuer les dénominations: IRI et Préfix
//
String ONTO_IRI_NAME = "http://java-ws.com/ontologie/tauximpot";
PrefixOWLOntologyFormat ontologyFormat = new TurtleOntologyFormat();
ontologyFormat.setDefaultPrefix(ONTO_IRI_NAME + "#");
ontologyFormat.setPrefix( "tauximpot",ONTO_IRI_NAME + "#");
PrefixManager prefix = new DefaultPrefixManager(ONTO_IRI_NAME +"#");
//
// Instancier le gestionnaire, et les fabriques
//
IRI ontologyIRI = IRI.create(ONTO_IRI_NAME);
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
//
// Instancier le gestionnaire, et les fabriques
///
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLOntology inferOntology = manager.createOntology();
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
/***********************************************************
*
* CORPS DU PROGRAMME (La description du modèle conceptuel)
*
***********************************************************/
PelletReasoner reasoner = (PelletReasoner) reasonerFactory.createNonBufferingReasoner(ontology, config);
OWLObjectProperty aLaChargeDe = factory.getOWLObjectProperty(":aLaChargeDe", prefix);
OWLIndividual john = factory.getOWLNamedIndividual(":John", prefix);
OWLIndividual sophie = factory.getOWLNamedIndividual(":Sophie", prefix);
OWLIndividual paul = factory.getOWLNamedIndividual(":Paul", prefix);
OWLIndividual bill = factory.getOWLNamedIndividual(":Bill", prefix);
manager.addAxiom(ontology, factory.getOWLDifferentIndividualsAxiom(john, bill, paul, sophie));
OWLObjectOneOf personnesAChargeDe_John = factory.getOWLObjectOneOf(paul, bill);
OWLObjectOneOf personnesAChargeDe_Sophie = factory.getOWLObjectOneOf();
// Règle: - Pour au maximum 1 enfant à charge, le taux est à TAUX_CINQUANTE
manager.addAxiom(ontology, factory.getOWLEquivalentClassesAxiom(
factory.getOWLClass(":TAUX_CINQUANTE", prefix),
factory.getOWLObjectMaxCardinality(1, aLaChargeDe)));
// Règle - Pour au minimum 2 et au maximum 4 enfants à charge,
// le taux est à TAUX_TRENTE. L'usage de l'intersection permet
// de fixer la limite inférieure et la limite supérieure
// de la règle.
manager.addAxiom(ontology, factory.getOWLEquivalentClassesAxiom(
factory.getOWLClass(":TAUX_TRENTE", prefix),
factory.getOWLObjectIntersectionOf(
factory.getOWLObjectMinCardinality(2, aLaChargeDe),
factory.getOWLObjectMaxCardinality(4, aLaChargeDe)
)));
//Règle: - Pour 5 enfants à charge, le taux est à TAUX_DIX
manager.addAxiom(ontology, factory.getOWLEquivalentClassesAxiom(
factory.getOWLClass(":TAUX_DIX", prefix),
factory.getOWLObjectExactCardinality(5, aLaChargeDe)));
//Règle: - Pour au minimum 6 enfants à charge, le taux est à TAUX_ZÉRO
manager.addAxiom(ontology, factory.getOWLEquivalentClassesAxiom(
factory.getOWLClass(":TAUX_ZERO", prefix),
factory.getOWLObjectMinCardinality(6, aLaChargeDe)));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(aLaChargeDe, john, paul));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(aLaChargeDe, john, bill));
manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(factory.getOWLObjectAllValuesFrom(aLaChargeDe, personnesAChargeDe_Sophie), sophie));
manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(factory.getOWLObjectAllValuesFrom(aLaChargeDe, personnesAChargeDe_John), john));
/***********************************************************
*
* PIED DU PROGRAMME
*
***********************************************************/
// Ajouter les axiomes à l’ontologie
// Imprimer l’ontologie descriptive
JavawsHelper.printTurtle(manager,ontology );
//Inférer l'ontologie descriptive
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner);
iog.fillOntology(manager, inferOntology);
// Imprimer l'ontologie inférée
manager.saveOntology(inferOntology, ontologyFormat, new StreamDocumentTarget(System.out));
}
/****************************************************************
****************************************************************
**
** Section 6. Usage avancée de la propriété
**
****************************************************************
****************************************************************/
public static void demoPropriete() throws UnsupportedOperationException, OWLException, IOException {
/***********************************************************
*
* ENTETE DU PROGRAMME
*
***********************************************************/
//
// Attribuer les dénominations: IRI et Préfix
//
String FAMILIES_IRI = "http://java-ws.com/ontologie/families";
PrefixOWLOntologyFormat familiesOntologyFormat = new TurtleOntologyFormat();
familiesOntologyFormat.setDefaultPrefix(FAMILIES_IRI + "#");
familiesOntologyFormat.setPrefix( "myFamily",FAMILIES_IRI + "#");
PrefixManager prefix = new DefaultPrefixManager(FAMILIES_IRI +"#");
//
// Instancier le gestionnaire, et les fabriques
//
IRI familiesIRI = IRI.create(FAMILIES_IRI);
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
OWLReasonerFactory reasonerFactory = PelletReasonerFactory.getInstance();
//
// Instancier le gestionnaire, et les fabriques
//
OWLOntology ontology = manager.createOntology(familiesIRI);
/***********************************************************
*
* CORPS DU PROGRAMME (La description du modèle conceptuel)
*
***********************************************************/
/*
* Construire l'ontologie
*/
/*
*/
/*
* Construire les axiomes et les intégrer à l'ontologie
*/
OWLIndividual paul = factory.getOWLNamedIndividual(":Paul", prefix);
OWLIndividual bill = factory.getOWLNamedIndividual(":Bill", prefix);
OWLIndividual john = factory.getOWLNamedIndividual(":John", prefix);
OWLIndividual jack = factory.getOWLNamedIndividual(":Jack", prefix);
OWLIndividual mary = factory.getOWLNamedIndividual(":Mary", prefix);
OWLIndividual sophie = factory.getOWLNamedIndividual(":Sophie", prefix);
OWLIndividual marc = factory.getOWLNamedIndividual(":Marc", prefix);
OWLIndividual steve = factory.getOWLNamedIndividual(":Steve", prefix);
OWLIndividual indvA = factory.getOWLNamedIndividual(":indvB", prefix);
OWLIndividual indvB = factory.getOWLNamedIndividual(":indvA", prefix);
// Modifiez le no du Case pour atteindre le modèle à démontrer:
// Case1 = Implantation de la figure 7.23
// Case2 = Implantation de la figure 7.24
// Case3 = Implantation de la figure 7.26
// Case4 = Implantation de la figure 7.27
// Case5 = Implantation de la figure 7.28
// Case6 = Implantation de la figure 7.29
// Case7 = Implantation de la figure 7.30
// Case8 = Implantation de la figure 7.31
// Case9 = Implantation de la figure 7.32
// Case10 = Implantation de la figure 7.33
// Case11 = Implantation de la figure 7.34
// Case12 = Implantation de la figure 7.35
// Case13 = Implantation de la figure 7.36
// Case14 = Implantation de la figure 7.37
String Case = "Case1";
// Implantation de la figure 7.23
if (Case.equals("Case1")){
OWLObjectProperty hasChild = factory.getOWLObjectProperty(":hasChild", prefix);
OWLObjectProperty hasParent = factory.getOWLObjectProperty(":hasParent", prefix);
manager.addAxiom(ontology, factory.getOWLInverseObjectPropertiesAxiom(hasParent, hasChild));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(hasChild, john, mary));
// Implantation de la figure 7.24
} else if (Case.equals("Case2")){
OWLClass dead = factory.getOWLClass(":Dead", prefix);
OWLObjectProperty hasChild = factory.getOWLObjectProperty(":hasChild", prefix);
OWLClass orphan = factory.getOWLClass(":Orphan", prefix);
OWLObjectInverseOf inverseHasChild = factory.getOWLObjectInverseOf(hasChild);
OWLObjectAllValuesFrom allValuesDead = factory.getOWLObjectAllValuesFrom(inverseHasChild, dead);
manager.addAxiom(ontology, factory.getOWLEquivalentClassesAxiom(orphan, allValuesDead));
manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(orphan, mary));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(hasChild, marc, mary));
// Implantation de la figure 7.25
} else if (Case.equals("Case3")){
OWLObjectProperty hasSpouse = factory.getOWLObjectProperty(":hasSpouse", prefix);
manager.addAxiom(ontology, factory.getOWLSymmetricObjectPropertyAxiom(hasSpouse));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(hasSpouse, john, mary));
// Implantation de la figure 7.26
} else if (Case.equals("Case4")){
OWLObjectProperty hasChild = factory.getOWLObjectProperty(":hasChild", prefix);
manager.addAxiom(ontology, factory.getOWLAsymmetricObjectPropertyAxiom(hasChild));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(hasChild, john, bill));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(hasChild, bill, john));
// Implantation de la figure 7.27
} else if (Case.equals("Case5")){
OWLObjectProperty hasSpouse = factory.getOWLObjectProperty(":hasSpouse", prefix);
OWLObjectProperty hasParent = factory.getOWLObjectProperty(":hasParent", prefix);
manager.addAxiom(ontology, factory.getOWLDisjointObjectPropertiesAxiom(hasParent, hasSpouse));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(hasSpouse, indvA, indvB));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(hasParent, indvA, indvB));
// Implantation de la figure 7.28
} else if (Case.equals("Case6")){
OWLObjectProperty knows = factory.getOWLObjectProperty(":knows", prefix);
manager.addAxiom(ontology, factory.getOWLReflexiveObjectPropertyAxiom(knows));
manager.addAxiom(ontology, factory.getOWLDeclarationAxiom((OWLEntity) bill));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(knows, mary, john));
// Implantation de la figure 7.29
} else if (Case.equals("Case7")){
OWLObjectProperty parentOf = factory.getOWLObjectProperty(":parentOf", prefix);
manager.addAxiom(ontology, factory.getOWLIrreflexiveObjectPropertyAxiom(parentOf));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(parentOf, indvA, indvA));
// Implantation de la figure 7.30
} else if (Case.equals("Case8")){
OWLObjectProperty hasHusband = factory.getOWLObjectProperty(":hasHusband", prefix);
manager.addAxiom(ontology, factory.getOWLFunctionalObjectPropertyAxiom(hasHusband));
manager.addAxiom(ontology, factory.getOWLDifferentIndividualsAxiom(john, jack));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(hasHusband, mary, john));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(hasHusband, mary, jack));
// Implantation de la figure 7.31
} else if (Case.equals("Case9")){
OWLObjectProperty hasHusband = factory.getOWLObjectProperty(":hasHusband", prefix);
manager.addAxiom(ontology, factory.getOWLInverseFunctionalObjectPropertyAxiom(hasHusband));
manager.addAxiom(ontology, factory.getOWLDifferentIndividualsAxiom(mary, sophie));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(hasHusband, mary, john));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(hasHusband, sophie, john));
// Implantation de la figure 7.32
} else if (Case.equals("Case10")){
OWLObjectProperty hasAncestor = factory.getOWLObjectProperty(":hasAncestor", prefix);
manager.addAxiom(ontology, factory.getOWLTransitiveObjectPropertyAxiom(hasAncestor));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(hasAncestor, mary, marc));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(hasAncestor, marc, steve));
// Implantation de la figure 7.33
} else if (Case.equals("Case11")){
OWLObjectProperty hasParent = factory.getOWLObjectProperty(":hasParent", prefix);
OWLObjectProperty hasGrandparent = factory.getOWLObjectProperty(":hasGrandparent", prefix);
List hasGrandparentChain=new ArrayList();
hasGrandparentChain.add(hasParent);
hasGrandparentChain.add(hasParent);
manager.addAxiom(ontology, factory.getOWLSubPropertyChainOfAxiom(hasGrandparentChain, hasGrandparent));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(hasParent, mary, marc));
manager.addAxiom(ontology, factory.getOWLObjectPropertyAssertionAxiom(hasParent, marc, steve));
// Implantation de la figure 7.34
} else if (Case.equals("Case12")){
OWLClass person = factory.getOWLClass(":Person", prefix);
OWLDataPropertyExpression hasSSN = factory.getOWLDataProperty(":hasSSN", prefix);
manager.addAxiom(ontology, factory.getOWLHasKeyAxiom(person, hasSSN));
manager.addAxiom(ontology, factory.getOWLDataPropertyAssertionAxiom(hasSSN, john, 1234));
manager.addAxiom(ontology, factory.getOWLDataPropertyAssertionAxiom(hasSSN, jack, 1234));
manager.addAxiom(ontology, factory.getOWLDataPropertyAssertionAxiom(hasSSN, mary, 1234));
manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(person, john));
manager.addAxiom(ontology, factory.getOWLClassAssertionAxiom(person, jack));
manager.addAxiom(ontology, factory.getOWLDifferentIndividualsAxiom(mary, jack)); // OK, puisque Mary n'est pas membre dans Person
manager.addAxiom(ontology, factory.getOWLDifferentIndividualsAxiom(john, jack)); // incohérant puisque John et Jack sont membres de Person
}
/***********************************************************
*
* PIED DU PROGRAMME
*
***********************************************************/
// Imprimer l’ontologie descriptive
JavawsHelper.printTurtle(manager,ontology );
PelletExplanation.setup();
OWLOntology inferOntology = manager.createOntology();
ConsoleProgressMonitor progressMonitor = new ConsoleProgressMonitor();
OWLReasonerConfiguration config = new SimpleConfiguration(progressMonitor);
PelletReasoner reasoner = (PelletReasoner) reasonerFactory.createNonBufferingReasoner(ontology, config);
System.out.println("Is consistance ? Rep: "+reasoner.isConsistent());
if (reasoner.isConsistent())
{
InferredOntologyGenerator iog = new InferredOntologyGenerator(reasoner);
iog.fillOntology(manager, inferOntology);
// Imprimer l'ontologie inférée
manager.saveOntology(inferOntology, familiesOntologyFormat, new StreamDocumentTarget(System.out));
}
ManchesterSyntaxExplanationRenderer renderer = new ManchesterSyntaxExplanationRenderer();
// The writer used for the explanation rendered
PrintWriter out = new PrintWriter( System.out );
renderer.startRendering( out );
PelletExplanation expGen = new PelletExplanation( reasoner );
Set> exp = expGen.getInconsistencyExplanations();
renderer.render( exp );
renderer.endRendering();
}
}