/*
* 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 java.util.ArrayList;
import java.util.List;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAsymmetricObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLDataPropertyExpression;
import org.semanticweb.owlapi.model.OWLDisjointObjectPropertiesAxiom;
import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom;
import org.semanticweb.owlapi.model.OWLFunctionalObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLHasKeyAxiom;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLInverseFunctionalObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLInverseObjectPropertiesAxiom;
import org.semanticweb.owlapi.model.OWLIrreflexiveObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom;
import org.semanticweb.owlapi.model.OWLObjectComplementOf;
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.OWLObjectMaxCardinality;
import org.semanticweb.owlapi.model.OWLObjectMinCardinality;
import org.semanticweb.owlapi.model.OWLObjectOneOf;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom;
import org.semanticweb.owlapi.model.OWLObjectUnionOf;
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.OWLReflexiveObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;
import org.semanticweb.owlapi.model.OWLSubPropertyChainOfAxiom;
import org.semanticweb.owlapi.model.OWLSymmetricObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLTransitiveObjectPropertyAxiom;
import com.java_ws.owlapi.exemple.util.JavawsHelper;
@SuppressWarnings("unused")
/** Auteur: Michel Héon PhD
* Cotechnoe http://www.cotechnoe.com
* Date: 15-jan-2014
*/
public class ChapVII {
/****************************************************************
****************************************************************
**
** Chapitre 7
**
****************************************************************
****************************************************************/
public static void main(String[] args) throws OWLOntologyCreationException, OWLOntologyStorageException {
// Section 2.1. Intersection d’objets
if (true) objectIntersectionOf();
// Section 2.2. Union d’objets
if (false) objectUnionOf();
// Section 2.3 Complément d’objets
if (false) objectComplementOf();
// Section 2.4 Intersection et sous-classes d’objets
if (false) objectIntersectionOfSubClassOf();
// Section 2.5 Assertion de classes en conjonction avec le complément d’objets
if (false) objectComplementOfClassAssertion();
// Section 3.1 Restriction existentielle sur la propriété d’objets
if (false) objectSomeValuesFrom();
// Section 3.2 Restriction universelle sur la propriété d’objets
if (false) objectAllValuesFrom();
// Section 3.3. Principe de fermeture
if (false) objectIntersectionOfObjectAllValuesFromObjectSomeValuesFrom();
// Section 3.4 Restriction de la valeur associée à un objet
if (false) objectHasValue();
// Section 3.5 Restriction sur soi-même
if (false) objectHasSelf();
// Section 4. Énumération d’individus
if (false) objectMaxCardinality();
// Section 5.1 Cardinalité maximale
if (false) objectMinCardinality();
// Section 5.2 Cardinalité minimale
if (false) objectExactCardinalityCas1();
// Section 5.3 Cardinalité exacte - Cas 1
if (false) objectExactCardinalityCas2();
// Section 5.3 Cardinalité exacte - Cas 2
if (false) objectOneOf();
// Section 6.1 Propriété inverse
if (false) inverseObjectProperties();
// Section 6.2 Inverse de
if (false) objectInverseOf();
// Section 6.3 Réciprocité et symétrie
if (false) symmetricObjectProperty();
// Section 6.4 Non réciproque, directionnel, antisymétrique
if (false) aSymmetricObjectProperty();
// Section 6.5 Disjonction de propriétés
if (false) disjointObjectProperties();
// Section 6.6 Propriété réflexive
if (false) reflexiveObjectProperty();
// Section 6.7 Propriété antiréflexive
if (false) irreflexiveObjectProperty();
// Section 6.8 Propriété fonctionnelle
if (false) functionalObjectProperty();
// Section 6.9 Propriété de fonctionnalité inverse
if (false) inverseFunctionalObjectProperty();
// Section 6.10 Transitivité de propriété
if (false) transitiveObjectProperty();
// Section 7. Enchaînement de propriétés
if (false) objectPropertyChain();
// Section 8. Association par clé
if (false) hasKey();
}
/****************************************************************
****************************************************************
**
** Section 2.1. Intersection d’objets
**
****************************************************************
****************************************************************/
public static void objectIntersectionOf() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLClass woman = factory.getOWLClass(IRI.create(ontologyIRI + "#Woman"));
OWLClass parent = factory.getOWLClass(IRI.create(ontologyIRI + "#Parent"));
OWLClass mother = factory.getOWLClass(IRI.create(ontologyIRI + "#Mother"));
OWLObjectIntersectionOf womanParent = factory.getOWLObjectIntersectionOf(woman, parent);
OWLEquivalentClassesAxiom axiom = factory.getOWLEquivalentClassesAxiom(mother, womanParent);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 2.2. Union d’objets
**
****************************************************************
****************************************************************/
public static void objectUnionOf() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLClass father = factory.getOWLClass(IRI.create(ontologyIRI + "#Father"));
OWLClass parent = factory.getOWLClass(IRI.create(ontologyIRI + "#Parent"));
OWLClass mother = factory.getOWLClass(IRI.create(ontologyIRI + "#Mother"));
OWLObjectUnionOf fatherOrMother = factory.getOWLObjectUnionOf(father, mother);
OWLEquivalentClassesAxiom axiom = factory.getOWLEquivalentClassesAxiom(parent, fatherOrMother);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 2.3 Complément d’objets
**
****************************************************************
****************************************************************/
public static void objectComplementOf() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLClass person = factory.getOWLClass(IRI.create(ontologyIRI + "#Person"));
OWLClass parent = factory.getOWLClass(IRI.create(ontologyIRI + "#Parent"));
OWLClass childlessPerson = factory.getOWLClass(IRI.create(ontologyIRI + "#ChildlessPerson"));
OWLObjectComplementOf notParent = factory.getOWLObjectComplementOf(parent);
OWLObjectIntersectionOf personNotParent = factory.getOWLObjectIntersectionOf(person, notParent);
OWLEquivalentClassesAxiom axiom = factory.getOWLEquivalentClassesAxiom(childlessPerson, personNotParent);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 2.4 Intersection et sous-classes d’objets
**
****************************************************************
****************************************************************/
public static void objectIntersectionOfSubClassOf() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLClass man = factory.getOWLClass(IRI.create(ontologyIRI + "#Man"));
OWLClass parent = factory.getOWLClass(IRI.create(ontologyIRI + "#Parent"));
OWLClass grandfather = factory.getOWLClass(IRI.create(ontologyIRI + "#Grandfather"));
OWLSubClassOfAxiom axiom = factory.getOWLSubClassOfAxiom(grandfather, factory.getOWLObjectIntersectionOf(man, parent));
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 2.5 Assertion de classes en conjonction avec le complément d’objets
**
****************************************************************
****************************************************************/
public static void objectComplementOfClassAssertion() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLIndividual jack = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#Jack"));
OWLClass person = factory.getOWLClass(IRI.create(ontologyIRI + "#Person"));
OWLClass parent = factory.getOWLClass(IRI.create(ontologyIRI + "#Parent"));
OWLClassAssertionAxiom axiom = factory.getOWLClassAssertionAxiom(factory.getOWLObjectIntersectionOf(person, factory.getOWLObjectComplementOf(parent)), jack);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 3.1 Restriction existentielle sur la propriété d’objets
**
****************************************************************
****************************************************************/
public static void objectSomeValuesFrom() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty hasChild = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasChild"));
OWLClass person = factory.getOWLClass(IRI.create(ontologyIRI + "#Person"));
OWLClass parent = factory.getOWLClass(IRI.create(ontologyIRI + "#Parent"));
OWLObjectSomeValuesFrom somePerson = factory.getOWLObjectSomeValuesFrom(hasChild, person);
OWLEquivalentClassesAxiom axiom = factory.getOWLEquivalentClassesAxiom(parent, somePerson);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 3.2 Restriction universelle sur la propriété d’objets
**
****************************************************************
****************************************************************/
public static void objectAllValuesFrom() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty hasChild = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasChild"));
OWLClass happyParent = factory.getOWLClass(IRI.create(ontologyIRI + "#HappyParent"));
OWLClass happyChildren = factory.getOWLClass(IRI.create(ontologyIRI + "#HappyChildren"));
OWLObjectAllValuesFrom allChildHappyChildren = factory.getOWLObjectAllValuesFrom(hasChild, happyChildren);
OWLAxiom axiom = factory.getOWLEquivalentClassesAxiom(happyParent, allChildHappyChildren);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
JavawsHelper.printFunctionalOWL(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 3.3. Principe de fermeture
**
****************************************************************
****************************************************************/
public static void objectIntersectionOfObjectAllValuesFromObjectSomeValuesFrom() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty hasChild = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasChild"));
OWLClass happyParent = factory.getOWLClass(IRI.create(ontologyIRI + "#HappyParent"));
OWLClass happyChildren = factory.getOWLClass(IRI.create(ontologyIRI + "#HappyChildren"));
OWLObjectAllValuesFrom allHasChild = factory.getOWLObjectAllValuesFrom(hasChild, happyChildren);
OWLObjectSomeValuesFrom someHasChild = factory.getOWLObjectSomeValuesFrom(hasChild, happyChildren);
OWLObjectIntersectionOf allANDSomeHasChild = factory.getOWLObjectIntersectionOf(allHasChild,someHasChild);
OWLAxiom axiom = factory.getOWLEquivalentClassesAxiom(happyParent, allANDSomeHasChild);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
JavawsHelper.printFunctionalOWL(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 3.4 Restriction de la valeur associée à un objet
**
****************************************************************
****************************************************************/
public static void objectHasValue() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty hasParent = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasParent"));
OWLClass johnsChildren = factory.getOWLClass(IRI.create(ontologyIRI + "#johnChildren"));
OWLIndividual john = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#John"));
OWLObjectHasValue hasValueJohn = factory.getOWLObjectHasValue(hasParent, john);
OWLAxiom axiom = factory.getOWLEquivalentClassesAxiom(johnsChildren, hasValueJohn);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 3.5 Restriction sur soi-même
**
****************************************************************
****************************************************************/
public static void objectHasSelf() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty loves = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#loves"));
OWLClass narcisticPerson = factory.getOWLClass(IRI.create(ontologyIRI + "#NarcisticPerson"));
OWLObjectHasSelf hasSelfLoves = factory.getOWLObjectHasSelf(loves);
OWLAxiom axiom = factory.getOWLEquivalentClassesAxiom(narcisticPerson, hasSelfLoves);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 4. Énumération d’individus
**
****************************************************************
****************************************************************/
public static void objectOneOf() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLClass myBirthdayGuests = factory.getOWLClass(IRI.create(ontologyIRI + "#MyBirthdayGuests"));
OWLIndividual john = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#John"));
OWLIndividual bill = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#Bill"));
OWLIndividual mary = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#Mary"));
OWLObjectOneOf oneOfJohnBillMary = factory.getOWLObjectOneOf(john, bill, mary);
OWLAxiom axiom = factory.getOWLEquivalentClassesAxiom(myBirthdayGuests, oneOfJohnBillMary);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 5.1 Cardinalité maximale
**
****************************************************************
****************************************************************/
public static void objectMaxCardinality() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty hasChild = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasChild"));
OWLClass person = factory.getOWLClass(IRI.create(ontologyIRI + "#Person"));
OWLIndividual john = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#John"));
OWLObjectMaxCardinality maxCardPerson = factory.getOWLObjectMaxCardinality(4, hasChild, person);
OWLAxiom axiom = factory.getOWLClassAssertionAxiom(maxCardPerson, john);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 5.2 Cardinalité minimale
**
****************************************************************
****************************************************************/
public static void objectMinCardinality() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty hasChild = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasChild"));
OWLClass person = factory.getOWLClass(IRI.create(ontologyIRI + "#Person"));
OWLIndividual john = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#John"));
OWLObjectMinCardinality minCardPerson = factory.getOWLObjectMinCardinality(2, hasChild, person);
OWLClassAssertionAxiom axiom = factory.getOWLClassAssertionAxiom(minCardPerson, john);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 5.3 Cardinalité exacte - Cas 1
**
****************************************************************
****************************************************************/
public static void objectExactCardinalityCas1() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty hasChild = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasChild"));
OWLClass person = factory.getOWLClass(IRI.create(ontologyIRI + "#Person"));
OWLIndividual john = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#John"));
OWLObjectExactCardinality exactCardPerson = factory.getOWLObjectExactCardinality(3, hasChild, person);
OWLClassAssertionAxiom axiom = factory.getOWLClassAssertionAxiom(exactCardPerson, john);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 5.3 Cardinalité exacte - Cas 2
**
****************************************************************
****************************************************************/
public static void objectExactCardinalityCas2() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty hasChild = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasChild "));
OWLIndividual john = factory.getOWLNamedIndividual(IRI.create(ontologyIRI + "#John"));
OWLObjectExactCardinality exactCardHasChild = factory.getOWLObjectExactCardinality(5, hasChild);
OWLAxiom axiom = factory.getOWLClassAssertionAxiom(exactCardHasChild, john);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 6.1 Propriété inverse
**
****************************************************************
****************************************************************/
public static void inverseObjectProperties() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty hasChild = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasChild"));
OWLObjectProperty hasParent = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasParent"));
OWLInverseObjectPropertiesAxiom axiom = factory.getOWLInverseObjectPropertiesAxiom(hasParent, hasChild);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 6.2 Inverse de
**
****************************************************************
****************************************************************/
public static void objectInverseOf() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty hasChild = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasChild"));
OWLClass orphan = factory.getOWLClass(IRI.create(ontologyIRI + "#Orphan"));
OWLClass dead = factory.getOWLClass(IRI.create(ontologyIRI + "#Dead"));
OWLObjectInverseOf inverseHasChild = factory.getOWLObjectInverseOf(hasChild);
OWLObjectAllValuesFrom allValuesDead = factory.getOWLObjectAllValuesFrom(inverseHasChild, dead);
OWLAxiom axiom = factory.getOWLEquivalentClassesAxiom(orphan, allValuesDead);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 6.3 Réciprocité et symétrie
**
****************************************************************
****************************************************************/
public static void symmetricObjectProperty() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty hasSpouse = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasSpouse"));
OWLSymmetricObjectPropertyAxiom axiom = factory.getOWLSymmetricObjectPropertyAxiom(hasSpouse);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 6.4 Non réciproque, directionnel, antisymétrique
**
****************************************************************
****************************************************************/
public static void aSymmetricObjectProperty() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty hasChild = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasChild"));
OWLAsymmetricObjectPropertyAxiom axiom = factory.getOWLAsymmetricObjectPropertyAxiom(hasChild);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 6.5 Disjonction de propriétés
**
****************************************************************
****************************************************************/
public static void disjointObjectProperties() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty hasParent = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasParent"));
OWLObjectProperty hasSpouse = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasSpouse"));
OWLDisjointObjectPropertiesAxiom axiom = factory.getOWLDisjointObjectPropertiesAxiom(hasParent, hasSpouse);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 6.6 Propriété réflexive
**
****************************************************************
****************************************************************/
public static void reflexiveObjectProperty() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty knows = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#knows"));
OWLReflexiveObjectPropertyAxiom axiom = factory.getOWLReflexiveObjectPropertyAxiom(knows);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 6.7 Propriété antiréflexive
**
****************************************************************
****************************************************************/
public static void irreflexiveObjectProperty() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty parentOf = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#parentOf"));
OWLIrreflexiveObjectPropertyAxiom axiom = factory.getOWLIrreflexiveObjectPropertyAxiom(parentOf);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 6.8 Propriété fonctionnelle
**
****************************************************************
****************************************************************/
public static void functionalObjectProperty() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty hasHusband = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasHusband"));
OWLFunctionalObjectPropertyAxiom axiom = factory.getOWLFunctionalObjectPropertyAxiom(hasHusband);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 6.9 Propriété de fonctionnalité inverse
**
****************************************************************
****************************************************************/
public static void inverseFunctionalObjectProperty() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty hasHusband = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasHusband"));
OWLInverseFunctionalObjectPropertyAxiom axiom = factory.getOWLInverseFunctionalObjectPropertyAxiom(hasHusband);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 6.10 Transitivité de propriété
**
****************************************************************
****************************************************************/
public static void transitiveObjectProperty() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty hasAncestor = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasAncestor"));
OWLTransitiveObjectPropertyAxiom axiom = factory.getOWLTransitiveObjectPropertyAxiom(hasAncestor);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 7. Enchaînement de propriétés
**
****************************************************************
****************************************************************/
public static void objectPropertyChain() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLObjectProperty hasParent = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasParent"));
OWLObjectProperty hasGrandparent = factory.getOWLObjectProperty(IRI.create(ontologyIRI + "#hasGrandparent"));
List hasGrandparentChain=new ArrayList();
hasGrandparentChain.add(hasParent);
hasGrandparentChain.add(hasParent);
OWLSubPropertyChainOfAxiom axiom = factory.getOWLSubPropertyChainOfAxiom(hasGrandparentChain, hasGrandparent);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
/****************************************************************
****************************************************************
**
** Section 8. Association par clé
**
****************************************************************
****************************************************************/
public static void hasKey() throws OWLOntologyCreationException, OWLOntologyStorageException {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI ontologyIRI = IRI.create("http://java-ws.com/ontologies/families");
OWLDataFactory factory = manager.getOWLDataFactory();
OWLOntology ontology = manager.createOntology(ontologyIRI);
OWLClass person = factory.getOWLClass(IRI.create(ontologyIRI + "#Person"));
OWLDataPropertyExpression hasSSN = factory.getOWLDataProperty(IRI.create(ontologyIRI + "#hasSSN"));
OWLHasKeyAxiom axiom = factory.getOWLHasKeyAxiom(person, hasSSN);
manager.addAxiom(ontology, axiom);
JavawsHelper.printTurtle(manager, ontology);
}
}