All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rationals.transformations.Mix Maven / Gradle / Ivy

Go to download

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 a value representing the OWLAPI release it is compatible with. Note that the group id for the upstream HermiT is com.hermit-reasoner, while this fork is released under net.sourceforge.owlapi. This fork exists to allow HermiT users to use newer OWLAPI versions than the ones supported by the original HermiT codebase. 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.

The newest version!
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.Map.Entry;
import java.util.Set;

import rationals.Automaton;
import rationals.DefaultSynchronization;
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 final 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; } @Override 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<>(); List todo = new ArrayList<>(); Set 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 = todo.remove(0); from = 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 tcm = new HashMap<>(); /* unsynchronizable transitions in A */ for (Iterator>> i = tam.entrySet().iterator(); i.hasNext();) { Map.Entry> me = i.next(); Object l = me.getKey(); as = me.getValue(); if (!alph.contains(l)) { Set asc = TransformationsToolBox.epsilonClosure(as, a); tcm.put(l, sc = new StatesCouple(asc, couple.sb)); State to = 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 = i.next(); Object l = me.getKey(); bs = me.getValue(); if (!alph.contains(l)) { Set bsc = TransformationsToolBox.epsilonClosure(bs, b); tcm.put(l, sc = new StatesCouple(couple.sa, bsc)); State to = 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 = i.next(); Object l = me.getKey(); as = me.getValue(); for (Iterator>> j = tbm.entrySet().iterator(); j.hasNext();) { Map.Entry> mbe = j.next(); Object k = mbe.getKey(); bs = 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 = 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();) { Entry me = i.next(); Object l = me.getKey(); sc = me.getValue(); State to = amap.get(sc); if (to == null) { to = ret.addState(false, TransformationsToolBox .containsATerminalState(sc.sa) && TransformationsToolBox .containsATerminalState(sc.sb)); amap.put(sc, to); } ret.addTransition(new Transition(from, l, to),null); } } while (!todo.isEmpty()); return ret; } }