Class RegexAutomaton
- java.lang.Object
-
- it.unive.lisa.util.datastructures.automaton.Automaton<RegexAutomaton,it.unive.lisa.util.datastructures.regex.RegularExpression>
-
- it.unive.lisa.analysis.string.tarsis.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 areRegularExpression
s.
-
-
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 givenstates
andtransitions
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
acceptsTopEventually()
Yieldstrue
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 collapsingthis
, 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 aRegexAutomaton
recognizing the empty language.RegexAutomaton
emptyLanguage()
static RegexAutomaton
emptyStr()
Builds aRegexAutomaton
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 then
-time concatenation ofthis
.RegexAutomaton
replace(RegexAutomaton toReplace, RegexAutomaton str)
Yields a new automaton where all occurrences of strings recognized bytoReplace
are replaced with the automatonstr
, assuming thattoReplace
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 aRegexAutomaton
recognizing the given string.static RegexAutomaton
string(java.lang.String string)
Builds aRegexAutomaton
recognizing the given string.static RegexAutomaton
strings(java.lang.String... strings)
Builds aRegexAutomaton
recognizing the given strings.it.unive.lisa.util.datastructures.regex.RegularExpression
symbolToRegex(it.unive.lisa.util.datastructures.regex.RegularExpression symbol)
static RegexAutomaton
topString()
Builds aRegexAutomaton
recognizing the top string, that is, with a single transition recognizingTopAtom
.RegexAutomaton
trim()
Yields a new automaton where trailing and leading whitespaces have been removed fromthis
.RegexAutomaton
trimLeft()
Yields a new automaton where leading whitespaces have been removed fromthis
.RegexAutomaton
trimRight()
Yields a new automaton where trailing whitespaces have been removed fromthis
.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
-
-
-
-
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 givenstates
andtransitions
.- Parameters:
states
- the set of states of the new automatontransitions
- the set of the transitions of the new automaton
-
-
Method Detail
-
topString
public static RegexAutomaton topString()
Builds aRegexAutomaton
recognizing the top string, that is, with a single transition recognizingTopAtom
.- Returns:
- the automaton
-
emptyLang
public static RegexAutomaton emptyLang()
Builds aRegexAutomaton
recognizing the empty language.- Returns:
- the automaton
-
string
public static RegexAutomaton string(java.lang.String string)
Builds aRegexAutomaton
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 aRegexAutomaton
recognizing the given string.- Parameters:
s
- the string to recognize- Returns:
- the automaton
-
emptyStr
public static RegexAutomaton emptyStr()
Builds aRegexAutomaton
recognizing the empty string.- Returns:
- the automaton
-
strings
public static RegexAutomaton strings(java.lang.String... strings)
Builds aRegexAutomaton
recognizing the given strings.- Parameters:
strings
- the strings to recognize- Returns:
- the automaton
-
singleString
public RegexAutomaton singleString(java.lang.String string)
-
unknownString
public RegexAutomaton unknownString()
-
emptyLanguage
public RegexAutomaton emptyLanguage()
-
emptyString
public RegexAutomaton emptyString()
-
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 classit.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 classit.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 classit.unive.lisa.util.datastructures.automaton.Automaton<RegexAutomaton,it.unive.lisa.util.datastructures.regex.RegularExpression>
-
acceptsTopEventually
public boolean acceptsTopEventually()
Yieldstrue
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 classit.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 collapsingthis
, 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 bytoReplace
are replaced with the automatonstr
, assuming thattoReplace
is finite (i.e., no loops nor top-transitions). The resulting automaton is then collapsed.
IftoReplace
recognizes a single string, than this method performs a must-replacement, meaning that the string recognized bytoReplace
will effectively be replaced. Otherwise, occurrences of strings oftoReplace
are not replaced in the resulting automaton: instead, a branching will be introduced to model an or between the original string oftoReplace
and the wholestr
.
this
is never modified by this method.- Parameters:
toReplace
- the automaton recognizing the strings to replacestr
- the automaton that must be used as replacement- Returns:
- the replaced automaton
- Throws:
it.unive.lisa.util.datastructures.automaton.CyclicAutomatonException
- iftoReplace
contains loops
-
repeat
public RegexAutomaton repeat(long n)
Yields an automaton that corresponds to then
-time concatenation ofthis
.- Parameters:
n
- the number of repetitions- Returns:
- an automaton that corresponds to the
n
-time concatenation ofthis
-
trimLeft
public RegexAutomaton trimLeft()
Yields a new automaton where leading whitespaces have been removed fromthis
.- 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 fromthis
.- 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 fromthis
.- Returns:
- a new automaton where trailing and leading whitespaces have been
removed from
this
-
-