Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
GeneralizedLevenshteinMatchingAutomaton.h
Go to the documentation of this file.
1
6#pragma once
7
9#include <string/LinearString.h>
12
13
14namespace stringology {
15
16namespace matching {
17
19public:
25 template < class SymbolType >
27
33 template < class SymbolType >
35};
36
37
38template < class SymbolType >
41
42 for (unsigned int j = 0; j<allowed_errors; j++) {
43 for (unsigned int i = j; i + 1 < pattern.getContent().size(); i++) {
44 auto from = ext::make_pair(i, j);
45 auto transpose_state = ext::make_pair(pattern.getContent().size()+1+i, j);
46 auto to = ext::make_pair(i+2, j+1);
47
48 result.addState(transpose_state);
49 result.addTransition(from, pattern.getContent()[i+1], transpose_state);
50 result.addTransition(transpose_state, pattern.getContent()[i], to);
51 }
52 }
53
54 return result;
55}
56
57template < class SymbolType >
60
61 ext::set<SymbolType> alphabet_without_wildcard = pattern.getAlphabet();
62 alphabet_without_wildcard.erase(pattern.getWildcardSymbol());
63
64 for (unsigned int j = 0; j<allowed_errors; j++) {
65 for (unsigned int i = j; i + 1 < pattern.getContent().size(); i++) {
66 auto from = ext::make_pair(i, j);
67 auto transpose_state = ext::make_pair(pattern.getContent().size()+1+i, j);
68 auto to = ext::make_pair(i+2, j+1);
69
70 result.addState(transpose_state);
71 if (pattern.getContent()[i+1] == pattern.getWildcardSymbol() ) {
72 for(const SymbolType & symbol : alphabet_without_wildcard) {
73 result.addTransition(from, symbol, transpose_state);
74 }
75 } else {
76 result.addTransition(from, pattern.getContent()[i+1], transpose_state);
77 }
78
79 if (pattern.getContent()[i] == pattern.getWildcardSymbol()) {
80 for(const SymbolType & symbol : alphabet_without_wildcard) {
81 result.addTransition(transpose_state, symbol, to);
82 }
83 } else {
84 result.addTransition(transpose_state, pattern.getContent()[i], to);
85 }
86 }
87 }
88
89 return result;
90}
91
92
93} /* namespace matching */
94
95} /* namespace stringology */
96
Epsilon nondeterministic finite automaton. Accepts regular languages.
Definition: EpsilonNFA.h:74
Definition: set.hpp:44
Linear string.
Definition: LinearString.h:57
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
Definition: GeneralizedLevenshteinMatchingAutomaton.h:18
static automaton::EpsilonNFA< SymbolType, ext::pair< unsigned int, unsigned int > > construct(const string::LinearString< SymbolType > &pattern, unsigned int allowed_errors)
Definition: GeneralizedLevenshteinMatchingAutomaton.h:39
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