liblevenshtein 4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
|
Lazily traverses the intersection between the dictionary automaton and Levenshtein automaton, guided by the query term, and yields each spelling candidate as it is matched. More...
#include <lazy_query.h>
Public Member Functions | |
LazyQuery (const std::string &term, std::size_t max_distance, Intersection *intersection, TransitionFn transition, DistanceFn min_distance) | |
Constructs a new LazyQuery which yields spelling candidates as they are matched while traversing the intersection between the dictionary automaton and Levenshtein automaton, guided by the query term. | |
LazyQuery ()=default | |
Constructs a LazyQuery that represents the end of the spelling candidates. | |
~LazyQuery () | |
Frees any owned members. | |
auto | operator++ () -> LazyQuery & |
Advances to the next spelling candidate. | |
auto | operator* () const -> const Result & |
Returns the current spelling candidate. | |
auto | operator== (const LazyQuery &other) const -> bool |
Returns whether this LazyQuery has matched all the spelling candidates. | |
Private Member Functions | |
void | advance () |
Advances to the next spelling candidate. | |
void | update_candidate (std::string &term, std::size_t distance) |
Sets the current spelling candidate according to the desired Result type. | |
auto | build_intersection (char label, DawgNode *node, State *state, Intersection *parent) -> Intersection * |
Factory function that constructs and records a new Intersection instance. | |
auto | characteristic_vector (char x, std::string &term, std::size_t k, std::size_t i) -> std::vector< bool > |
Flags all instances of the given character in the query term within a window of consecutive characters. | |
void | update_candidate (std::string &term, std::size_t distance) |
void | update_candidate (std::string &term, std::size_t distance) |
Private Attributes | |
std::queue< Intersection * > | _pending |
Intermediate Intersection instances representing paths along the intersection between the dictionary automaton and Levenshtein automaton, guided by the query term. | |
std::queue< std::pair< char, DawgNode * > > | _edges |
Outgoing dictionary node edges that are pending traversal along the intersection between the dictionary automaton and Levenshtein automaton, guided by the query term. | |
std::vector< Intersection * > | _intersections |
Tracks Intersection allocations so they may be freed. | |
bool | _is_complete = false |
Whether all the spelling candidates have been matched. | |
Intersection * | _intersection = nullptr |
Current whose respective spelling candidates are being considered. | |
Result | _candidate |
Presently matched spelling candidate. | |
std::string | _term |
Query term whose spelling candidates are to be matched. | |
std::size_t | _max_distance |
Maximum edit distance to consider when matching spelling candidates. | |
TransitionFn | transition |
Maps one Levenshtein State to another given the State and a characteristic vector. | |
DistanceFn | min_distance |
Infers the Levenshtein distance between the query term and a spelling candidate. | |
std::size_t | _a |
Intermediate value used to compare edit distances without overflowing. | |
std::size_t | _k |
Intermediate value used to compare edit distances without overflowing. | |
std::size_t | _i |
Intermediate value used to compare edit distances without overflowing. | |
Lazily traverses the intersection between the dictionary automaton and Levenshtein automaton, guided by the query term, and yields each spelling candidate as it is matched.
Definition at line 30 of file lazy_query.h.
liblevenshtein::LazyQuery< Result >::LazyQuery | ( | const std::string & | term, |
std::size_t | max_distance, | ||
Intersection * | intersection, | ||
TransitionFn | transition, | ||
DistanceFn | min_distance ) |
Constructs a new LazyQuery which yields spelling candidates as they are matched while traversing the intersection between the dictionary automaton and Levenshtein automaton, guided by the query term.
term | Query term whose spelling candidates are to be matched. |
max_distance | Maximum edit distance to consider when matching spelling candidates. |
intersection | Initial Intersection between the root node of the dictionary and the initial Levenshtein State. |
transition | Function that maps one Levenshtein State to another with input from a characteristic vector. |
min_distance | Infers the Levenshtein distance between the query term and a spelling candidate. |
Definition at line 9 of file lazy_query.cpp.
References liblevenshtein::LazyQuery< Result >::_pending, liblevenshtein::LazyQuery< Result >::advance(), liblevenshtein::DawgNode::is_final(), query(), and liblevenshtein::LazyQuery< Result >::update_candidate().
|
default |
Constructs a LazyQuery that represents the end of the spelling candidates.
liblevenshtein::LazyQuery< Result >::~LazyQuery | ( | ) |
Frees any owned members.
Definition at line 26 of file lazy_query.cpp.
References query().
|
private |
Advances to the next spelling candidate.
Definition at line 33 of file lazy_query.cpp.
References liblevenshtein::distance(), liblevenshtein::DawgNode::for_each_edge(), liblevenshtein::State::head(), and query().
Referenced by liblevenshtein::LazyQuery< Result >::LazyQuery().
|
private |
Factory function that constructs and records a new Intersection instance.
label | The character annotating the incoming edge of the current dictionary node in the traversal. |
node | The current dictionary node in the traversal. |
state | The current Levenshtein State in the traversal. |
parent | The immediately preceding Intersection node used to reconstruct the spelling candidate. |
Definition at line 80 of file lazy_query.cpp.
References query().
|
private |
Flags all instances of the given character in the query term within a window of consecutive characters.
x | Character from the dictionary automaton to match within the window over the characters in the query term. |
term | Query term. |
k | Window size of the characteristic vector. |
i | Base offset of the window for the characteristic vector. |
Definition at line 119 of file lazy_query.cpp.
References query().
auto liblevenshtein::LazyQuery< Result >::operator* | ( | ) | const -> const Result & |
Returns the current spelling candidate.
Definition at line 108 of file lazy_query.cpp.
auto liblevenshtein::LazyQuery< Result >::operator++ | ( | ) | -> LazyQuery & |
Advances to the next spelling candidate.
Definition at line 89 of file lazy_query.cpp.
auto liblevenshtein::LazyQuery< Result >::operator== | ( | const LazyQuery< Result > & | other | ) | const -> bool |
Returns whether this LazyQuery has matched all the spelling candidates.
other | An ignored instance of LazyQuery. |
Definition at line 113 of file lazy_query.cpp.
|
private |
Definition at line 95 of file lazy_query.cpp.
References query().
|
private |
Definition at line 101 of file lazy_query.cpp.
References liblevenshtein::distance(), and query().
|
private |
Sets the current spelling candidate according to the desired Result type.
term | Spelling candidate. |
distance | Levenshtein distance between the query term and the spelling candidate. |
Referenced by liblevenshtein::LazyQuery< Result >::LazyQuery().
|
private |
Intermediate value used to compare edit distances without overflowing.
Definition at line 123 of file lazy_query.h.
|
private |
Presently matched spelling candidate.
Definition at line 106 of file lazy_query.h.
|
private |
Outgoing dictionary node edges that are pending traversal along the intersection between the dictionary automaton and Levenshtein automaton, guided by the query term.
Definition at line 94 of file lazy_query.h.
|
private |
Intermediate value used to compare edit distances without overflowing.
Definition at line 129 of file lazy_query.h.
|
private |
Current whose respective spelling candidates are being considered.
Definition at line 103 of file lazy_query.h.
|
private |
Tracks Intersection allocations so they may be freed.
Definition at line 97 of file lazy_query.h.
Whether all the spelling candidates have been matched.
Definition at line 100 of file lazy_query.h.
|
private |
Intermediate value used to compare edit distances without overflowing.
Definition at line 126 of file lazy_query.h.
|
private |
Maximum edit distance to consider when matching spelling candidates.
Definition at line 112 of file lazy_query.h.
|
private |
Intermediate Intersection instances representing paths along the intersection between the dictionary automaton and Levenshtein automaton, guided by the query term.
Definition at line 89 of file lazy_query.h.
Referenced by liblevenshtein::LazyQuery< Result >::LazyQuery().
|
private |
Query term whose spelling candidates are to be matched.
Definition at line 109 of file lazy_query.h.
|
private |
Infers the Levenshtein distance between the query term and a spelling candidate.
Definition at line 120 of file lazy_query.h.
|
private |
Maps one Levenshtein State to another given the State and a characteristic vector.
Definition at line 116 of file lazy_query.h.