Class RegexAutomaton

  • All Implemented Interfaces:
    it.unive.lisa.util.datastructures.automaton.AutomataFactory<RegexAutomaton,​it.unive.lisa.util.datastructures.regex.RegularExpression>

    public class RegexAutomaton
    extends it.unive.lisa.util.datastructures.automaton.Automaton<RegexAutomaton,​it.unive.lisa.util.datastructures.regex.RegularExpression>
    A class that describes an generic automaton(dfa, nfa, epsilon nfa) using an alphabet of strings, extended with a special symbol for statically unknown ones. Transition symbols are RegularExpressions.
    • Field Summary

      • Fields inherited from class it.unive.lisa.util.datastructures.automaton.Automaton

        deterministic, minimized, states, transitions
    • Constructor Summary

      Constructors 
      Constructor Description
      RegexAutomaton​(java.util.SortedSet<it.unive.lisa.util.datastructures.automaton.State> states, java.util.SortedSet<it.unive.lisa.util.datastructures.automaton.Transition<it.unive.lisa.util.datastructures.regex.RegularExpression>> transitions)
      Builds a new automaton with given states and transitions.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean acceptsTopEventually()
      Yields true if and only if there is at least one transition in this automaton that recognizes a top string.
      RegexAutomaton collapse()
      Yields a new automaton that is built by collapsing this, that is, by merging together subsequent states that are never the root of a branch, the destination of a loop, or that have at least one outgoing transition recognizing the top string.

      this is never modified by this method.
      it.unive.lisa.util.datastructures.regex.RegularExpression concat​(it.unive.lisa.util.datastructures.regex.RegularExpression first, it.unive.lisa.util.datastructures.regex.RegularExpression second)  
      static RegexAutomaton emptyLang()
      Builds a RegexAutomaton recognizing the empty language.
      RegexAutomaton emptyLanguage()  
      static RegexAutomaton emptyStr()
      Builds a RegexAutomaton recognizing the empty string.
      RegexAutomaton emptyString()  
      it.unive.lisa.util.datastructures.regex.RegularExpression epsilon()  
      RegexAutomaton explode()
      Yields a new automaton that is built by exploding this one, that is, by ensuring that each transition recognizes regular expressions of at most one character (excluding the ones recognizing the top string).
      RegexAutomaton from​(java.util.SortedSet<it.unive.lisa.util.datastructures.automaton.State> states, java.util.SortedSet<it.unive.lisa.util.datastructures.automaton.Transition<it.unive.lisa.util.datastructures.regex.RegularExpression>> transitions)  
      RegexAutomaton intersection​(RegexAutomaton other)  
      RegexAutomaton repeat​(long n)
      Yields an automaton that corresponds to the n-time concatenation of this.
      RegexAutomaton replace​(RegexAutomaton toReplace, RegexAutomaton str)
      Yields a new automaton where all occurrences of strings recognized by toReplace are replaced with the automaton str, assuming that toReplace is finite (i.e., no loops nor top-transitions).
      RegexAutomaton singleString​(java.lang.String string)  
      static RegexAutomaton string​(it.unive.lisa.util.datastructures.regex.symbolic.SymbolicString s)
      Builds a RegexAutomaton recognizing the given string.
      static RegexAutomaton string​(java.lang.String string)
      Builds a RegexAutomaton recognizing the given string.
      static RegexAutomaton strings​(java.lang.String... strings)
      Builds a RegexAutomaton recognizing the given strings.
      it.unive.lisa.util.datastructures.regex.RegularExpression symbolToRegex​(it.unive.lisa.util.datastructures.regex.RegularExpression symbol)  
      static RegexAutomaton topString()
      Builds a RegexAutomaton recognizing the top string, that is, with a single transition recognizing TopAtom.
      RegexAutomaton trim()
      Yields a new automaton where trailing and leading whitespaces have been removed from this.
      RegexAutomaton trimLeft()
      Yields a new automaton where leading whitespaces have been removed from this.
      RegexAutomaton trimRight()
      Yields a new automaton where trailing whitespaces have been removed from this.
      RegexAutomaton unknownString()  
      • Methods inherited from class it.unive.lisa.util.datastructures.automaton.Automaton

        acceptsEmptyLanguage, addState, addTransition, addTransition, areMutuallyReachable, commonAlphabet, complement, concat, copy, determinize, epsilonClosure, epsilonClosure, equals, extractLongestString, factors, factorsChangingInitialState, getAllPaths, getAllTransitionsConnecting, getAlphabet, getFinalStates, getIngoingTransitionsFrom, getInitialState, getInitialStates, getLanguage, getNextStates, getNextSymbols, getOutgoingTransitionsFrom, getReadableSymbolsFromState, getReadableSymbolsFromStates, getStateFromPair, getStates, getTransitions, hasCycle, hashCode, hasOnlyOnePath, isContained, isDeterministic, isEqualTo, lenghtOfLongestString, makeAcyclic, maximumPath, minimize, minimumPath, nextStatesNFA, prefix, prettyPrint, recognizesExactlyOneString, removeStates, removeTransitions, removeUnreachableStates, reverse, star, suffix, toRegex, toSingleInitalState, toString, totalize, union, widening
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • RegexAutomaton

        public RegexAutomaton​(java.util.SortedSet<it.unive.lisa.util.datastructures.automaton.State> states,
                              java.util.SortedSet<it.unive.lisa.util.datastructures.automaton.Transition<it.unive.lisa.util.datastructures.regex.RegularExpression>> transitions)
        Builds a new automaton with given states and transitions.
        Parameters:
        states - the set of states of the new automaton
        transitions - the set of the transitions of the new automaton
    • Method Detail

      • topString

        public static RegexAutomaton topString()
        Builds a RegexAutomaton recognizing the top string, that is, with a single transition recognizing TopAtom.
        Returns:
        the automaton
      • string

        public static RegexAutomaton string​(java.lang.String string)
        Builds a RegexAutomaton recognizing the given string.
        Parameters:
        string - the string to recognize
        Returns:
        the automaton
      • string

        public static RegexAutomaton string​(it.unive.lisa.util.datastructures.regex.symbolic.SymbolicString s)
        Builds a RegexAutomaton recognizing the given string.
        Parameters:
        s - the string to recognize
        Returns:
        the automaton
      • strings

        public static RegexAutomaton strings​(java.lang.String... strings)
        Builds a RegexAutomaton recognizing the given strings.
        Parameters:
        strings - the strings to recognize
        Returns:
        the automaton
      • singleString

        public RegexAutomaton singleString​(java.lang.String string)
      • from

        public RegexAutomaton from​(java.util.SortedSet<it.unive.lisa.util.datastructures.automaton.State> states,
                                   java.util.SortedSet<it.unive.lisa.util.datastructures.automaton.Transition<it.unive.lisa.util.datastructures.regex.RegularExpression>> transitions)
      • epsilon

        public it.unive.lisa.util.datastructures.regex.RegularExpression epsilon()
        Specified by:
        epsilon in class it.unive.lisa.util.datastructures.automaton.Automaton<RegexAutomaton,​it.unive.lisa.util.datastructures.regex.RegularExpression>
      • concat

        public it.unive.lisa.util.datastructures.regex.RegularExpression concat​(it.unive.lisa.util.datastructures.regex.RegularExpression first,
                                                                                it.unive.lisa.util.datastructures.regex.RegularExpression second)
        Specified by:
        concat in class it.unive.lisa.util.datastructures.automaton.Automaton<RegexAutomaton,​it.unive.lisa.util.datastructures.regex.RegularExpression>
      • symbolToRegex

        public it.unive.lisa.util.datastructures.regex.RegularExpression symbolToRegex​(it.unive.lisa.util.datastructures.regex.RegularExpression symbol)
        Specified by:
        symbolToRegex in class it.unive.lisa.util.datastructures.automaton.Automaton<RegexAutomaton,​it.unive.lisa.util.datastructures.regex.RegularExpression>
      • acceptsTopEventually

        public boolean acceptsTopEventually()
        Yields true if and only if there is at least one transition in this automaton that recognizes a top string.
        Returns:
        true if that condition holds
      • explode

        public RegexAutomaton explode()
        Yields a new automaton that is built by exploding this one, that is, by ensuring that each transition recognizes regular expressions of at most one character (excluding the ones recognizing the top string).

        This automaton is never modified by this method.
        Returns:
        the exploded automaton
      • intersection

        public RegexAutomaton intersection​(RegexAutomaton other)
        Overrides:
        intersection in class it.unive.lisa.util.datastructures.automaton.Automaton<RegexAutomaton,​it.unive.lisa.util.datastructures.regex.RegularExpression>
      • collapse

        public RegexAutomaton collapse()
        Yields a new automaton that is built by collapsing this, that is, by merging together subsequent states that are never the root of a branch, the destination of a loop, or that have at least one outgoing transition recognizing the top string.

        this is never modified by this method.
        Returns:
        the collapsed automaton
      • replace

        public RegexAutomaton replace​(RegexAutomaton toReplace,
                                      RegexAutomaton str)
                               throws it.unive.lisa.util.datastructures.automaton.CyclicAutomatonException
        Yields a new automaton where all occurrences of strings recognized by toReplace are replaced with the automaton str, assuming that toReplace is finite (i.e., no loops nor top-transitions). The resulting automaton is then collapsed.

        If toReplace recognizes a single string, than this method performs a must-replacement, meaning that the string recognized by toReplace will effectively be replaced. Otherwise, occurrences of strings of toReplace are not replaced in the resulting automaton: instead, a branching will be introduced to model an or between the original string of toReplace and the whole str.

        this is never modified by this method.
        Parameters:
        toReplace - the automaton recognizing the strings to replace
        str - the automaton that must be used as replacement
        Returns:
        the replaced automaton
        Throws:
        it.unive.lisa.util.datastructures.automaton.CyclicAutomatonException - if toReplace contains loops
      • repeat

        public RegexAutomaton repeat​(long n)
        Yields an automaton that corresponds to the n-time concatenation of this.
        Parameters:
        n - the number of repetitions
        Returns:
        an automaton that corresponds to the n-time concatenation of this
      • trimLeft

        public RegexAutomaton trimLeft()
        Yields a new automaton where leading whitespaces have been removed from this.
        Returns:
        a new automaton where leading whitespaces have been removed from this
      • trimRight

        public RegexAutomaton trimRight()
        Yields a new automaton where trailing whitespaces have been removed from this.
        Returns:
        a new automaton where trailing whitespaces have been removed from this
      • trim

        public RegexAutomaton trim()
        Yields a new automaton where trailing and leading whitespaces have been removed from this.
        Returns:
        a new automaton where trailing and leading whitespaces have been removed from this