liblevenshtein 4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
Loading...
Searching...
No Matches
unsubsume.cpp
Go to the documentation of this file.
1#include <utility>
2
5
6namespace liblevenshtein {
7
9
10void UnsubsumeFn::operator()(State *state, std::size_t query_length) {
12 StateIterator iter_end = state->end();
13 while (outer_iter != iter_end) {
15 std::size_t outer_errors = outer->num_errors();
16
18 ++inner_iter;
19
20 while (inner_iter != iter_end) {
22 if (outer_errors < inner->num_errors()) {
23 break;
24 }
25 ++inner_iter;
26 }
27
28 while (inner_iter != iter_end) {
30 if (subsumes(outer, inner, query_length)) {
31 inner_iter.remove();
32 }
33 ++inner_iter;
34 }
35
36 ++outer_iter;
37 }
38}
39
40} // namespace liblevenshtein
Represents a location within the Levenshtein automaton.
Definition position.h:11
auto num_errors() const -> std::size_t
Returns the accumulated number of errors at the term_index.
Definition position.cpp:27
Iterates over the Position nodes in the linked-list of a Levenshtein State.
Consists of a closure of Position nodes within the Levenshtein automaton.
Definition state.h:23
auto begin() -> StateIterator
Returns an iterator over the Positions in this State, beginning at the head and traversing to the tai...
Definition state.cpp:134
auto end() -> StateIterator
Returns an iterator representing the end of the linked-list of Positions.
Definition state.cpp:138
SubsumesFn subsumes
Determines whether one Position subsumes another given the maximum edit distance to consider.
Definition unsubsume.h:46
void operator()(State *state, std::size_t query_length)
Removes (unsubsumes) all Positions from a State that are subsumed by another Position within the same...
Definition unsubsume.cpp:10
UnsubsumeFn(SubsumesFn subsumes)
Constructs a new UnsubsumeFn that uses a SubsumesFn to filter-out subsumed Positions from a State.
Definition unsubsume.cpp:8
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
auto subsumes(Position *lhs, Position *rhs, std::size_t n) -> bool
Returns whether Position lhs subsumes Position rhs, given the maximum edit distance n.
std::function< bool(Position *, Position *, std::size_t)> SubsumesFn
Determines whether one Position subsumes another given the maximum edit distance to consider.
Definition unsubsume.h:14
STL namespace.