12 : _term(
term), _max_distance(max_distance),
13 transition(
std::
move(transition)), min_distance(
std::
move(min_distance)),
14 _a(max_distance < (
SIZE_MAX - 1) >> 1 ? (max_distance << 1) + 1
34 if (!_edges.empty() || !_pending.empty()) {
38 _intersection = _pending.front();
40 DawgNode *node = _intersection->node();
41 State *state = _intersection->state();
42 _i = state->
head()->term_index();
43 std::size_t
b = _term.length() - _i;
44 _k = (_a <
b) ? _a :
b;
46 _edges.emplace(label, target);
49 DawgNode *node = _intersection->node();
50 State *state = _intersection->state();
51 std::pair<char, DawgNode *>
edge = _edges.front();
55 std::vector<bool> characteristic_vector =
56 this->characteristic_vector(
next_label, _term, _k, _i);
73 }
while (!_edges.empty() || !_pending.empty());
79template <
class Result>
88template <
class Result>
96 std::size_t distance) {
102 std::string &
term, std::size_t distance) {
103 _candidate.first =
term;
107template <
class Result>
112template <
class Result>
118template <
class Result>
120 std::size_t
k, std::size_t
i)
121 -> std::vector<bool> {
122 std::vector<bool> characteristic_vector(
k);
123 for (
int j = 0;
j <
k;
j += 1) {
124 characteristic_vector[
j] = (
x ==
term[
i +
j]);
126 return characteristic_vector;
132template <
class Result>
135 std::size_t max_distance,
139 : _term(
term), _max_distance(max_distance),
141 min_distance(
std::
move(min_distance)) {}
143template <
class Result>
149template <
class Result>
Represents a position within one or more terms of a DAWG dictionary.
void is_final(bool is_final)
Specifies whether this node represents a word boundary, or immediately follows an edge having the fin...
void for_each_edge(const std::function< void(char, DawgNode *)> &fn) const
Iterates over each outgoing edge of this node and invokes a callback function with each edge's charac...
Represents an Intersection between a dictionary automaton and Levenshtein automaton,...
Lazily traverses the intersection between the dictionary automaton and Levenshtein automaton,...
auto end() -> LazyQuery< Result >
Returns a placeholder representing the end of the spelling candidates.
LazyIterator(const std::string &term, std::size_t max_distance, Intersection *intersection, TransitionFn transition, DistanceFn min_distance)
Constructs a new LazyIterator which yields spelling candidates as they are matched while traversing t...
auto begin() -> LazyQuery< Result >
Returns an instance of LazyQuery that yields spelling candidates of the given Type.
Lazily traverses the intersection between the dictionary automaton and Levenshtein automaton,...
void advance()
Advances to the next spelling candidate.
std::queue< Intersection * > _pending
Intermediate Intersection instances representing paths along the intersection between the dictionary ...
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 character...
auto operator==(const LazyQuery &other) const -> bool
Returns whether this LazyQuery has matched all the spelling candidates.
auto operator++() -> LazyQuery &
Advances to the next spelling candidate.
LazyQuery()=default
Constructs a LazyQuery that represents the end of the spelling candidates.
auto build_intersection(char label, DawgNode *node, State *state, Intersection *parent) -> Intersection *
Factory function that constructs and records a new Intersection instance.
auto operator*() const -> const Result &
Returns the current spelling candidate.
void update_candidate(std::string &term, std::size_t distance)
Sets the current spelling candidate according to the desired Result type.
~LazyQuery()
Frees any owned members.
Consists of a closure of Position nodes within the Levenshtein automaton.
void head(Position *head)
Sets the first element in the linked-list of Position nodes.
void query(ll::Dawg *dawg, const std::string &query_term, std::size_t max_distance)
Various utilities regarding Levenshtein transducers.
std::function< std::size_t(State *, std::size_t)> DistanceFn
Infers the Levenshtein distance from a final Levenshtein State and the length of the query term.
auto distance(State *state, std::size_t query_length) -> std::size_t
Infers the Levenshtein distance from the given State and query length.
std::function< State *(State *, std::vector< bool > &)> TransitionFn
Returns the Levenshtein State mapped-to by another State and characteristic vector.