diff --git a/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.cpp b/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.cpp index 57f28681430abfca902fa9bd6c848f150af4fb99..daed1b36a1806a2f38767d01dbb6a6afaa2ffcdb 100644 --- a/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.cpp +++ b/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.cpp @@ -6,6 +6,7 @@ */ #include "ExactPatternMatchingAutomaton.h" +#include "ExactSubtreeMatchingAutomaton.h" #include "SubtreeJumpTable.h" #include <exception/AlibException.h> @@ -29,27 +30,7 @@ automaton::Automaton ExactPatternMatchingAutomaton::construct ( const tree::Rank } automaton::InputDrivenNPDA ExactPatternMatchingAutomaton::construct ( const tree::PrefixRankedTree & pattern ) { - automaton::InputDrivenNPDA res ( automaton::State ( 0 ), alphabet::symbolFrom ( 'S' ) ); - - for ( const alphabet::RankedSymbol & symbol : pattern.getAlphabet ( ) ) { - res.addInputSymbol ( alphabet::Symbol { symbol } ); - res.setPushdownStoreOperation ( alphabet::Symbol { symbol }, std::vector < alphabet::Symbol > { 1, alphabet::symbolFrom ( 'S' ) }, std::vector < alphabet::Symbol > { symbol.getRank ( ).getData ( ), alphabet::symbolFrom ( 'S' ) } ); - } - - for ( const alphabet::RankedSymbol & symbol : pattern.getAlphabet ( ) ) { - res.addTransition ( automaton::State ( 0 ), alphabet::Symbol { symbol }, automaton::State ( 0 ) ); - } - - int i = 1; - - for ( const alphabet::RankedSymbol & symbol : pattern.getContent ( ) ) { - res.addState ( automaton::State ( i ) ); - res.addTransition ( automaton::State ( i - 1 ), alphabet::Symbol { symbol }, automaton::State ( i ) ); - i++; - } - - res.addFinalState ( automaton::State ( i - 1 ) ); - return res; + return ExactSubtreeMatchingAutomaton::construct ( pattern ); } auto ExactPatternMatchingAutomatonPrefixRankedTree = ExactPatternMatchingAutomaton::RegistratorWrapper < automaton::InputDrivenNPDA, tree::PrefixRankedTree > ( ExactPatternMatchingAutomaton::getInstance ( ), ExactPatternMatchingAutomaton::construct ); @@ -130,28 +111,8 @@ automaton::NPDA ExactPatternMatchingAutomaton::construct ( const tree::PrefixRan auto ExactPatternMatchingAutomatonPrefixRankedPattern = ExactPatternMatchingAutomaton::RegistratorWrapper < automaton::NPDA, tree::PrefixRankedPattern > ( ExactPatternMatchingAutomaton::getInstance ( ), ExactPatternMatchingAutomaton::construct ); -automaton::State constructRecursiveTree ( const tree::RankedNode & node, automaton::NFTA & res, int & nextState ) { - std::vector < automaton::State > states; - - states.reserve ( node.getSymbol ( ).getRank ( ).getData ( ) ); - - for ( const auto & child : node.getChildren ( ) ) - states.push_back ( constructRecursiveTree ( * child, res, nextState ) ); - - automaton::State state ( nextState++ ); - res.addState ( state ); - res.addTransition ( node.getSymbol ( ), states, state ); - return state; -} - automaton::NFTA ExactPatternMatchingAutomaton::construct ( const tree::RankedTree & pattern ) { - const std::set < alphabet::RankedSymbol > & alphabet = pattern.getAlphabet ( ); - automaton::NFTA res; - - res.setInputSymbols ( alphabet ); - int nextState = 0; - res.addFinalState ( constructRecursiveTree ( pattern.getRoot ( ), res, nextState ) ); - return res; + return ExactSubtreeMatchingAutomaton::construct ( pattern ); } auto ExactPatternMatchingAutomatonRankedTree = ExactPatternMatchingAutomaton::RegistratorWrapper < automaton::NFTA, tree::RankedTree > ( ExactPatternMatchingAutomaton::getInstance ( ), ExactPatternMatchingAutomaton::construct );