rationals.transformations.Mix Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.semanticweb.hermit Show documentation
Show all versions of org.semanticweb.hermit Show documentation
HermiT is reasoner for ontologies written using the Web
Ontology Language (OWL). Given an OWL file, HermiT can determine whether or
not the ontology is consistent, identify subsumption relationships between
classes, and much more.
This is the maven build of HermiT and is designed for people who wish to use
HermiT from within the OWL API. It is now versioned in the main HermiT
version repository, although not officially supported by the HermiT
developers.
The version number of this package is a composite of the HermiT version and
an value representing releases of this packaged version. So, 1.3.7.1 is the
first release of the mavenized version of HermiT based on the 1.3.7 release
of HermiT.
This package includes the Jautomata library
(http://jautomata.sourceforge.net/), and builds with it directly. This
library appears to be no longer under active development, and so a "fork"
seems appropriate. No development is intended or anticipated on this code
base.
package rationals.transformations;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import rationals.Automaton;
import rationals.DefaultSynchronization;
import rationals.NoSuchStateException;
import rationals.State;
import rationals.Synchronization;
import rationals.Transition;
/**
* This class implements the mix - ie: synchronization product - operator
* between two automatas.
*
* - C = A mix B
* - S(C) = { (a,b) | a in S(A) and b in S(B) }
* - S0(C) = (S0(A),SO(B))
* - T(C) = { (a,b) | a in T(A) and b in T(B) }
* - D(C) = { ((s1a,s1b),a,(s2a,s2b)) | exists (s1a,a,s2a) in D(A) and exists
* (s1b,a,s2b) in D(b) } U { ((s1a,s1b),a,(s1a,s2b)) | a not in S(A) and exists
* (s1b,a,s2b) in D(b) } U { ((s1a,s1b),a,(s2a,s1b)) | a not in S(B) and exists
* (s1a,a,s2a) in D(a) }
*
*
* @author Arnaud Bailly
* @version 22032002
*/
public class Mix implements BinaryTransformation {
private Synchronization synchronization;
/**
* Compute mix of two automata using default synchronization scheme which is
* the equality of labels.
*
* @see rationals.DefaultSynchronization
* @see rationals.Synchronization
*/
public Mix() {
this.synchronization = new DefaultSynchronization();
}
/**
* Compute mix of two automata using given synchronization scheme.
*
* @param synch
* a Synchronization object. Must not be null.
*/
public Mix(Synchronization synch) {
this.synchronization = synch;
}
/*
* (non-Javadoc)
* @see rationals.transformations.BinaryTransformation#transform(rationals.Automaton, rationals.Automaton)
*/
public Automaton transform(Automaton a, Automaton b) {
Automaton ret = new Automaton();
Set alph = synchronization.synchronizable(a.alphabet(), b.alphabet());
/* check alphabets */
Map amap = new HashMap();
Map bmap = new HashMap();
List /* < StatesCouple > */todo = new ArrayList();
Set /* < StatesCouple > */done = new HashSet();
Set as = TransformationsToolBox.epsilonClosure(a.initials(), a);
Set bs = TransformationsToolBox.epsilonClosure(b.initials(), b);
State from = ret.addState(true, TransformationsToolBox
.containsATerminalState(as)
&& TransformationsToolBox.containsATerminalState(bs));
StatesCouple sc = new StatesCouple(as, bs);
amap.put(sc, from);
todo.add(sc);
do {
StatesCouple couple = (StatesCouple) todo.remove(0);
from = (State) amap.get(couple);
if (done.contains(couple))
continue;
done.add(couple);
/* get transition sets */
Map tam = TransformationsToolBox.mapAlphabet(a.delta(couple.sa), a);
Map tbm = TransformationsToolBox.mapAlphabet(b.delta(couple.sb), b);
/* create label map for synchronized trans */
Map /* < Object, StatesCouple > */tcm = new HashMap();
/* unsynchronizable transitions in A */
for (Iterator i = tam.entrySet().iterator(); i.hasNext();) {
Map.Entry me = (Map.Entry) i.next();
Object l = me.getKey();
as = (Set) me.getValue();
if (!alph.contains(l)) {
Set asc = TransformationsToolBox.epsilonClosure(as, a);
tcm.put(l, sc = new StatesCouple(asc, couple.sb));
State to = (State) amap.get(sc);
if (to == null) {
to = ret.addState(false, TransformationsToolBox
.containsATerminalState(sc.sa)
&& TransformationsToolBox
.containsATerminalState(sc.sb));
amap.put(sc, to);
}
todo.add(sc);
i.remove();
}
}
/* unsynchronizable transition(s) in B */
for (Iterator i = tbm.entrySet().iterator(); i.hasNext();) {
Map.Entry me = (Map.Entry) i.next();
Object l = me.getKey();
bs = (Set) me.getValue();
if (!alph.contains(l)) {
Set bsc = TransformationsToolBox.epsilonClosure(bs, b);
tcm.put(l, sc = new StatesCouple(couple.sa, bsc));
State to = (State) amap.get(sc);
if (to == null) {
to = ret.addState(false, TransformationsToolBox
.containsATerminalState(sc.sa)
&& TransformationsToolBox
.containsATerminalState(sc.sb));
amap.put(sc, to);
}
todo.add(sc);
i.remove();
}
}
/*
* there remains in tam and tbm only possibly synchronizable
* transitions
*/
for (Iterator i = tam.entrySet().iterator(); i.hasNext();) {
Map.Entry me = (Map.Entry) i.next();
Object l = me.getKey();
as = (Set) me.getValue();
for (Iterator j = tbm.entrySet().iterator(); j.hasNext();) {
Map.Entry mbe = (Map.Entry) j.next();
Object k = mbe.getKey();
bs = (Set) mbe.getValue();
Object sy = synchronization.synchronize(l, k);
if (sy != null) {
Set asc = TransformationsToolBox.epsilonClosure(as, a);
Set bsc = TransformationsToolBox.epsilonClosure(bs, b);
tcm.put(sy, sc = new StatesCouple(asc, bsc));
State to = (State) amap.get(sc);
if (to == null) {
to = ret.addState(false, TransformationsToolBox
.containsATerminalState(sc.sa)
&& TransformationsToolBox
.containsATerminalState(sc.sb));
amap.put(sc, to);
}
todo.add(sc);
}
}
}
/*
*
* create new transitions in return automaton, update maps
*/
for (Iterator i = tcm.entrySet().iterator(); i.hasNext();) {
Map.Entry me = (Map.Entry) i.next();
Object l = me.getKey();
sc = (StatesCouple) me.getValue();
State to = (State) amap.get(sc);
if (to == null) {
to = ret.addState(false, TransformationsToolBox
.containsATerminalState(sc.sa)
&& TransformationsToolBox
.containsATerminalState(sc.sb));
amap.put(sc, to);
}
try {
ret.addTransition(new Transition(from, l, to));
} catch (NoSuchStateException e) {
}
}
} while (!todo.isEmpty());
return ret;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy