liblevenshtein 4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
Loading...
Searching...
No Matches
subsumes.cpp
Go to the documentation of this file.
2
3namespace liblevenshtein {
4
5template <>
7 -> bool {
8 std::size_t i = lhs->term_index();
9 std::size_t e = lhs->num_errors();
10 std::size_t j = rhs->term_index();
11 std::size_t f = rhs->num_errors();
12 return ((i < j) ? (j - i) : (i - j)) <= (f - e);
13}
14
15template <>
17 std::size_t n) -> bool {
18 std::size_t i = lhs->term_index();
19 std::size_t e = lhs->num_errors();
20 bool s = lhs->is_special();
21
22 std::size_t j = rhs->term_index();
23 std::size_t f = rhs->num_errors();
24 bool t = lhs->is_special();
25
26 if (s) {
27 if (t) {
28 return (i == j);
29 }
30
31 return (f == n) && (i == j);
32 }
33
34 if (t) {
35 return ((j < i) ? (i - j - 1) : (j - i + 1)) <= (f - e);
36 }
37
38 return ((i < j) ? (j - i) : (i - j)) <= (f - e);
39}
40
41template <>
43 std::size_t n) -> bool {
44 std::size_t i = lhs->term_index();
45 std::size_t e = lhs->num_errors();
46 bool s = lhs->is_special();
47 std::size_t j = rhs->term_index();
48 std::size_t f = rhs->num_errors();
49 bool t = lhs->is_special();
50
51 if (s && !t) {
52 return false;
53 }
54
55 return ((i < j) ? (j - i) : (i - j)) <= (f - e);
56}
57
58} // namespace liblevenshtein
Represents a location within the Levenshtein automaton.
Definition position.h:11
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< Algorithm::MERGE_AND_SPLIT >(Position *lhs, Position *rhs, std::size_t n) -> bool
Returns whether lhs subsumes rhs according to the subsumption rules of standard Levenshtein distance ...
Definition subsumes.cpp:42
auto subsumes< Algorithm::TRANSPOSITION >(Position *lhs, Position *rhs, std::size_t n) -> bool
Returns whether lhs subsumes rhs according to the subsumption rules of standard Levenshtein distance ...
Definition subsumes.cpp:16
auto subsumes< Algorithm::STANDARD >(Position *lhs, Position *rhs, std::size_t n) -> bool
Returns whether lhs subsumes rhs according to the subsumption rules of standard Levenshtein distance,...
Definition subsumes.cpp:6