Commit 92e83042 authored by Chan LE DUC's avatar Chan LE DUC

Upload New File

parent 84b29751
* $Id$
* Copyright (C) Paris8-IUT de Montreuil, 2013-2018
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will b checkForMatchinge useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//import net.sourceforge.sizeof.SizeOf;
import java.util.HashMap;
import java.util.Scanner;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Vector;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.ListIterator;
import java.util.Stack;
import java.util.Iterator;
import java.util.Arrays;
import java.util.Collections;
//import java.util.function.Predicate;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.util.DLExpressivityChecker;
import org.semanticweb.owlapi.util.DLExpressivityChecker.Construct;
import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.AxiomType;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLProperty;
import org.semanticweb.owlapi.model.OWLClassAxiom;
import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLDataAllValuesFrom;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLDataHasValue;
import org.semanticweb.owlapi.model.OWLDataMaxCardinality;
import org.semanticweb.owlapi.model.OWLDataMinCardinality;
import org.semanticweb.owlapi.model.OWLDataPropertyExpression;
import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom;
import org.semanticweb.owlapi.model.OWLDataRange;
import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLDatatype;
import org.semanticweb.owlapi.model.OWLLiteral;
import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom;
import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom;
import org.semanticweb.owlapi.model.OWLObjectComplementOf;
import org.semanticweb.owlapi.model.OWLObjectHasValue;
import org.semanticweb.owlapi.model.OWLObjectIntersectionOf;
import org.semanticweb.owlapi.model.OWLObjectMaxCardinality;
import org.semanticweb.owlapi.model.OWLObjectMinCardinality;
import org.semanticweb.owlapi.model.OWLObjectOneOf;
import org.semanticweb.owlapi.model.OWLObjectInverseOf;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLPropertyExpression;
import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLObjectPropertyDomainAxiom;
import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;
import org.semanticweb.owlapi.model.OWLObjectPropertyRangeAxiom;
import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom;
import org.semanticweb.owlapi.model.OWLObjectUnionOf;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;
import org.semanticweb.owlapi.model.OWLSubDataPropertyOfAxiom;
import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom;
import org.semanticweb.owlapi.model.SWRLPredicate;
import org.semanticweb.owlapi.model.OWLException;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.ClassExpressionType;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLPropertyExpression;
import org.semanticweb.owlapi.model.OWLQuantifiedRestriction;
import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom;
import org.semanticweb.owlapi.manchestersyntax.renderer.ManchesterOWLSyntaxOWLObjectRendererImpl;
* This class contains all those related to individuals and assertions. So it represents a graph
* An object of this class is created when a new ABox is needed, e.g. entailment of link keys, axioms, assertions
* For SHIQ, an ABox may evolve because of inverse roles and number restrictions
* 1) First, it saturates ABox with assertions to find a model of ABox => S_0(sat, unsat)
* A model is composed of saturated, clash-free star-types and each individual d occurs once
* (a star-type can contain several individuals)
* 2) Pick a model (s_1,...,s_n) of ABox and develop inf. layers. This can leads to change (s_1,...,s_n) and thus S_0(sat, unsat).
A model of ABox which cannot lead to a model of onto will be unsat and rejected
* 3) while no model of onto. is found, pick a "new" model from ABox and and develop inf. layers.
* It would be needed to maintain sat, unsat startypes, and sat, unsat Abox models
* It should propose a method nextModel
public class ABox implements Serializable
private static final long serialVersionUID = 1L;
private Set<OWLIndividual> newInds;
private Set<OWLIndividual> initInds;
private SetMultimap<OWLIndividual, OWLIndividual> sameIndAssers;//for both initInds and newinds
private SetMultimap<OWLIndividual, OWLIndividual> diffIndAssers;
//we need this own structure because there may be new individuals
private SetMultimap<OWLIndividual, OWLClassExpression> conceptsByInd; //for both initInds and newinds
private SetMultimap<OWLIndividual, Map<OWLObjectPropertyExpression, OWLIndividual>> conceptObjeAssertsBySource;
private SetMultimap<OWLIndividual, Map<OWLObjectPropertyExpression, OWLIndividual>> conceptObjeAssertsByTarget;
private SetMultimap<OWLIndividual, Map<OWLDataPropertyExpression, OWLLiteral>> conceptDataAssertsBySource;
private SetMultimap<OWLLiteral, Map<OWLDataPropertyExpression, OWLIndividual>> conceptDataAssertsByTarget;
private Set<SharedStartype> sats;
private Set<SharedStartype> unsats;
private Set<Set<SharedStartype>> processedModels;
private Set<Set<SharedStartype>> satModels;
//private SetMultimap<Triple, SharedStartype> startypesByPredTriple; //get startypes from a pred triple
private SetMultimap<SharedStartype, Triple> startypesBySuccTriple; //get startypes from a succ triple
public ABox( )
initInds = new HashSet<OWLIndividual>();
newInds = new HashSet<OWLIndividual>();
conceptsByInd = HashMultimap.create();
conceptObjeAssertsBySource = HashMultimap.create();
conceptObjeAssertsByTarget = HashMultimap.create();
conceptDataAssertsBySource = HashMultimap.create();
conceptDataAssertsByTarget = HashMultimap.create();
sameIndAssers = HashMultimap.create();
diffIndAssers = HashMultimap.create();
sats = new HashSet<SharedStartype>();
unsats = new HashSet<SharedStartype>();
processedModels = new HashSet<Set<SharedStartype>>();
satModels = new HashSet<Set<SharedStartype>>();
startypesBySuccTriple = HashMultimap.create();
// Get a next model over ABox
public Set<SharedStartype> nextModel(ReasoningData data)
return null;
// Generate sat, unsat startypes from initial individuals and form a Abox model
public void saturate(ReasoningData data)
* Merge x,y if x=y
* This leads to update :
* 1) L(x) <- L(x) + L(y)
* 2) L(x,z) <- L(y,z)
* 3) L(z,x) <- L(z,y)
public void merge2Inds(OWLIndividual d1, OWLIndividual d2)
// 1)
// 2)
// 3)
* Two possible clashes : A, -A
* x <> y : for each transitive closure x+, if x1, x2 belong to x+ and x1 <> x2 then there is a clash
public boolean isClash()
// A, -A
// check the classes of all individuals(
for (OWLIndividual ind : conceptsByInd.keySet()) {
List<OWLClassExpression> classes = new ArrayList<OWLClassExpression>(conceptsByInd.get(ind));
// pos will be the position of the first class
int pos = 0;
while (pos < classes.size() - 1) {
OWLClassExpression leftClass = classes.get(pos);
// i will be the position of the second class
for (int i = pos + 1; i < classes.size(); i++) {
OWLClassExpression rightClass = classes.get(i).getComplementNNF();
// check if the complement of one class is equall to the other (clash)
if (leftClass.equals(rightClass))
return true;
// x <> y with x belongs to y transitive closure
// store all transitive closures
Set<Set<OWLIndividual>> closures = new HashSet<Set<OWLIndividual>>();
boolean found;
// check all individuals
for (OWLIndividual i : initInds) {
found = false;
// see if some existing closure contains the current individual
for (Set<OWLIndividual> closure : closures)
if (closure.contains(i)) {
// if yes, no need to re process it
found = true;
// if not, we need to process and add a new transitive closure
if (!found)
// once all closures are processed, we can look for the clash
// if both individuals of an inequivalence are in the same closure, there is a
// clash
for (OWLIndividual i1 : diffIndAssers.keySet()) {
for (OWLIndividual i2 : diffIndAssers.get(i1)) {
for (Set<OWLIndividual> closure : closures)
if (closure.contains(i1) && closure.contains(i2))
return true;
return false;
// returns the transitive closure of an individual
public Set<OWLIndividual> getTransitiveClosure(OWLIndividual individual)
Set<OWLIndividual> closure = new HashSet<OWLIndividual>();
// the list of individuals whose equivalents need to be processed
// at initialization, contains only the argument
List<OWLIndividual> toProcess = new ArrayList<OWLIndividual>();
while (!toProcess.isEmpty()) {
OWLIndividual ind = toProcess.remove(0);
// the individual to process may already be in the closure
// do nothing in such case
if (!closure.contains(ind)) {
// once it's been added, we check for its equivalent using the adapted MultiMap
Set<OWLIndividual> equivalents = sameIndAssers.get(ind);
if (!equivalents.isEmpty())
// but the individual is not necessarily the key of the map
// then the values must be checked as well
for (Entry<OWLIndividual, OWLIndividual> entry : sameIndAssers.entries())
if (entry.getValue().equals(ind))
return closure;
public void addConceptAssertions( ) {}
public void addIndividuals( ) {}
public void addObjectPropertyAssertions( ) {}
public void addDataPropertyAssertions( ) {}
public SetMultimap<OWLIndividual, OWLClassExpression> getConceptsByInd()
return conceptsByInd;
public SetMultimap<OWLIndividual, Map<OWLObjectPropertyExpression,OWLIndividual>> getConceptObjeAssertBySource()
return conceptObjeAssertsBySource;
public SetMultimap<OWLIndividual, Map<OWLObjectPropertyExpression,OWLIndividual>> getConceptObjeAssertByTarget()
return conceptObjeAssertsByTarget;
public SetMultimap<OWLIndividual, Map<OWLDataPropertyExpression,OWLLiteral>> getConceptDataAssertBySource()
return conceptDataAssertsBySource;
public SetMultimap<OWLLiteral, Map<OWLDataPropertyExpression,OWLIndividual>> getConceptDataAssertByTarget()
return conceptDataAssertsByTarget;
public Set<OWLIndividual> getInitInds()
return initInds;
public Set<OWLIndividual> getInds()
return Sets.union(initInds, newInds);
public Set<OWLIndividual> getNewInds()
return newInds;
public SetMultimap<OWLIndividual, OWLIndividual> getSameIndAssers()
return sameIndAssers;
public SetMultimap<OWLIndividual, OWLIndividual> getDiffIndAssers()
return diffIndAssers;
public void setNewInds(Set<OWLIndividual> is)
newInds = is;
public void setInitInds(Set<OWLIndividual> is)
initInds = is;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment