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 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.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 {

    /**
     * @param s
     *            s
     * @return true if there is a terminal state in the input
     */
    public static boolean containsATerminalState(Set s) {
        Iterator i = s.iterator();
        while (i.hasNext()) {
            State e = i.next();
            if (e.isTerminal())
                return true;
        }
        return false;
    }

    /**
     * @param s
     *            s
     * @return true if there is an initial state in the input
     */
    public static boolean containsAnInitialState(Set s) {
        Iterator i = s.iterator();
        while (i.hasNext()) {
            State e = i.next();
            if (e.isInitial())
                return true;
        }
        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 = it.next();
                Iterator it2 = a.delta(st).iterator();
                while (it2.hasNext()) {
                    Transition tr = 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.
     * @param a
     *            a
     * @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 = tas.remove(0);
            Object l = tr.label();
            if (l == null)
                continue;
            Set as = am.get(l);
            if (as == null) {
                as = a.getStateFactory().stateSet();
                am.put(l, as);
            }
            as.add(tr.end());
        }
        return am;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy