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

rationals.transformations.TransformationsToolBox 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 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.

There is a newer version: 1.3.8.4
Show newest version
package rationals.transformations;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import rationals.Automaton;
import rationals.State;
import rationals.Transition;

/**
 * A set of utility methods used in transformations of automaton.
 * 
 * @author nono
 * @version $Id: TransformationsToolBox.java 10 2007-05-30 17:25:00Z oqube $
 */
public class TransformationsToolBox {

  public static boolean containsATerminalState(Set s) {
    Iterator i = s.iterator() ;
    while(i.hasNext()) {
      try {
        State e = (State) i.next() ;
        if (e.isTerminal()) return true ;
      } catch(ClassCastException x) {}
    }
    return false ;
  } 

  public static boolean containsAnInitialState(Set s) {
    Iterator i = s.iterator() ;
    while(i.hasNext()) {
      try {
        State e = (State) i.next() ;
        if (e.isInitial()) return true ;
      } catch(ClassCastException x) {}
    }
    return false ;
  } 
  
  /**
   * Compute the set of states that are reachable ina given automanton
   * from a set of states using epsilon moves.
   * An epsilon transition is a transition which is labelled null.
   * 
   * @param s the set of starting states 
   * @param a the automaton 
   * @return a - possibly empty - set of states reachable from s through
   * epsilon transitions. 
   */
  public static Set epsilonClosure(Set s, Automaton a) {
      Set exp = a.getStateFactory().stateSet();
      exp.addAll(s); /* set of states to visit */
      Set view = a.getStateFactory().stateSet(); /* set of states visited */
      Set arr = a.getStateFactory().stateSet(); /* the set of arrival states */
      arr.addAll(s);
      do {
          Set ns = a.getStateFactory().stateSet();
          ns.addAll(exp); /* arrival states */
          Iterator it = ns.iterator();
          while (it.hasNext()) {
              State st = (State) it.next();
              Iterator it2 = a.delta(st).iterator();
              while (it2.hasNext()) {
                  Transition tr = (Transition) it2.next();
                  if (tr.label() == null && !view.contains(tr.end())
                          && !tr.end().equals(st)) {
                      /* compute closure of epsilon transitions */
                      exp.add(tr.end());
                      arr.add(tr.end());
                  }
              }
              exp.remove(st);
              view.add(st);
          }
      } while (!exp.isEmpty());
      return arr;
  }

  
  /**
   * Compute a map from letters to set of states given 
   * a set of transitions.
   * This method computes the arrival set of states for each letter
   * occuring in a given set of transitions. epsilon transitions 
   * are not taken into account.
   *  
   * @param ts a Set of Transition objects.
   * @return a Map from Object - transition labels - to Set of State objects. 
   */
  public static Map mapAlphabet(Set ts,Automaton a) {
      Map am = new HashMap();
      List tas =new ArrayList(ts);
      /* compute set of states for each letter */
      while (!tas.isEmpty()) {
          Transition tr = (Transition) tas.remove(0);
          Object l = tr.label();
          if (l == null)
              continue;
          Set as = (Set) am.get(l);
          if (as == null) {
              as = a.getStateFactory().stateSet();
              am.put(l, as);
          }
          as.add(tr.end());
      }
      return am;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy