Skip to content
Snippets Groups Projects
Commit 431b7403 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

update construction of approximate matching automata

parent b64034dd
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -37,12 +37,14 @@ public:
 
template < class SymbolType >
automaton::NFA < SymbolType, ext::pair<unsigned int, unsigned int> > HammingMatchingAutomaton::construct(const string::LinearString < SymbolType > & pattern, unsigned int allowed_errors) {
automaton::NFA < SymbolType, ext::pair<unsigned int, unsigned int > > result( ext::make_pair(0, 0) );
auto initial_state = ext::make_pair(0, 0);
automaton::NFA < SymbolType, ext::pair<unsigned int, unsigned int > > result ( initial_state );
result.setInputAlphabet(pattern.getAlphabet());
 
// add k+1 paralel automatas (sfoeco type = exact matching) (where k is allowed_errors)
for (unsigned int i = 0; i<pattern.getContent().size() + 1; i++) {
for (unsigned int j = 0; j<allowed_errors + 1; j++) {
for (unsigned int j = 0; j<allowed_errors + 1; j++) {
for (unsigned int i = j; i<pattern.getContent().size() + 1; i++) {
result.addState(ext::make_pair(i, j));
if (i == pattern.getContent().size()) {
result.addFinalState(ext::make_pair(i, j));
......@@ -50,15 +52,12 @@ automaton::NFA < SymbolType, ext::pair<unsigned int, unsigned int> > HammingMatc
}
}
 
for (unsigned int i = 0; i<allowed_errors + 1; i++) {
for (const SymbolType& symbol : pattern.getAlphabet()) {
auto initial_state = ext::make_pair(0, i);
result.addTransition(initial_state, symbol, initial_state);
}
for (const SymbolType& symbol : pattern.getAlphabet()) {
result.addTransition(initial_state, symbol, initial_state);
}
 
for (unsigned int i = 0; i<pattern.getContent().size(); i++) {
for (unsigned int j = 0; j < allowed_errors + 1; j++) {
for (unsigned int j = 0; j < allowed_errors + 1; j++) {
for (unsigned int i = j; i<pattern.getContent().size(); i++) {
auto from = ext::make_pair(i, j);
auto to = ext::make_pair(i+1, j);
result.addTransition(from, pattern.getContent()[i], to);
......@@ -66,8 +65,8 @@ automaton::NFA < SymbolType, ext::pair<unsigned int, unsigned int> > HammingMatc
}
 
// add diagonal addTransition
for (unsigned int i = 0; i<pattern.getContent().size(); i++) {
for (unsigned int j = 0; j<allowed_errors; j++) {
for (unsigned int j = 0; j<allowed_errors; j++) {
for (unsigned int i = j; i<pattern.getContent().size(); i++) {
auto from = ext::make_pair(i, j);
auto to = ext::make_pair(i + 1, j + 1);
 
......@@ -86,7 +85,9 @@ automaton::NFA < SymbolType, ext::pair<unsigned int, unsigned int> > HammingMatc
 
template < class SymbolType >
automaton::NFA < SymbolType, ext::pair<unsigned int, unsigned int> > HammingMatchingAutomaton::construct(const string::WildcardLinearString < SymbolType > & pattern, unsigned int allowed_errors) {
automaton::NFA < SymbolType, ext::pair<unsigned int, unsigned int > > result( ext::make_pair(0, 0) );
auto initial_state = ext::make_pair(0, 0);
automaton::NFA < SymbolType, ext::pair<unsigned int, unsigned int > > result ( initial_state );
result.setInputAlphabet(pattern.getAlphabet());
 
SymbolType wildcard = pattern.getWildcardSymbol();
......@@ -94,8 +95,8 @@ automaton::NFA < SymbolType, ext::pair<unsigned int, unsigned int> > HammingMatc
alphabet_without_wildcard.erase(wildcard);
 
// add k+1 paralel automatas (sfoeco type = exact matching) (where k is allowed_errors)
for (unsigned int i = 0; i<pattern.getContent().size() + 1; i++) {
for (unsigned int j = 0; j<allowed_errors + 1; j++) {
for (unsigned int j = 0; j<allowed_errors + 1; j++) {
for (unsigned int i = j; i<pattern.getContent().size() + 1; i++) {
result.addState(ext::make_pair(i, j));
if (i == pattern.getContent().size()) {
result.addFinalState(ext::make_pair(i, j));
......@@ -103,16 +104,12 @@ automaton::NFA < SymbolType, ext::pair<unsigned int, unsigned int> > HammingMatc
}
}
 
for (unsigned int i = 0; i<allowed_errors + 1; i++) {
for (const SymbolType& symbol : alphabet_without_wildcard) {
auto initial_state = ext::make_pair(0, i);
result.addTransition(initial_state, symbol, initial_state);
}
for (const SymbolType& symbol : alphabet_without_wildcard) {
result.addTransition(initial_state, symbol, initial_state);
}
 
for (unsigned int i = 0; i<pattern.getContent().size(); i++) {
for (unsigned int j = 0; j < allowed_errors + 1; j++) {
for (unsigned int j = 0; j < allowed_errors + 1; j++) {
for (unsigned int i = j; i<pattern.getContent().size(); i++) {
auto from = ext::make_pair(i, j);
auto to = ext::make_pair(i+1, j);
if (pattern.getContent()[i] == pattern.getWildcardSymbol()) {
......@@ -126,18 +123,16 @@ automaton::NFA < SymbolType, ext::pair<unsigned int, unsigned int> > HammingMatc
}
 
// add diagonal addTransition
for (unsigned int i = 0; i<pattern.getContent().size(); i++) {
for (unsigned int j = 0; j<allowed_errors; j++) {
for (unsigned int j = 0; j<allowed_errors; j++) {
for (unsigned int i = j; i<pattern.getContent().size(); i++) {
auto from = ext::make_pair(i, j);
auto to = ext::make_pair(i + 1, j + 1);
 
if (pattern.getContent()[i] == wildcard) {
continue;
}
for ( const SymbolType & symbol : alphabet_without_wildcard ) {
if (symbol != pattern.getContent()[i]) {
result.addTransition(from, symbol, to);
if (pattern.getContent()[i] != wildcard) {
for ( const SymbolType & symbol : alphabet_without_wildcard ) {
if (symbol != pattern.getContent()[i]) {
result.addTransition(from, symbol, to);
}
}
}
}
......
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