liblevenshtein 4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
Loading...
Searching...
No Matches
state_transition.cpp
Go to the documentation of this file.
1#include <utility>
2
5
6namespace liblevenshtein {
7
10 UnsubsumeFn unsubsume,
11 std::size_t max_distance,
12 std::size_t query_length)
13 : transition(std::move(transition)), compare(std::move(compare)),
14 merge(std::move(merge)), unsubsume(std::move(unsubsume)),
15 max_distance(max_distance), query_length(query_length) {}
16
18 std::vector<bool> &characteristic_vector)
19 -> State * {
20 std::size_t offset = curr_state->head()->term_index();
21 auto *next_state = new State();
22 std::size_t n = max_distance;
23
24 for (Position *position : *curr_state) {
25 merge(next_state, transition(n, position, characteristic_vector, offset));
26 }
27
28 unsubsume(next_state, query_length);
29
30 if (next_state->head() != nullptr) {
31 next_state->sort(compare);
32 return next_state;
33 }
34
35 delete next_state;
36 return nullptr;
37}
38
39} // namespace liblevenshtein
Represents a location within the Levenshtein automaton.
Definition position.h:11
StateTransition(PositionTransitionFn transition, CompareFn compare, MergeFn merge, UnsubsumeFn unsubsume, std::size_t max_distance, std::size_t query_length)
Constructs a new StateTransition function.
auto operator()(State *curr_state, std::vector< bool > &characteristic_vector) -> State *
Returns a successive State to the current one given the characteristic vector.
Consists of a closure of Position nodes within the Levenshtein automaton.
Definition state.h:23
void head(Position *head)
Sets the first element in the linked-list of Position nodes.
Definition state.cpp:26
Removes (unsubsumes) all Positions from a State that are subsumed by another Position within the same...
Definition unsubsume.h:20
void query(ll::Dawg *dawg, const std::string &query_term, std::size_t max_distance)
Definition main.cpp:25
Various utilities regarding Levenshtein transducers.
Definition namespaces.dox:9
std::function< int(Position *, Position *)> CompareFn
Compares Position nodes.
auto compare(Position *lhs, Position *rhs) -> int
Compares two Positions within the Levenshtein transducer.
void merge(State *state, const std::vector< Position * > &positions)
Merges a list of Positions into the Levenshtein state.
std::function< std::vector< Position * >(std::size_t, Position *, std::vector< bool > &, std::size_t)> PositionTransitionFn
Transitions Position nodes.
std::function< void(State *, std::vector< Position * >)> MergeFn
Merges Position nodes into a State.
STL namespace.