|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.jscience.computing.automaton.Automaton
public class Automaton
Finite-state automaton with regular expression operations.
Automata are represented usingState and Transition objects.
Implicitly, all states and transitions of an automaton are reachable from its initial state.
If the states or transitions are manipulated manually, the restoreInvariant()
and setDeterministic(boolean) methods should be used afterwards to restore
certain representation invariants that are assumed by the built-in automata operations.
| Field Summary | |
|---|---|
static int |
MINIMIZE_BRZOZOWSKI
Minimize using Brzozowski's O(2n) algorithm. |
static int |
MINIMIZE_HOPCROFT
Minimize using Hopcroft's O(n log n) algorithm. |
static int |
MINIMIZE_HUFFMAN
Minimize using Huffman's O(n2) algorithm. |
| Constructor Summary | |
|---|---|
Automaton()
Constructs new automaton that accepts the empty language. |
|
| Method Summary | |
|---|---|
void |
addEpsilons(java.util.Collection<StatePair> pairs)
Adds epsilon transitions to this automaton. |
java.lang.Object |
clone()
Returns a clone of this automaton. |
Automaton |
complement()
Returns new (deterministic) automaton that accepts the complement of the language of this automaton. |
Automaton |
compress(java.lang.String set,
char c)
Returns a new automaton that accepts the compressed language of this automaton. |
Automaton |
concatenate(Automaton a)
Returns new automaton that accepts the concatenation of the languages of this and the given automaton. |
static Automaton |
concatenate(java.util.List<Automaton> l)
Returns new automaton that accepts the concatenation of the languages of the given automata. |
void |
determinize()
Determinizes this automaton. |
boolean |
equals(java.lang.Object obj)
Returns true if the language of this automaton is equal to the language of the given automaton. |
java.util.Set<State> |
getAcceptStates()
Returns the set of reachable accept states. |
java.lang.String |
getCommonPrefix()
Returns the longest string that is a prefix of all accepted strings and visits each state at most once. |
java.util.Set<java.lang.String> |
getFiniteStrings()
Returns set of accepted strings, assuming this automaton has a finite language. |
java.util.Set<java.lang.String> |
getFiniteStrings(int limit)
Returns set of accepted strings, assuming that at most limit
strings are accepted. |
java.lang.Object |
getInfo()
Returns extra information associated with this automaton. |
State |
getInitialState()
Gets initial state. |
java.util.Set<State> |
getLiveStates()
Returns set of live states. |
int |
getNumberOfStates()
Returns number of states in this automaton. |
int |
getNumberOfTransitions()
Returns number of transitions in this automaton. |
java.lang.String |
getShortestExample(boolean accepted)
Returns a shortest accepted/rejected string. |
java.lang.String |
getSingleton()
Returns the singleton string for this automaton. |
java.util.Set<State> |
getStates()
Returns the set states that are reachable from the initial state. |
int |
hashCode()
Returns hash code for this automaton. |
Automaton |
homomorph(char[] source,
char[] dest)
Returns new automaton accepting the homomorphic image of this automaton using the given function. |
Automaton |
intersection(Automaton a)
Returns new (deterministic) automaton that accepts the intersection of the languages of this and the given automaton. |
boolean |
isDeterministic()
Returns deterministic flag for this automaton. |
boolean |
isEmpty()
Returns true if this automaton accepts no strings. |
boolean |
isEmptyString()
Returns true if this automaton accepts the empty string and nothing else. |
boolean |
isFinite()
Returns true if the language of this automaton is finite. |
boolean |
isTotal()
Returns true if this automaton accepts all strings. |
static Automaton |
load(java.io.InputStream stream)
Retrieves a serialized Automaton from a stream. |
static Automaton |
load(java.net.URL url)
Retrieves a serialized Automaton located by a URL. |
static Automaton |
makeAnyChar()
Returns new (deterministic) automaton that accepts any single character. |
static Automaton |
makeAnyString()
Returns new (deterministic) automaton that accepts all strings. |
static Automaton |
makeChar(char c)
Returns new (deterministic) automaton that accepts a single character of the given value. |
static Automaton |
makeCharRange(char min,
char max)
Returns new (deterministic) automaton that accepts a single char whose value is in the given interval (including both end points). |
static Automaton |
makeCharSet(java.lang.String set)
Returns new (deterministic) automaton that accepts a single character in the given set. |
static Automaton |
makeEmpty()
Returns new (deterministic) automaton with the empty language. |
static Automaton |
makeEmptyString()
Returns new (deterministic) automaton that accepts only the empty string. |
static Automaton |
makeInterval(int min,
int max,
int digits)
Returns new automaton that accepts strings representing decimal non-negative integers in the given interval. |
static Automaton |
makeString(java.lang.String s)
Returns new (deterministic) automaton that accepts the single given string. |
void |
minimize()
Minimizes (and determinizes if not already deterministic) this automaton. |
Automaton |
minus(Automaton a)
Returns new (deterministic) automaton that accepts the intersection of the language of this automaton and the complement of the language of the given automaton. |
Automaton |
optional()
Returns new automaton that accepts the union of the empty string and the language of this automaton. |
Automaton |
overlap(Automaton a)
Returns automaton that accepts the strings in more than one way can be split into a left part being accepted by this automaton and a right part being accepted by the given automaton. |
Automaton |
projectChars(java.util.Set<java.lang.Character> chars)
Returns new automaton with projected alphabet. |
void |
reduce()
Reduces this automaton. |
void |
removeDeadTransitions()
Removes transitions to dead states and calls reduce()
(a state is "dead" if no accept state is reachable from it). |
Automaton |
repeat()
Returns new automaton that accepts the Kleene star (zero or more concatenated repetitions) of the language of this automaton. |
Automaton |
repeat(int min)
Returns new automaton that accepts min or more
concatenated repetitions of the language of this automaton. |
Automaton |
repeat(int min,
int max)
Returns new automaton that accepts between min and
max (including both) concatenated repetitions of the
language of this automaton. |
void |
restoreInvariant()
Restores representation invariant. |
boolean |
run(java.lang.String s)
Returns true if the given string is accepted by this automaton. |
void |
setDeterministic(boolean deterministic)
Sets deterministic flag for this automaton. |
void |
setInfo(java.lang.Object info)
Associates extra information with this automaton. |
void |
setInitialState(State s)
Sets initial state. |
static void |
setMinimization(int algorithm)
Selects minimization algorithm (default: MINIMIZE_HOPCROFT). |
static void |
setMinimizeAlways(boolean flag)
Sets or resets minimize always flag. |
Automaton |
shuffle(Automaton a)
Returns new automaton that accepts the shuffle (interleaving) of the languages of this and the given automaton. |
static java.lang.String |
shuffleSubsetOf(java.util.Collection<Automaton> ca,
Automaton a,
java.lang.Character suspend_shuffle,
java.lang.Character resume_shuffle)
Returns a string that is an interleaving of strings that are accepted by ca but not by a. |
Automaton |
singleChars()
Returns new automaton that accepts the single chars that occur in strings that are accepted by this automaton. |
void |
store(java.io.OutputStream stream)
Writes this Automaton to the given stream. |
boolean |
subsetOf(Automaton a)
Returns true if the language of this automaton is a subset of the language of the given automaton. |
Automaton |
subst(char c,
java.lang.String s)
Returns new automaton where all transitions of the given char are replaced by a string. |
Automaton |
subst(java.util.Map<java.lang.Character,java.util.Set<java.lang.Character>> map)
Returns new automaton where all transition labels have been substituted. |
java.lang.String |
toDot()
Returns Graphviz Dot representation of this automaton. |
java.lang.String |
toString()
Returns a string representation of this automaton. |
Automaton |
trim(java.lang.String set,
char c)
Returns a new automaton that accepts the trimmed language of this automaton. |
Automaton |
union(Automaton a)
Returns new automaton that accepts the union of the languages of this and the given automaton. |
static Automaton |
union(java.util.Collection<Automaton> l)
Returns new automaton that accepts the union of the languages of the given automata. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int MINIMIZE_HUFFMAN
setMinimization(int),
Constant Field Valuespublic static final int MINIMIZE_BRZOZOWSKI
setMinimization(int),
Constant Field Valuespublic static final int MINIMIZE_HOPCROFT
setMinimization(int),
Constant Field Values| Constructor Detail |
|---|
public Automaton()
State and Transition objects.
setInitialState(State),
State,
Transition| Method Detail |
|---|
public static void setMinimization(int algorithm)
MINIMIZE_HOPCROFT).
algorithm - minimization algorithmpublic static void setMinimizeAlways(boolean flag)
minimize() will automatically
be invoked after all operations that otherwise may produce non-minimal automata.
By default, the flag is not set.
flag - if true, the flag is setpublic java.lang.String getSingleton()
public void setInitialState(State s)
s - statepublic State getInitialState()
public boolean isDeterministic()
public void setDeterministic(boolean deterministic)
deterministic - true if the automaton is definitely deterministic, false if the automaton
may be nondeterministicpublic void setInfo(java.lang.Object info)
info - extra informationpublic java.lang.Object getInfo()
setInfo(Object)public java.util.Set<State> getStates()
State objectspublic java.util.Set<State> getAcceptStates()
State objectspublic void restoreInvariant()
setDeterministic(boolean)public void reduce()
public java.util.Set<State> getLiveStates()
State objectspublic void removeDeadTransitions()
reduce()
(a state is "dead" if no accept state is reachable from it).
public static Automaton makeEmpty()
public static Automaton makeEmptyString()
public static Automaton makeAnyString()
public static Automaton makeAnyChar()
public static Automaton makeChar(char c)
public static Automaton makeCharRange(char min,
char max)
public static Automaton makeCharSet(java.lang.String set)
public static Automaton makeInterval(int min,
int max,
int digits)
throws java.lang.IllegalArgumentException
min - minimal value of intervalmax - maximal value of inverval (both end points are included in the interval)digits - if >0, use fixed number of digits (strings must be prefixed
by 0's to obtain the right length) -
otherwise, the number of digits is not fixed
java.lang.IllegalArgumentException - if min>max or if numbers in the interval cannot be expressed
with the given fixed number of digitspublic static Automaton makeString(java.lang.String s)
public Automaton concatenate(Automaton a)
public static Automaton concatenate(java.util.List<Automaton> l)
public Automaton optional()
public Automaton repeat()
public Automaton repeat(int min)
min or more
concatenated repetitions of the language of this automaton.
Complexity: linear in number of states and in min.
public Automaton repeat(int min,
int max)
min and
max (including both) concatenated repetitions of the
language of this automaton.
Complexity: linear in number of states and in min and
max.
public Automaton complement()
public Automaton minus(Automaton a)
public Automaton intersection(Automaton a)
public static java.lang.String shuffleSubsetOf(java.util.Collection<Automaton> ca,
Automaton a,
java.lang.Character suspend_shuffle,
java.lang.Character resume_shuffle)
ca but not by a. If no such string
exists, null is returned. As a side-effect, a is determinized,
if not already deterministic. Only interleavings that respect
the suspend/resume markers (two BMP private code points) are considered if the markers are non-null.
Also, interleavings never split surrogate pairs.
Complexity: proportional to the product of the numbers of states (if a
is already deterministic).
public Automaton union(Automaton a)
public static Automaton union(java.util.Collection<Automaton> l)
public void determinize()
public void minimize()
setMinimization(int)public Automaton overlap(Automaton a)
public Automaton singleChars()
public Automaton trim(java.lang.String set,
char c)
c character is allowed in the original automaton, one or
more set characters are allowed in the new automaton. 2)
The automaton is prefixed and postfixed with any number of
set characters.
set - set of characters to be trimmedc - canonical trim character (assumed to be in set)
public Automaton compress(java.lang.String set,
char c)
c character is allowed in the
original automaton, one or more set characters are allowed
in the new automaton.
set - set of characters to be compressedc - canonical compress character (assumed to be in set)public Automaton subst(java.util.Map<java.lang.Character,java.util.Set<java.lang.Character>> map)
c is changed to a set of
transitions, one for each character in map(c). If
map(c) is null, then the transition is unchanged.
map - map from characters to sets of characters (where characters
are Character objects)
public Automaton subst(char c,
java.lang.String s)
c - chars - string
public Automaton homomorph(char[] source,
char[] dest)
source and dest are assumed to be arrays of
same length, and source must be sorted in increasing order
and contain no duplicates. source defines the starting
points of char intervals, and the corresponding entries in
dest define the starting points of corresponding new
intervals.
public Automaton projectChars(java.util.Set<java.lang.Character> chars)
Character). If
null is 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 from chars are in the
interval uE000-uF8FF.
public void addEpsilons(java.util.Collection<StatePair> pairs)
pairs - collection of StatePair objects representing pairs of source/destination states
where epsilon transitions should be addedpublic boolean run(java.lang.String s)
RunAutomaton class.
public int getNumberOfStates()
public int getNumberOfTransitions()
public boolean isEmptyString()
public boolean isEmpty()
public boolean isTotal()
public boolean isFinite()
public java.util.Set<java.lang.String> getFiniteStrings()
public java.util.Set<java.lang.String> getFiniteStrings(int limit)
limit
strings are accepted. If more than limit strings are
accepted, null is returned. If limit<0, then this
methods works like getFiniteStrings().
public java.lang.String getShortestExample(boolean accepted)
accepted - if true, look for accepted strings; otherwise, look for rejected strings
public java.lang.String getCommonPrefix()
public boolean subsetOf(Automaton a)
this.intersection(a.complement()).isEmpty().
public boolean equals(java.lang.Object obj)
hashCode and
subsetOf.
equals in class java.lang.Objectpublic Automaton shuffle(Automaton a)
public int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String toDot()
public java.lang.Object clone()
clone in class java.lang.Object
public static Automaton load(java.net.URL url)
throws java.io.IOException,
java.io.OptionalDataException,
java.lang.ClassCastException,
java.lang.ClassNotFoundException,
java.io.InvalidClassException
Automaton located by a URL.
url - URL of serialized automaton
java.io.IOException - if input/output related exception occurs
java.io.OptionalDataException - if the data is not a serialized object
java.io.InvalidClassException - if the class serial number does not match
java.lang.ClassCastException - if the data is not a serialized Automaton
java.lang.ClassNotFoundException - if the class of the serialized object cannot be found
public static Automaton load(java.io.InputStream stream)
throws java.io.IOException,
java.io.OptionalDataException,
java.lang.ClassCastException,
java.lang.ClassNotFoundException,
java.io.InvalidClassException
Automaton from a stream.
stream - input stream with serialized automaton
java.io.IOException - if input/output related exception occurs
java.io.OptionalDataException - if the data is not a serialized object
java.io.InvalidClassException - if the class serial number does not match
java.lang.ClassCastException - if the data is not a serialized Automaton
java.lang.ClassNotFoundException - if the class of the serialized object cannot be found
public void store(java.io.OutputStream stream)
throws java.io.IOException
Automaton to the given stream.
stream - output stream for serialized automaton
java.io.IOException - if input/output related exception occurs
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||