Skip to content
Snippets Groups Projects
Commit f0c491da authored by Tomas Capek's avatar Tomas Capek
Browse files

Implement simulation for aproximate string matching using dynamic programming...

Implement simulation for aproximate string matching using dynamic programming and Levenshtein distance.
parent cc40bf3c
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@
#define _LEVENSHTEIN_DYNAMIC_PROGRAMMING_H__
 
#include <algorithm>
#include <limits.h>
 
#include <string/LinearString.h>
 
......@@ -46,13 +47,14 @@ ext::vector<ext::vector<unsigned int>> LevenshteinDynamicProgramming::compute_ta
value_a = table[j-1][i-1] + 1;
}
 
unsigned int value_b;
unsigned int value_b = UINT_MAX;
if(j < pattern.getContent().size()) {
value_b = table[j][i-1] + 1;
} else {
value_b = table[j-1][i] + 1;
}
 
value_b = std::min(table[j-1][i] + 1, value_b);
table[j][i] = std::min({value_a, value_b});
}
}
......
......@@ -11,23 +11,13 @@ void LevenshteinDynamicProgrammingTest::testTableConstruction() {
auto pattern = string::LinearString<>("adbbca");
 
ext::vector<ext::vector<unsigned int>> expected_result = {
ext::vector<unsigned int>({0, 1, 2, 3, 4, 5, 6}),
ext::vector<unsigned int>({0, 0, 1, 2, 3, 4, 5}),
ext::vector<unsigned int>({0, 1, 0, 1, 2, 3, 4}),
ext::vector<unsigned int>({0, 1, 1, 1, 2, 2, 3}),
ext::vector<unsigned int>({0, 0, 1, 2, 2, 3, 2}),
ext::vector<unsigned int>({0, 1, 1, 1, 2, 3, 4}),
ext::vector<unsigned int>({0, 1, 2, 2, 2, 2, 3}),
ext::vector<unsigned int>({0, 0, 1, 2, 3, 3, 2}),
ext::vector<unsigned int>({0, 0, 1, 2, 3, 4, 3}),
ext::vector<unsigned int>({0, 1, 1, 1, 2, 3, 4}),
ext::vector<unsigned int>({0, 0, 1, 2, 2, 3, 3}),
ext::vector<unsigned int>({0, 1, 0, 1, 2, 3, 4}),
ext::vector<unsigned int>({0, 1, 1, 0, 1, 2, 3}),
ext::vector<unsigned int>({0, 1, 2, 1, 0, 1, 2}),
ext::vector<unsigned int>({0, 1, 2, 2, 1, 0, 1}),
ext::vector<unsigned int>({0, 0, 1, 2, 2, 1, 0}),
ext::vector<unsigned int>({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}),
ext::vector<unsigned int>({1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0}),
ext::vector<unsigned int>({2, 1, 0, 1, 1, 1, 2, 1, 1, 1, 1, 0, 1, 2, 2, 1}),
ext::vector<unsigned int>({3, 2, 1, 1, 2, 1, 2, 2, 2, 1, 2, 1, 0, 1, 2, 2}),
ext::vector<unsigned int>({4, 3, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 1, 0, 1, 2}),
ext::vector<unsigned int>({5, 4, 3, 2, 3, 3, 2, 3, 4, 3, 3, 3, 2, 1, 0, 1}),
ext::vector<unsigned int>({6, 5, 4, 3, 2, 4, 3, 2, 3, 4, 3, 4, 3, 2, 1, 0}),
};
 
CPPUNIT_ASSERT(expected_result == stringology::simulations::LevenshteinDynamicProgramming::compute_table(text, pattern));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment