Class SpecialOperations
- java.lang.Object
-
- dk.brics.automaton.SpecialOperations
-
public final class SpecialOperations extends java.lang.ObjectSpecial automata operations.
-
-
Constructor Summary
Constructors Modifier Constructor Description privateSpecialOperations()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static voidacceptToAccept(Automaton a)private static java.util.Set<StatePair>addInnerSetStates(Automaton a, java.lang.String set, char c)For each transition oncfrom a statesto a stater, adds a stateqwith transitions on thesetcharacters fromsandqtoq.private static voidaddSetTransitions(State s, java.lang.String set, State p)static Automatoncompress(Automaton a, java.lang.String set, char c)Returns an automaton that accepts the compressed language of the given automaton.(package private) static intfindIndex(char c, char[] points)Finds the largest entry whose value is less than or equal to c, or 0 if there is no such entry.static java.lang.StringgetCommonPrefix(Automaton a)Returns the longest string that is a prefix of all accepted strings and visits each state at most once.static java.util.Set<java.lang.String>getFiniteStrings(Automaton a)Returns the set of accepted strings, assuming this automaton has a finite language.static java.util.Set<java.lang.String>getFiniteStrings(Automaton a, int limit)Returns the set of accepted strings, assuming that at mostlimitstrings are accepted.private static booleangetFiniteStrings(State s, java.util.HashSet<State> pathstates, java.util.HashSet<java.lang.String> strings, java.lang.StringBuilder path, int limit)Returns the strings that can be produced from the given state, or false if more thanlimitstrings are found.static java.util.Set<java.lang.String>getStrings(Automaton a, int length)Returns the set of accepted strings of the given length.private static voidgetStrings(State s, java.util.Set<java.lang.String> strings, java.lang.StringBuilder path, int length)static AutomatonhexCases(Automaton a)Constructs automaton that accepts the same strings as the given automaton but ignores upper/lower case of A-F.static Automatonhomomorph(Automaton a, char[] source, char[] dest)Returns an automaton accepting the homomorphic image of the given automaton using the given function.static booleanisFinite(Automaton a)Returns true if the language of this automaton is finite.private static booleanisFinite(State s, java.util.HashSet<State> path, java.util.HashSet<State> visited)Checks whether there is a loop containing s.static Automatonoverlap(Automaton a1, Automaton a2)Returns an automaton that accepts the overlap of strings that in more than one way can be split into a left part being accepted bya1and a right part being accepted bya2.static voidprefixClose(Automaton a)Prefix closes the given automaton.static AutomatonprojectChars(Automaton a, java.util.Set<java.lang.Character> chars)Returns an automaton with projected alphabet.static AutomatonreplaceWhitespace(Automaton a)Constructs automaton that accepts 0x20, 0x9, 0xa, and 0xd in place of each 0x20 transition in the given automaton.static java.util.Set<State>reverse(Automaton a)Reverses the language of the given (non-singleton) automaton while returning the set of new initial states.static AutomatonsingleChars(Automaton a)Returns an automaton that accepts the single chars that occur in strings that are accepted by the given automaton.static Automatonsubst(Automaton a, char c, java.lang.String s)Returns an automaton where all transitions of the given char are replaced by a string.static Automatonsubst(Automaton a, java.util.Map<java.lang.Character,java.util.Set<java.lang.Character>> map)Returns an automaton where all transition labels have been substituted.static Automatontrim(Automaton a, java.lang.String set, char c)Returns an automaton that accepts the trimmed language of the given automaton.
-
-
-
Method Detail
-
reverse
public static java.util.Set<State> reverse(Automaton a)
Reverses the language of the given (non-singleton) automaton while returning the set of new initial states.
-
overlap
public static Automaton overlap(Automaton a1, Automaton a2)
Returns an automaton that accepts the overlap of strings that in more than one way can be split into a left part being accepted bya1and a right part being accepted bya2.
-
acceptToAccept
private static void acceptToAccept(Automaton a)
-
singleChars
public static Automaton singleChars(Automaton a)
Returns an automaton that accepts the single chars that occur in strings that are accepted by the given automaton. Never modifies the input automaton.
-
trim
public static Automaton trim(Automaton a, java.lang.String set, char c)
Returns an automaton that accepts the trimmed language of the given automaton. The resulting automaton is constructed as follows: 1) Whenever accharacter is allowed in the original automaton, one or moresetcharacters are allowed in the new automaton. 2) The automaton is prefixed and postfixed with any number ofsetcharacters.- Parameters:
set- set of characters to be trimmedc- canonical trim character (assumed to be inset)
-
addInnerSetStates
private static java.util.Set<StatePair> addInnerSetStates(Automaton a, java.lang.String set, char c)
For each transition oncfrom a statesto a stater, adds a stateqwith transitions on thesetcharacters fromsandqtoq. Returns the epsilon transitions from eachqto the correspondingr.
-
compress
public static Automaton compress(Automaton a, java.lang.String set, char c)
Returns an automaton that accepts the compressed language of the given automaton. Whenever accharacter is allowed in the original automaton, one or moresetcharacters are allowed in the new automaton.- Parameters:
set- set of characters to be compressedc- canonical compress character (assumed to be inset)
-
subst
public static Automaton subst(Automaton a, java.util.Map<java.lang.Character,java.util.Set<java.lang.Character>> map)
Returns an automaton where all transition labels have been substituted.Each transition labeled
cis changed to a set of transitions, one for each character inmap(c). Ifmap(c)is null, then the transition is unchanged.- Parameters:
map- map from characters to sets of characters (where characters areCharacterobjects)
-
findIndex
static int findIndex(char c, char[] points)Finds the largest entry whose value is less than or equal to c, or 0 if there is no such entry.
-
subst
public static Automaton subst(Automaton a, char c, java.lang.String s)
Returns an automaton where all transitions of the given char are replaced by a string.- Parameters:
c- chars- string- Returns:
- new automaton
-
homomorph
public static Automaton homomorph(Automaton a, char[] source, char[] dest)
Returns an automaton accepting the homomorphic image of the given automaton using the given function.This method maps each transition label to a new value.
sourceanddestare assumed to be arrays of same length, andsourcemust be sorted in increasing order and contain no duplicates.sourcedefines the starting points of char intervals, and the corresponding entries indestdefine the starting points of corresponding new intervals.
-
projectChars
public static Automaton projectChars(Automaton a, java.util.Set<java.lang.Character> chars)
Returns an automaton with projected alphabet. The new automaton accepts all strings that are projections of strings accepted by the given automaton onto the given characters (represented byCharacter). Ifnullis in the set, it abbreviates the intervals u0000-uDFFF and uF900-uFFFF (i.e., the non-private code points). It is assumed that all other characters fromcharsare in the interval uE000-uF8FF.
-
isFinite
public static boolean isFinite(Automaton a)
Returns true if the language of this automaton is finite.
-
isFinite
private static boolean isFinite(State s, java.util.HashSet<State> path, java.util.HashSet<State> visited)
Checks whether there is a loop containing s. (This is sufficient since there are never transitions to dead states, seeAutomaton.restoreInvariant().)
-
getStrings
public static java.util.Set<java.lang.String> getStrings(Automaton a, int length)
Returns the set of accepted strings of the given length.
-
getStrings
private static void getStrings(State s, java.util.Set<java.lang.String> strings, java.lang.StringBuilder path, int length)
-
getFiniteStrings
public static java.util.Set<java.lang.String> getFiniteStrings(Automaton a)
Returns the set of accepted strings, assuming this automaton has a finite language. If the language is not finite, null is returned.Complexity: efficient on deterministic automata; on nondeterministic automata, the running time may be exponential in the number of states, so consider determinizing first.
-
getFiniteStrings
public static java.util.Set<java.lang.String> getFiniteStrings(Automaton a, int limit)
Returns the set of accepted strings, assuming that at mostlimitstrings are accepted. If more thanlimitstrings are accepted, null is returned. Iflimit<0, then this methods works likegetFiniteStrings(Automaton).Complexity: efficient on deterministic automata; on nondeterministic automata, the running time may be exponential in the number of states, so consider determinizing first.
-
getFiniteStrings
private static boolean getFiniteStrings(State s, java.util.HashSet<State> pathstates, java.util.HashSet<java.lang.String> strings, java.lang.StringBuilder path, int limit)
Returns the strings that can be produced from the given state, or false if more thanlimitstrings are found.limit<0 means "infinite".
-
getCommonPrefix
public static java.lang.String getCommonPrefix(Automaton a)
Returns the longest string that is a prefix of all accepted strings and visits each state at most once.- Returns:
- common prefix
-
prefixClose
public static void prefixClose(Automaton a)
Prefix closes the given automaton.
-
hexCases
public static Automaton hexCases(Automaton a)
Constructs automaton that accepts the same strings as the given automaton but ignores upper/lower case of A-F.- Parameters:
a- automaton- Returns:
- automaton
-
-