Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
LevenshteinMatchingAutomaton.h
Go to the documentation of this file.
1
6#pragma once
7
10#include <string/LinearString.h>
13
14
15namespace stringology {
16
17namespace matching {
18
20public:
26 template < class SymbolType >
28
34 template < class SymbolType >
36};
37
38
39template < class SymbolType >
41 auto hamming_matching_automaton = stringology::matching::HammingMatchingAutomaton::construct(pattern, allowed_errors);
42
44
45 for (unsigned int j = 0; j<allowed_errors; j++) {
46 for (unsigned int i = j; i<pattern.getContent().size(); i++) {
47 auto from = ext::make_pair(i, j);
48 auto to = ext::make_pair(i + 1, j + 1);
49
50 // add diagonal transition representing deletion
51 result.addTransition(from, to);
52
53 if (i == j) {
54 continue;
55 }
56
57 to = ext::make_pair(i, j + 1);
58
59 for (const SymbolType& symbol : pattern.getAlphabet()) {
60 // add horizontal transition representing insertion
61 result.addTransition(from, symbol, to);
62 }
63 }
64 }
65
66 return result;
67}
68
69
70template < class SymbolType >
72 auto hamming_matching_automaton = stringology::matching::HammingMatchingAutomaton::construct(pattern, allowed_errors);
73
75
76 ext::set<SymbolType> alphabet_without_wildcard = pattern.getAlphabet();
77 alphabet_without_wildcard.erase(pattern.getWildcardSymbol());
78
79 for (unsigned int j = 0; j<allowed_errors; j++) {
80 for (unsigned int i = j; i<pattern.getContent().size(); i++) {
81 auto from = ext::make_pair(i, j);
82 auto to = ext::make_pair(i + 1, j + 1);
83
84 // add diagonal transition representing deletion
85 result.addTransition(from, to);
86
87 if (i == j) {
88 continue;
89 }
90
91 to = ext::make_pair(i, j + 1);
92
93 for (const SymbolType& symbol : alphabet_without_wildcard) {
94 // add horizontal transition representing insertion
95 result.addTransition(from, symbol, to);
96 }
97 }
98 }
99
100 return result;
101}
102
103
104
105} /* namespace matching */
106
107} /* namespace stringology */
108
Epsilon nondeterministic finite automaton. Accepts regular languages.
Definition: EpsilonNFA.h:74
Definition: set.hpp:44
Linear string.
Definition: LinearString.h:57
const ext::set< SymbolType > & getAlphabet() const &
Definition: LinearString.h:103
const ext::vector< SymbolType > & getContent() const &
Definition: LinearString.h:238
Linear wildcard string.
Definition: WildcardLinearString.h:44
const ext::vector< SymbolType > & getContent() const &
Definition: WildcardLinearString.h:279
const SymbolType & getWildcardSymbol() const &
Definition: WildcardLinearString.h:139
const ext::set< SymbolType > & getAlphabet() const &
Definition: WildcardLinearString.h:112
static automaton::NFA< SymbolType, ext::pair< unsigned int, unsigned int > > construct(const string::LinearString< SymbolType > &pattern, unsigned int allowed_errors)
Definition: HammingMatchingAutomaton.h:39
Definition: LevenshteinMatchingAutomaton.h:19
static automaton::EpsilonNFA< SymbolType, ext::pair< unsigned int, unsigned int > > construct(const string::LinearString< SymbolType > &pattern, unsigned int allowed_errors)
Definition: LevenshteinMatchingAutomaton.h:40
int i
Definition: AllEpsilonClosure.h:118
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
for(const StateType &state :fsm.getStates()) renamingData.insert(std Rename::RenamedAutomaton< T > result(renamingData.at(fsm.getInitialState()))
Definition: Rename.h:253
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: ArithmeticCompression.h:18