Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
GeneralizedLevenshteinSequenceMatchingAutomaton.h
Go to the documentation of this file.
1
6#pragma once
7
10#include <string/LinearString.h>
11
12
13namespace stringology {
14
15namespace matching {
16
18public:
24 template < class SymbolType >
26
32 template < class SymbolType >
34
35};
36
37template < class SymbolType >
40
41 for (unsigned int j = 0; j<allowed_errors + 1; j++) {
42 for (unsigned int i = j; i<pattern.getContent().size(); i++) {
43 auto current_state = ext::make_pair(i, j);
44
45 for (const SymbolType & symbol : pattern.getAlphabet()) {
46 if (symbol != pattern.getContent()[i]) {
47 result.addTransition(current_state, symbol, current_state);
48 }
49 }
50 }
51 }
52
53 for (unsigned int j = 0; j<allowed_errors; j++) {
54 for (unsigned int i = j; i + 1 < pattern.getContent().size(); i++) {
55 auto transpose_state = ext::make_pair(pattern.getContent().size()+1+i, j);
56
57 for (const SymbolType & symbol : pattern.getAlphabet()) {
58 if (symbol != pattern.getContent()[i]) {
59 result.addTransition(transpose_state, symbol, transpose_state);
60 }
61 }
62 }
63 }
64
65 return result;
66}
67
68template < class SymbolType >
71
72 const SymbolType& wildcard = pattern.getWildcardSymbol();
73 ext::set<SymbolType> alphabet_without_wildcard = pattern.getAlphabet();
74 alphabet_without_wildcard.erase(wildcard);
75
76 for (unsigned int j = 0; j<allowed_errors + 1; j++) {
77 for (unsigned int i = j; i<pattern.getContent().size(); i++) {
78 auto current_state = ext::make_pair(i, j);
79
80 if (pattern.getContent()[i] != wildcard) {
81 for (const SymbolType & symbol : alphabet_without_wildcard) {
82 if (symbol != pattern.getContent()[i]) {
83 result.addTransition(current_state, symbol, current_state);
84 }
85 }
86 }
87 }
88 }
89
90 for (unsigned int j = 0; j<allowed_errors; j++) {
91 for (unsigned int i = j; i + 1 < pattern.getContent().size(); i++) {
92 if (pattern.getContent()[i] == wildcard) {
93 continue;
94 }
95
96 auto transpose_state = ext::make_pair(pattern.getContent().size()+1+i, j);
97
98 for (const SymbolType & symbol : alphabet_without_wildcard) {
99 if (symbol != pattern.getContent()[i]) {
100 result.addTransition(transpose_state, symbol, transpose_state);
101 }
102 }
103 }
104 }
105
106 return result;
107}
108
109
110
111} /* namespace matching */
112
113} /* namespace stringology */
114
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::EpsilonNFA< SymbolType, ext::pair< unsigned int, unsigned int > > construct(const string::LinearString< SymbolType > &pattern, unsigned int allowed_errors)
Definition: GeneralizedLevenshteinMatchingAutomaton.h:39
Definition: GeneralizedLevenshteinSequenceMatchingAutomaton.h:17
static automaton::EpsilonNFA< SymbolType, ext::pair< unsigned int, unsigned int > > construct(const string::LinearString< SymbolType > &pattern, unsigned int allowed_errors)
Definition: GeneralizedLevenshteinSequenceMatchingAutomaton.h:38
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