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

Rework simulation of Levenshtein searching automaton.

parent 20eaab0d
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,8 @@ public: ...@@ -22,6 +22,8 @@ public:
template <class SymbolType> template <class SymbolType>
static ext::vector<ext::vector<unsigned int>> compute_table(const string::LinearString<SymbolType> & text, const string::LinearString<SymbolType> & pattern); static ext::vector<ext::vector<unsigned int>> compute_table(const string::LinearString<SymbolType> & text, const string::LinearString<SymbolType> & pattern);
   
template <class SymbolType>
static ext::set<unsigned int> search(const string::LinearString<SymbolType> & text, const string::LinearString<SymbolType> & pattern, unsigned int errors);
}; };
   
#include <iostream> #include <iostream>
...@@ -59,11 +61,22 @@ ext::vector<ext::vector<unsigned int>> LevenshteinDynamicProgramming::compute_ta ...@@ -59,11 +61,22 @@ ext::vector<ext::vector<unsigned int>> LevenshteinDynamicProgramming::compute_ta
} }
} }
   
for(const auto & row : table) { return table;
std::cout << row << std::endl; }
template <class SymbolType>
ext::set<unsigned int> LevenshteinDynamicProgramming::search(const string::LinearString<SymbolType> & text, const string::LinearString<SymbolType> & pattern, unsigned int errors) {
auto table = LevenshteinDynamicProgramming::compute_table(text, pattern);
ext::set<unsigned int> result;
for(unsigned int i = 0; i<= text.getContent().size(); i++) {
if(table[pattern.getContent().size()][i] <= errors) {
result.insert(i-1);
}
} }
   
return table; return result;
} }
   
   
......
...@@ -23,6 +23,14 @@ void LevenshteinDynamicProgrammingTest::testTableConstruction() { ...@@ -23,6 +23,14 @@ void LevenshteinDynamicProgrammingTest::testTableConstruction() {
CPPUNIT_ASSERT(expected_result == stringology::simulations::LevenshteinDynamicProgramming::compute_table(text, pattern)); CPPUNIT_ASSERT(expected_result == stringology::simulations::LevenshteinDynamicProgramming::compute_table(text, pattern));
} }
   
void LevenshteinDynamicProgrammingTest::testSearch() {
auto text = string::LinearString<>("adcabcaabadbbca");
auto pattern = string::LinearString<>("adbbca");
ext::set<unsigned int> expected_result = {2, 3, 5, 6, 7, 9, 11, 12, 13, 14};
auto result = stringology::simulations::LevenshteinDynamicProgramming::search(text, pattern, 3);
CPPUNIT_ASSERT(expected_result == result);
}
   
void LevenshteinDynamicProgrammingTest::setUp() { } void LevenshteinDynamicProgrammingTest::setUp() { }
   
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
class LevenshteinDynamicProgrammingTest : public CppUnit::TestFixture { class LevenshteinDynamicProgrammingTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(LevenshteinDynamicProgrammingTest); CPPUNIT_TEST_SUITE(LevenshteinDynamicProgrammingTest);
CPPUNIT_TEST(testTableConstruction); CPPUNIT_TEST(testTableConstruction);
CPPUNIT_TEST(testSearch);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
   
public: public:
...@@ -13,5 +14,6 @@ public: ...@@ -13,5 +14,6 @@ public:
void tearDown ( ); void tearDown ( );
   
void testTableConstruction(); void testTableConstruction();
void testSearch();
}; };
#endif // LEVENSHTEIN_DYNAMIC_PROGRAMMING_TEST_H_ #endif // LEVENSHTEIN_DYNAMIC_PROGRAMMING_TEST_H_
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