summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
authorGeir Storli <geirst@yahooinc.com>2022-03-25 15:44:59 +0000
committerGeir Storli <geirst@yahooinc.com>2022-03-25 15:44:59 +0000
commit37508626ed6a22bbbf053add1d2065ff16d261c3 (patch)
tree08814e828e4c2c4b7a16bf7df12ffa0d1b3d4ea0 /vespalib
parentdbeb8290c852403d7af19690d5213fa2731487cd (diff)
Fix typo (levenstein -> levenshtein).
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/tests/fuzzy/CMakeLists.txt6
-rw-r--r--vespalib/src/tests/fuzzy/levenshtein_distance_test.cpp (renamed from vespalib/src/tests/fuzzy/levenstein_distance_test.cpp)8
-rw-r--r--vespalib/src/vespa/vespalib/fuzzy/CMakeLists.txt2
-rw-r--r--vespalib/src/vespa/vespalib/fuzzy/fuzzy_matcher.cpp4
-rw-r--r--vespalib/src/vespa/vespalib/fuzzy/fuzzy_matcher.h2
-rw-r--r--vespalib/src/vespa/vespalib/fuzzy/levenshtein_distance.cpp (renamed from vespalib/src/vespa/vespalib/fuzzy/levenstein_distance.cpp)10
-rw-r--r--vespalib/src/vespa/vespalib/fuzzy/levenshtein_distance.h (renamed from vespalib/src/vespa/vespalib/fuzzy/levenstein_distance.h)4
7 files changed, 18 insertions, 18 deletions
diff --git a/vespalib/src/tests/fuzzy/CMakeLists.txt b/vespalib/src/tests/fuzzy/CMakeLists.txt
index 2a415a9ad62..bc48e775711 100644
--- a/vespalib/src/tests/fuzzy/CMakeLists.txt
+++ b/vespalib/src/tests/fuzzy/CMakeLists.txt
@@ -8,11 +8,11 @@ vespa_add_executable(vespalib_fuzzy_matcher_test_app TEST
)
vespa_add_test(NAME vespalib_fuzzy_matcher_test_app COMMAND vespalib_fuzzy_matcher_test_app)
-vespa_add_executable(vespalib_levenstein_distance_test_app TEST
+vespa_add_executable(vespalib_levenshtein_distance_test_app TEST
SOURCES
- levenstein_distance_test.cpp
+ levenshtein_distance_test.cpp
DEPENDS
vespalib
GTest::GTest
)
-vespa_add_test(NAME vespalib_levenstein_distance_test_app COMMAND vespalib_levenstein_distance_test_app) \ No newline at end of file
+vespa_add_test(NAME vespalib_levenshtein_distance_test_app COMMAND vespalib_levenshtein_distance_test_app)
diff --git a/vespalib/src/tests/fuzzy/levenstein_distance_test.cpp b/vespalib/src/tests/fuzzy/levenshtein_distance_test.cpp
index efdcc82fce1..7869f5acd66 100644
--- a/vespalib/src/tests/fuzzy/levenstein_distance_test.cpp
+++ b/vespalib/src/tests/fuzzy/levenshtein_distance_test.cpp
@@ -1,6 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-#include <vespa/vespalib/fuzzy/levenstein_distance.h>
+#include <vespa/vespalib/fuzzy/levenshtein_distance.h>
#include <vespa/vespalib/text/lowercase.h>
#include <vespa/vespalib/gtest/gtest.h>
@@ -8,15 +8,15 @@ std::optional<uint32_t> calculate(std::string_view left, std::string_view right,
std::vector<uint32_t> leftCodepoints = vespalib::LowerCase::convert_to_ucs4(left);
std::vector<uint32_t> rightCodepoints = vespalib::LowerCase::convert_to_ucs4(right);
- std::optional<uint32_t> leftRight = vespalib::LevensteinDistance::calculate(leftCodepoints,rightCodepoints, threshold);
- std::optional<uint32_t> rightLeft = vespalib::LevensteinDistance::calculate(rightCodepoints,leftCodepoints, threshold);
+ std::optional<uint32_t> leftRight = vespalib::LevenshteinDistance::calculate(leftCodepoints, rightCodepoints, threshold);
+ std::optional<uint32_t> rightLeft = vespalib::LevenshteinDistance::calculate(rightCodepoints, leftCodepoints, threshold);
EXPECT_EQ(leftRight, rightLeft); // should be independent whether left or right strings are swapped
return leftRight;
}
-TEST(LevensteinDistance, calculate_edgecases) {
+TEST(LevenshteinDistance, calculate_edgecases) {
EXPECT_EQ(calculate("abc", "abc", 2), std::optional{0});
EXPECT_EQ(calculate("abc", "ab1", 2), std::optional{1});
EXPECT_EQ(calculate("abc", "1bc", 2), std::optional{1});
diff --git a/vespalib/src/vespa/vespalib/fuzzy/CMakeLists.txt b/vespalib/src/vespa/vespalib/fuzzy/CMakeLists.txt
index 0f7583da1d7..1d770163e06 100644
--- a/vespalib/src/vespa/vespalib/fuzzy/CMakeLists.txt
+++ b/vespalib/src/vespa/vespalib/fuzzy/CMakeLists.txt
@@ -2,7 +2,7 @@
vespa_add_library(vespalib_vespalib_fuzzy OBJECT
SOURCES
fuzzy_matcher.cpp
- levenstein_distance.cpp
+ levenshtein_distance.cpp
DEPENDS
)
diff --git a/vespalib/src/vespa/vespalib/fuzzy/fuzzy_matcher.cpp b/vespalib/src/vespa/vespalib/fuzzy/fuzzy_matcher.cpp
index 495e08c42e3..e170f83c541 100644
--- a/vespalib/src/vespa/vespalib/fuzzy/fuzzy_matcher.cpp
+++ b/vespalib/src/vespa/vespalib/fuzzy/fuzzy_matcher.cpp
@@ -1,7 +1,7 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "fuzzy_matcher.h"
-#include "levenstein_distance.h"
+#include "levenshtein_distance.h"
#include <vespa/vespalib/text/lowercase.h>
#include <vespa/vespalib/text/utf8.h>
@@ -13,7 +13,7 @@ vespalib::FuzzyMatcher vespalib::FuzzyMatcher::from_term(std::string_view term)
bool vespalib::FuzzyMatcher::isMatch(std::string_view target) const {
std::vector<uint32_t> targetCodepoints = LowerCase::convert_to_ucs4(target);
- return LevensteinDistance::calculate(
+ return LevenshteinDistance::calculate(
_folded_term_codepoints,
targetCodepoints,
_max_edit_distance).has_value();
diff --git a/vespalib/src/vespa/vespalib/fuzzy/fuzzy_matcher.h b/vespalib/src/vespa/vespalib/fuzzy/fuzzy_matcher.h
index bfcf98d79fd..d4ee0e6d40f 100644
--- a/vespalib/src/vespa/vespalib/fuzzy/fuzzy_matcher.h
+++ b/vespalib/src/vespa/vespalib/fuzzy/fuzzy_matcher.h
@@ -9,7 +9,7 @@
namespace vespalib {
/**
- * Fuzzy matching between a lowercased instances of query and document terms based on Levenstein distance.
+ * Fuzzy matching between lowercased instances of query and document terms based on Levenshtein distance.
* Class has two main parameters:
* - prefix size, i.e the size of the prefix that is considered frozen.
* - max edit distance, i.e an upper bound for edit distance for it to be a match between terms
diff --git a/vespalib/src/vespa/vespalib/fuzzy/levenstein_distance.cpp b/vespalib/src/vespa/vespalib/fuzzy/levenshtein_distance.cpp
index 5ee0f2d4a2d..86ced3e52db 100644
--- a/vespalib/src/vespa/vespalib/fuzzy/levenstein_distance.cpp
+++ b/vespalib/src/vespa/vespalib/fuzzy/levenshtein_distance.cpp
@@ -1,11 +1,13 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// Levenstein distance algorithm is based off Java implementation from apache commons-text library licensed under the Apache 2.0 license.
+// Levenshtein distance algorithm is based off Java implementation from apache commons-text library licensed under the Apache 2.0 license.
-#include "levenstein_distance.h"
+#include "levenshtein_distance.h"
#include <limits>
-std::optional<uint32_t> vespalib::LevensteinDistance::calculate(const std::vector<uint32_t>& left, const std::vector<uint32_t>& right, uint32_t threshold) {
+std::optional<uint32_t>
+vespalib::LevenshteinDistance::calculate(const std::vector<uint32_t>& left, const std::vector<uint32_t>& right, uint32_t threshold)
+{
uint32_t n = left.size();
uint32_t m = right.size();
@@ -22,7 +24,6 @@ std::optional<uint32_t> vespalib::LevensteinDistance::calculate(const std::vecto
return n <= threshold ? std::optional(n) : std::nullopt;
}
-
// the edit distance cannot be less than the length difference
if (m - n > threshold) {
return std::nullopt;
@@ -69,7 +70,6 @@ std::optional<uint32_t> vespalib::LevensteinDistance::calculate(const std::vecto
} else {
// 1 + minimum of cell to the left, to the top, diagonally
// left and up
-
d[i] = 1 + std::min(std::min(d[i - 1], p[i]), p[i - 1]);
}
lowerBound = std::min(lowerBound, d[i]);
diff --git a/vespalib/src/vespa/vespalib/fuzzy/levenstein_distance.h b/vespalib/src/vespa/vespalib/fuzzy/levenshtein_distance.h
index bce7599fc23..311211aba7a 100644
--- a/vespalib/src/vespa/vespalib/fuzzy/levenstein_distance.h
+++ b/vespalib/src/vespa/vespalib/fuzzy/levenshtein_distance.h
@@ -8,7 +8,7 @@
namespace vespalib {
/**
- * LevensteinDistance::calculate implements basic Levenstein distance algorithm
+ * LevenshteinDistance::calculate implements basic Levenshtein distance algorithm
* with early stopping if the distance is already too high.
* If the distance is above threshold method would return empty optional,
* if the distance is below or equal to it, the distance will be wrapped in optional.
@@ -17,7 +17,7 @@ namespace vespalib {
*
* Algorithm is based off Java implementation from commons-text library
*/
-class LevensteinDistance {
+class LevenshteinDistance {
public:
static std::optional<uint32_t> calculate(const std::vector<uint32_t>& left, const std::vector<uint32_t>& right, uint32_t threshold);
};