From d8858fb17d449342f16bedfca4f0453fa60903f9 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Fri, 7 Sep 2018 13:38:24 +0200 Subject: [PATCH] fix different results of automaton vs dynamic programming distance simulation --- .../src/stringology/matching/LevenshteinMatchingAutomaton.h | 6 ++---- .../GeneralizedLevenshteinMatchingAutomatonTest.cpp | 3 +++ .../GeneralizedLevenshteinSequenceMatchingAutomatonTest.cpp | 3 +++ .../matching/LevenshteinMatchingAutomatonTest.cpp | 3 +++ .../matching/LevenshteinSequenceMatchingAutomatonTest.cpp | 3 +++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/alib2algo/src/stringology/matching/LevenshteinMatchingAutomaton.h b/alib2algo/src/stringology/matching/LevenshteinMatchingAutomaton.h index 301e253f19..05a8f059d6 100644 --- a/alib2algo/src/stringology/matching/LevenshteinMatchingAutomaton.h +++ b/alib2algo/src/stringology/matching/LevenshteinMatchingAutomaton.h @@ -60,10 +60,8 @@ automaton::EpsilonNFA < SymbolType, void, ext::pair<unsigned int, unsigned int> to = ext::make_pair(i, j + 1); for (const SymbolType& symbol : pattern.getAlphabet()) { - if (symbol != pattern.getContent()[i]) { - // add horizontal transition representing insertion - result.addTransition(from, symbol, to); - } + // add horizontal transition representing insertion + result.addTransition(from, symbol, to); } } } diff --git a/alib2algo/test-src/stringology/matching/GeneralizedLevenshteinMatchingAutomatonTest.cpp b/alib2algo/test-src/stringology/matching/GeneralizedLevenshteinMatchingAutomatonTest.cpp index c41b2c2f2c..d7d3f42196 100644 --- a/alib2algo/test-src/stringology/matching/GeneralizedLevenshteinMatchingAutomatonTest.cpp +++ b/alib2algo/test-src/stringology/matching/GeneralizedLevenshteinMatchingAutomatonTest.cpp @@ -78,15 +78,18 @@ void GeneralizedLevenshteinMatchingAutomatonTest::testSimpleConstruction() { res.addTransition(q5, q8); res.addTransition(q1, 'a', q4); // insertions + res.addTransition(q1, 'b', q4); res.addTransition(q1, 'c', q4); res.addTransition(q1, 'd', q4); res.addTransition(q2, 'a', q5); res.addTransition(q2, 'b', q5); + res.addTransition(q2, 'c', q5); res.addTransition(q2, 'd', q5); res.addTransition(q5, 'a', q7); res.addTransition(q5, 'b', q7); + res.addTransition(q5, 'c', q7); res.addTransition(q5, 'd', q7); res.addTransition(q0, 'b', r1); // transposition diff --git a/alib2algo/test-src/stringology/matching/GeneralizedLevenshteinSequenceMatchingAutomatonTest.cpp b/alib2algo/test-src/stringology/matching/GeneralizedLevenshteinSequenceMatchingAutomatonTest.cpp index 27104a1fc3..01e2aa26ae 100644 --- a/alib2algo/test-src/stringology/matching/GeneralizedLevenshteinSequenceMatchingAutomatonTest.cpp +++ b/alib2algo/test-src/stringology/matching/GeneralizedLevenshteinSequenceMatchingAutomatonTest.cpp @@ -77,15 +77,18 @@ void GeneralizedLevenshteinSequenceMatchingAutomatonTest::testSimpleConstruction test.addTransition(q5, q8); test.addTransition(q1, 'a', q4); // insertions + test.addTransition(q1, 'b', q4); test.addTransition(q1, 'c', q4); test.addTransition(q1, 'd', q4); test.addTransition(q2, 'a', q5); test.addTransition(q2, 'b', q5); + test.addTransition(q2, 'c', q5); test.addTransition(q2, 'd', q5); test.addTransition(q5, 'a', q7); test.addTransition(q5, 'b', q7); + test.addTransition(q5, 'c', q7); test.addTransition(q5, 'd', q7); test.addTransition(q1, 'a', q1); // loops for sequence matching diff --git a/alib2algo/test-src/stringology/matching/LevenshteinMatchingAutomatonTest.cpp b/alib2algo/test-src/stringology/matching/LevenshteinMatchingAutomatonTest.cpp index b5a5a21057..4b5726e0d3 100644 --- a/alib2algo/test-src/stringology/matching/LevenshteinMatchingAutomatonTest.cpp +++ b/alib2algo/test-src/stringology/matching/LevenshteinMatchingAutomatonTest.cpp @@ -74,15 +74,18 @@ void LevenshteinMatchingAutomatonTest::testSimpleConstruction() { res.addTransition(q5, q8); res.addTransition(q1, 'a', q4); // insertions + res.addTransition(q1, 'b', q4); res.addTransition(q1, 'c', q4); res.addTransition(q1, 'd', q4); res.addTransition(q2, 'a', q5); res.addTransition(q2, 'b', q5); + res.addTransition(q2, 'c', q5); res.addTransition(q2, 'd', q5); res.addTransition(q5, 'a', q7); res.addTransition(q5, 'b', q7); + res.addTransition(q5, 'c', q7); res.addTransition(q5, 'd', q7); CPPUNIT_ASSERT(res == automaton::simplify::UnreachableStatesRemover::remove(resulting_automata)); diff --git a/alib2algo/test-src/stringology/matching/LevenshteinSequenceMatchingAutomatonTest.cpp b/alib2algo/test-src/stringology/matching/LevenshteinSequenceMatchingAutomatonTest.cpp index 7bb6061bf1..88bdb69167 100644 --- a/alib2algo/test-src/stringology/matching/LevenshteinSequenceMatchingAutomatonTest.cpp +++ b/alib2algo/test-src/stringology/matching/LevenshteinSequenceMatchingAutomatonTest.cpp @@ -73,14 +73,17 @@ void LevenshteinSequenceMatchingAutomatonTest::testSimpleConstruction() { test.addTransition(q5, q8); test.addTransition(q1, 'a', q4); // insertions + test.addTransition(q1, 'b', q4); test.addTransition(q1, 'c', q4); test.addTransition(q1, 'd', q4); test.addTransition(q2, 'a', q5); test.addTransition(q2, 'b', q5); + test.addTransition(q2, 'c', q5); test.addTransition(q2, 'd', q5); test.addTransition(q5, 'a', q7); + test.addTransition(q5, 'c', q7); test.addTransition(q5, 'b', q7); test.addTransition(q5, 'd', q7); -- GitLab