liblevenshtein
4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
Loading...
Searching...
No Matches
merge_and_split_distance.cpp
Go to the documentation of this file.
1
#include "
liblevenshtein/distance/merge_and_split_distance.h
"
2
#include "
liblevenshtein/distance/symmetric_pair.h
"
3
4
namespace
liblevenshtein::distance
{
5
6
auto
MergeAndSplitDistance::between
(std::string
v
, std::string
w
)
7
-> std::size_t {
8
const
SymmetricPair
key
(
v
,
w
);
9
10
std::size_t
distance
;
11
if
(get(
key
,
distance
)) {
12
return
distance
;
13
}
14
15
if
(
v
.empty()) {
16
return
set(
key
,
w
.length());
17
}
18
19
if
(
w
.empty()) {
20
return
set(
key
,
v
.length());
21
}
22
23
char
a
=
v
[0];
24
std::string
x
=
v
.substr(1);
25
char
b
=
w
[0];
26
std::string
y
=
w
.substr(1);
27
28
// Discard identical characters
29
while
(
a
==
b
&& !(
x
.empty() ||
y
.empty())) {
30
a
=
x
[0];
31
v
=
x
;
32
x
=
v
.substr(1);
33
b
=
y
[0];
34
w
=
y
;
35
y
=
w
.substr(1);
36
}
37
38
// x.empty() || y.empty()
39
if
(
a
==
b
) {
40
if
(
x
.empty()) {
41
return
set(
key
,
y
.length());
42
}
43
return
set(
key
,
x
.length());
44
}
45
46
distance
= between(
x
,
w
);
47
if
(0 ==
distance
) {
48
return
set(
key
, 1);
49
}
50
51
std::size_t min_distance =
distance
;
52
53
distance
= between(
v
,
y
);
54
if
(0 ==
distance
) {
55
return
set(
key
, 1);
56
}
57
58
if
(
distance
< min_distance) {
59
min_distance =
distance
;
60
}
61
62
distance
= between(
x
,
y
);
63
if
(0 ==
distance
) {
64
return
set(
key
, 1);
65
}
66
67
if
(
distance
< min_distance) {
68
min_distance =
distance
;
69
}
70
71
if
(
w
.length() > 1) {
72
distance
= between(
x
, f(
w
, 1));
73
74
if
(0 ==
distance
) {
75
return
set(
key
, 1);
76
}
77
78
if
(
distance
< min_distance) {
79
min_distance =
distance
;
80
}
81
}
82
83
if
(
v
.length() > 1) {
84
distance
= between(f(
v
, 1),
y
);
85
86
if
(0 ==
distance
) {
87
return
set(
key
, 1);
88
}
89
90
if
(
distance
< min_distance) {
91
min_distance =
distance
;
92
}
93
}
94
95
return
set(
key
, 1 + min_distance);
96
}
97
98
}
// namespace liblevenshtein::distance
liblevenshtein::distance::MergeAndSplitDistance::between
auto between(std::string v, std::string w) -> std::size_t override
Measures the edit distance between two terms.
Definition
merge_and_split_distance.cpp:6
liblevenshtein::distance::SymmetricPair
Represents a pair of terms sorted, lexicographically, in ascending order.
Definition
symmetric_pair.h:12
query
void query(ll::Dawg *dawg, const std::string &query_term, std::size_t max_distance)
Definition
main.cpp:25
merge_and_split_distance.h
liblevenshtein::distance
Memoized, recursive distance metrics typically used to evaluate the correctness of Levenshtein automa...
Definition
namespaces.dox:16
liblevenshtein::distance
auto distance(State *state, std::size_t query_length) -> std::size_t
Infers the Levenshtein distance from the given State and query length.
symmetric_pair.h
src
liblevenshtein
distance
merge_and_split_distance.cpp
Generated by
1.10.0