From 78b0de48e10453c6211ba2fb76676f5c34cd98df Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Tue, 5 Feb 2019 11:45:08 +0100 Subject: [PATCH] template construction of Automata Matchers --- .../matching/DAWGMatcherConstruction.cpp | 9 --------- .../matching/DAWGMatcherConstruction.h | 14 ++++++++++++- .../matching/NaiveDAWGMatcherConstruction.cpp | 15 -------------- .../matching/NaiveDAWGMatcherConstruction.h | 20 ++++++++++++++++++- .../matching/OracleMatcherConstruction.cpp | 9 --------- .../matching/OracleMatcherConstruction.h | 14 ++++++++++++- 6 files changed, 45 insertions(+), 36 deletions(-) diff --git a/alib2algo/src/stringology/matching/DAWGMatcherConstruction.cpp b/alib2algo/src/stringology/matching/DAWGMatcherConstruction.cpp index 7c537890ff..ead0cafa71 100644 --- a/alib2algo/src/stringology/matching/DAWGMatcherConstruction.cpp +++ b/alib2algo/src/stringology/matching/DAWGMatcherConstruction.cpp @@ -3,21 +3,12 @@ */ #include "DAWGMatcherConstruction.h" -#include <stringology/indexing/ExactSuffixAutomaton.h> #include <registration/AlgoRegistration.hpp> namespace stringology { namespace matching { -indexes::stringology::SuffixAutomaton < DefaultSymbolType > DAWGMatcherConstruction::construct ( const string::LinearString < > & pattern ) { - auto patternData = pattern.getContent ( ); - reverse ( patternData.begin ( ), patternData.end ( ) ); - string::LinearString < > reversedPattern ( pattern.getAlphabet ( ), std::move ( patternData ) ); - - return stringology::indexing::ExactSuffixAutomaton::construct ( reversedPattern ); -} - auto DAWGMatcherConstructionLinearString = registration::AbstractRegister < DAWGMatcherConstruction, indexes::stringology::SuffixAutomaton < DefaultSymbolType >, const string::LinearString < > & > ( DAWGMatcherConstruction::construct ); } /* namespace matching */ diff --git a/alib2algo/src/stringology/matching/DAWGMatcherConstruction.h b/alib2algo/src/stringology/matching/DAWGMatcherConstruction.h index 0ddb9eedc9..458e24a497 100644 --- a/alib2algo/src/stringology/matching/DAWGMatcherConstruction.h +++ b/alib2algo/src/stringology/matching/DAWGMatcherConstruction.h @@ -8,6 +8,8 @@ #include <indexes/stringology/SuffixAutomaton.h> #include <string/LinearString.h> +#include <stringology/indexing/ExactSuffixAutomaton.h> + namespace stringology { namespace matching { @@ -18,10 +20,20 @@ public: * Linear time on-line construction of minimal suffix automaton for given pattern. * @return minimal suffix automaton for given pattern. */ - static indexes::stringology::SuffixAutomaton < > construct ( const string::LinearString < > & pattern ); + template < class SymbolType > + static indexes::stringology::SuffixAutomaton < SymbolType > construct ( const string::LinearString < SymbolType > & pattern ); }; +template < class SymbolType > +indexes::stringology::SuffixAutomaton < SymbolType > DAWGMatcherConstruction::construct ( const string::LinearString < SymbolType > & pattern ) { + auto patternData = pattern.getContent ( ); + reverse ( patternData.begin ( ), patternData.end ( ) ); + string::LinearString < SymbolType > reversedPattern ( pattern.getAlphabet ( ), std::move ( patternData ) ); + + return stringology::indexing::ExactSuffixAutomaton::construct ( reversedPattern ); +} + } /* namespace matching */ } /* namespace stringology */ diff --git a/alib2algo/src/stringology/matching/NaiveDAWGMatcherConstruction.cpp b/alib2algo/src/stringology/matching/NaiveDAWGMatcherConstruction.cpp index 51651cfef8..2aa4bdfc6a 100644 --- a/alib2algo/src/stringology/matching/NaiveDAWGMatcherConstruction.cpp +++ b/alib2algo/src/stringology/matching/NaiveDAWGMatcherConstruction.cpp @@ -3,27 +3,12 @@ */ #include "NaiveDAWGMatcherConstruction.h" -#include <automaton/determinize/Determinize.h> -#include <automaton/simplify/Minimize.h> -#include <automaton/simplify/EpsilonRemoverIncoming.h> -#include <stringology/indexing/NondeterministicExactSuffixAutomaton.h> #include <registration/AlgoRegistration.hpp> namespace stringology { namespace matching { -automaton::DFA < DefaultSymbolType, ext::set < unsigned > > NaiveDAWGMatcherConstruction::naiveConstruct ( const string::LinearString < > & pattern ) { - auto patternData = pattern.getContent ( ); - reverse ( patternData.begin ( ), patternData.end ( ) ); - string::LinearString < > reversedPattern ( pattern.getAlphabet ( ), std::move ( patternData ) ); - - automaton::EpsilonNFA < DefaultSymbolType, DefaultEpsilonType, unsigned > nfaSuffixAutomaton = stringology::indexing::NondeterministicExactSuffixAutomaton::construct ( reversedPattern ); - - return automaton::simplify::Minimize::minimize ( automaton::determinize::Determinize::determinize ( automaton::simplify::EpsilonRemoverIncoming::remove ( nfaSuffixAutomaton ) ) ); - -} - auto NaiveDAWGMatcherConstructionLinearString = registration::AbstractRegister < NaiveDAWGMatcherConstruction, automaton::DFA < DefaultSymbolType, ext::set < unsigned > >, const string::LinearString < > & > ( NaiveDAWGMatcherConstruction::naiveConstruct ); } /* namespace matching */ diff --git a/alib2algo/src/stringology/matching/NaiveDAWGMatcherConstruction.h b/alib2algo/src/stringology/matching/NaiveDAWGMatcherConstruction.h index 3fabc582c9..8388f00c5d 100644 --- a/alib2algo/src/stringology/matching/NaiveDAWGMatcherConstruction.h +++ b/alib2algo/src/stringology/matching/NaiveDAWGMatcherConstruction.h @@ -8,6 +8,11 @@ #include <automaton/FSM/DFA.h> #include <string/LinearString.h> +#include <automaton/determinize/Determinize.h> +#include <automaton/simplify/Minimize.h> +#include <automaton/simplify/EpsilonRemoverIncoming.h> +#include <stringology/indexing/NondeterministicExactSuffixAutomaton.h> + namespace stringology { namespace matching { @@ -18,10 +23,23 @@ public: * Naive construction of minimal suffix automaton for given pattern - EpsNFA -> NFA -> DFA -> minDFA -> removeErrorState. * @return minimal suffix automaton for given pattern. */ - static automaton::DFA < DefaultSymbolType, ext::set < unsigned > > naiveConstruct ( const string::LinearString < > & pattern ); + template < class SymbolType > + static automaton::DFA < SymbolType, ext::set < unsigned > > naiveConstruct ( const string::LinearString < SymbolType > & pattern ); }; +template < class SymbolType > +automaton::DFA < SymbolType, ext::set < unsigned > > NaiveDAWGMatcherConstruction::naiveConstruct ( const string::LinearString < SymbolType > & pattern ) { + auto patternData = pattern.getContent ( ); + reverse ( patternData.begin ( ), patternData.end ( ) ); + string::LinearString < SymbolType > reversedPattern ( pattern.getAlphabet ( ), std::move ( patternData ) ); + + automaton::EpsilonNFA < SymbolType, DefaultEpsilonType, unsigned > nfaSuffixAutomaton = stringology::indexing::NondeterministicExactSuffixAutomaton::construct ( reversedPattern ); + + return automaton::simplify::Minimize::minimize ( automaton::determinize::Determinize::determinize ( automaton::simplify::EpsilonRemoverIncoming::remove ( nfaSuffixAutomaton ) ) ); + +} + } /* namespace matching */ } /* namespace stringology */ diff --git a/alib2algo/src/stringology/matching/OracleMatcherConstruction.cpp b/alib2algo/src/stringology/matching/OracleMatcherConstruction.cpp index d56866487e..9c38892355 100644 --- a/alib2algo/src/stringology/matching/OracleMatcherConstruction.cpp +++ b/alib2algo/src/stringology/matching/OracleMatcherConstruction.cpp @@ -3,21 +3,12 @@ */ #include "OracleMatcherConstruction.h" -#include <stringology/indexing/ExactSuffixAutomaton.h> #include <registration/AlgoRegistration.hpp> namespace stringology { namespace matching { -automaton::DFA < DefaultSymbolType, unsigned > OracleMatcherConstruction::construct ( const string::LinearString < > & pattern ) { - auto patternData = pattern.getContent ( ); - reverse ( patternData.begin ( ), patternData.end ( ) ); - string::LinearString < > reversedPattern ( pattern.getAlphabet ( ), std::move ( patternData ) ); - - return stringology::indexing::ExactSuffixAutomaton::construct ( reversedPattern ).getAutomaton ( ); // FIXME this is not oracle automaton -} - auto OracleMatcherConstructionLinearString = registration::AbstractRegister < OracleMatcherConstruction, automaton::DFA < DefaultSymbolType, unsigned >, const string::LinearString < > & > ( OracleMatcherConstruction::construct ); } /* namespace matching */ diff --git a/alib2algo/src/stringology/matching/OracleMatcherConstruction.h b/alib2algo/src/stringology/matching/OracleMatcherConstruction.h index 55b3bd3740..e59871f360 100644 --- a/alib2algo/src/stringology/matching/OracleMatcherConstruction.h +++ b/alib2algo/src/stringology/matching/OracleMatcherConstruction.h @@ -8,6 +8,8 @@ #include <automaton/FSM/DFA.h> #include <string/LinearString.h> +#include <stringology/indexing/ExactSuffixAutomaton.h> + namespace stringology { namespace matching { @@ -18,10 +20,20 @@ public: * Linear time on-line construction of minimal suffix automaton for given pattern. * @return minimal suffix automaton for given pattern. */ - static automaton::DFA < DefaultSymbolType, unsigned > construct ( const string::LinearString < > & pattern ); + template < class SymbolType > + static automaton::DFA < SymbolType, unsigned > construct ( const string::LinearString < SymbolType > & pattern ); }; +template < class SymbolType > +automaton::DFA < SymbolType, unsigned > OracleMatcherConstruction::construct ( const string::LinearString < SymbolType > & pattern ) { + auto patternData = pattern.getContent ( ); + reverse ( patternData.begin ( ), patternData.end ( ) ); + string::LinearString < SymbolType > reversedPattern ( pattern.getAlphabet ( ), std::move ( patternData ) ); + + return stringology::indexing::ExactSuffixAutomaton::construct ( reversedPattern ).getAutomaton ( ); // FIXME this is not oracle automaton +} + } /* namespace matching */ } /* namespace stringology */ -- GitLab