regexp_learner.lstar package¶
Submodules¶
regexp_learner.lstar.automaton_match module¶
- automaton_match(g1: Automaton, g2: Automaton, verbose=False) str [source]¶
Tests whether two minimized deterministic
Automaton
recognize the same language. One can minimize an Automaton usingpybgl.hopcroft_minimize.hopcroft_minimize
.- Parameters:
g1 (Automaton) – A minimal deterministic
Automaton
instance.g2 (Automaton) – A minimal deterministic
Automaton
instance.verbose (bool) – Pass
True
to print useful HTML information.
- Returns:
None
if g1 matches g2, otherwise a counter-example (possibly the empty word).
regexp_learner.lstar.learner module¶
- class Learner(teacher: Teacher, epsilon: str = '', verbose: bool = True)[source]¶
Bases:
object
The learner (in the Angluin framework).
Constructor.
- Parameters:
teacher (Teacher) – The teacher aka oracle (in the Angluin framework).
epsilon (str) – The empty word.
verbose (bool) –
- extend()[source]¶
Extends the
LstarObservationTable
of thisLearner
. This method is triggered when the Teacher returns a counter example.
- initialize(verbose: bool = True)[source]¶
Initializes the
LstarObservationTable
of thisLearner
.- Parameters:
verbose (bool) – Pass
True
to print useful HTML information.
- make_automaton_from_observation_table(o: LstarObservationTable, verbose: bool = False) Automaton [source]¶
Builds an
Automaton
instance from anLstarObservationTable
instance.- Parameters:
o (LstarObservationTable) – An
LstarObservationTable
instance.verbose (bool) –
- Returns:
The resulting Automaton instance.
regexp_learner.lstar.observation_table module¶
- class LstarObservationTable(a='abcdefghijklmnopqrstuvwxyz')[source]¶
Bases:
object
LstarObservationTable
implements the L* observation table used by theLearner
in the Angluin algorithm.Constructor.
Args:
- add_col()[source]¶
Inserts a column in this
LstarObservationTable
.
- add_prefix(s: str) tuple [source]¶
Inserts a prefix in this
LstarObservationTable
.- Parameters:
s (str) – The inserted prefix.
- Returns:
i
is the index ofs
in thisLstarObservationTable
added
equalsTrue
ifs
was not yet in thisLstarObservationTable
,False
otherwise.
- Return type:
A
(i, added)
tuple where
- add_row()[source]¶
Inserts a row in this
LstarObservationTable
.
- add_suffix(e: str) tuple [source]¶
Inserts a suffix in this
LstarObservationTable
.- Parameters:
e (str) – The inserted suffix.
- Returns:
i
is the index ofe
in thisLstarObservationTable
added
equalsTrue
ife
was not yet in thisLstarObservationTable
,False
otherwise.
- Return type:
A
(i, added)
tuple where
- property e: set¶
Retrieves the observed suffixes.
- Returns:
The set of suffixes observed in this
LstarObservationTable
.
- find_mismatch_closeness() tuple [source]¶
Search a pair (prefix, symbol) that shows this
LstarObservationTable
is not closed.- Returns:
s
is a prefix of thisLstarObservationTable
;a
is a symbol of the alphabet of thisLstarObservationTable
(i.e.,self.a
)
- Return type:
A
(s, a)
pair (if found),None
otherwise, where
- find_mismatch_consistency() tuple [source]¶
Search a pair (prefix, symbol) that shows this
LstarObservationTable
is not closed.- Returns:
s1
ands2
are two prefixes of thisLstarObservationTable
;a
is a symbol of the alphabet of thisLstarObservationTable
(i.e.,self.a
)e
is a contradicting suffix w.r.t.s1
ands2
.
- Return type:
A
(s1, s2, a, e)
pair (if found),None
otherwise, where
- get(s: str, e: str) bool [source]¶
Probes this
LstarObservationTable
for a given prefix and a given suffix.- Parameters:
s (str) – The prefix.
e (str) – The suffix.
- Returns:
The observation related to
s + e
.
- get_col(e: str) int [source]¶
Retrieves the column index related to a given prefix. See also
LstarObservationTable.col()
.- Parameters:
e (str) – A suffix.
- Returns:
The corresponding column if found,
None
otherwise.
- static get_or_create_index(m: dict, k: str) int [source]¶
Retrieves the index of a key in a dictionary. If the key is not in the dictionary, the key is inserted and mapped with
len(m)
.- Parameters:
m (dict) – The dictionary.
k (str) – The key.
- Returns:
The index assigned to
k
.
- get_row(s: str) int [source]¶
Retrieves the row index related to a given prefix. See also
LstarObservationTable.row()
.- Parameters:
s (str) – A prefix.
- Returns:
The corresponding row if found,
None
otherwise.
- is_closed(verbose: bool = False) bool [source]¶
Checks whether this
LstarObservationTable
is closed (see Angluin’s paper or Angluin.pdf in this repository).- Parameters:
verbose (bool) – Pass
True
to print debug information.- Returns:
True
if thisLstarObservationTable
is closed,False
otherwise.
- is_consistent(verbose: bool = False) bool [source]¶
Checks whether this
LstarObservationTable
is consistent (see Angluin’s paper or Angluin.pdf in this repository).- Parameters:
verbose (bool) – Pass
True
to print debug information.- Returns:
True
if thisLstarObservationTable
is closed,False
otherwise.
- row(s: str) bytes [source]¶
Retrieves the row in this
LstarObservationTable
.- Parameters:
s (str) – A prefix.
- Returns:
The corresponding row.
- set(s: str, e: str, accepted: bool = True)[source]¶
Fill this
LstarObservationTable
according to a given prefix, a given suffix, and a boolean indicating whether their concatenation belongs to theTeacher
’s language.- Parameters:
s (str) – The prefix.
e (str) – The suffix.
accepted (bool) – Pass
True
ifs + e
belongs to theTeacher
’s language,False
otherwise.
- to_html() str [source]¶
Exports this
LstarObservationTable
to HTML.- Returns:
The corresponding HTML string.
regexp_learner.lstar.teacher module¶
- class Teacher(g: Automaton)[source]¶
Bases:
object
The
Teacher
class (aka oracle) in the Angluin framework.Constructor.
- Parameters:
g – The
pybgl.Automaton
that theLearner
tries to infer.
- property alphabet: set¶
Accessor the alphabet of this
Teacher
instance.- Returns:
The alphabet of the
pybgl.Automaton
of thisTeacher
instance.
- conjecture(h: Automaton) str [source]¶
Handles a conjecture query. (see Angluin’s paper or Angluin.pdf in this repository).
- Parameters:
h (Automaton) – The tested
pybgl.Automaton
(typically, submitted by theLearner
).- Returns:
True
ifh
matches theAutomaton
of thisTeacher
instance,False
otherwise.
- membership_query(w: str) bool [source]¶
Handles a membership query. (see Angluin’s paper or Angluin.pdf in this repository).
- Parameters:
w – The tested word (typically, submitted by the
Learner
).- Returns:
True
ifw
is matched by theAutomaton
of thisTeacher
instance,False
otherwise.