Newer
Older
/*
* ExactSubtreeMatchingAutomaton.cpp
*
* Created on: 9. 2. 2014
* Author: Jan Travnicek
*/
#include "ExactSubtreeMatchingAutomaton.h"
#include <tree/ranked/PrefixRankedBarTree.h>
#include <automaton/PDA/InputDrivenNPDA.h>
#include <automaton/TA/NFTA.h>
#include <alphabet/BottomOfTheStackSymbol.h>
#include <registration/AlgoRegistration.hpp>
namespace arbology {
namespace exact {
automaton::InputDrivenNPDA < > ExactSubtreeMatchingAutomaton::construct ( const tree::PrefixRankedTree < > & pattern ) {
automaton::InputDrivenNPDA < > res ( DefaultStateType ( 0 ), DefaultSymbolType ( 'S' ) );
for ( const common::ranked_symbol < > & symbol : pattern.getAlphabet ( ) ) {
res.addInputSymbol ( DefaultSymbolType ( alphabet::RankedSymbol < > { symbol } ) );
res.setPushdownStoreOperation ( DefaultSymbolType ( alphabet::RankedSymbol < > { symbol } ), ext::vector < DefaultSymbolType > ( 1, DefaultSymbolType ( 'S' ) ), ext::vector < DefaultSymbolType > ( ( size_t ) symbol.getRank ( ), DefaultSymbolType ( 'S' ) ) );
for ( const common::ranked_symbol < > & symbol : pattern.getAlphabet ( ) ) {
res.addTransition ( DefaultStateType ( 0 ), DefaultSymbolType ( alphabet::RankedSymbol < > { symbol } ), DefaultStateType ( 0 ) );
for ( const common::ranked_symbol < > & symbol : pattern.getContent ( ) ) {
res.addState ( DefaultStateType ( i ) );
res.addTransition ( DefaultStateType ( i - 1 ), DefaultSymbolType ( alphabet::RankedSymbol < > { symbol } ), DefaultStateType ( i ) );
res.addFinalState ( DefaultStateType ( i - 1 ) );
auto ExactSubtreeMatchingAutomatonPrefixRankedTree = registration::AbstractRegister < ExactSubtreeMatchingAutomaton, automaton::InputDrivenNPDA < >, const tree::PrefixRankedTree < > & > ( ExactSubtreeMatchingAutomaton::construct );
automaton::InputDrivenNPDA < > ExactSubtreeMatchingAutomaton::construct ( const tree::PrefixRankedBarTree < > & pattern ) {
automaton::InputDrivenNPDA < > res ( DefaultStateType ( 0 ), alphabet::BottomOfTheStackSymbol::instance < DefaultSymbolType > ( ) );
res.setPushdownStoreAlphabet ( { alphabet::BottomOfTheStackSymbol::instance < DefaultSymbolType > ( ), DefaultSymbolType ( 'S' ) } );
for ( const common::ranked_symbol < > & symbol : pattern.getAlphabet ( ) ) {
res.addInputSymbol ( DefaultSymbolType ( alphabet::RankedSymbol < > { symbol } ) );
if ( pattern.getBars ( ).count ( symbol ) )
res.setPushdownStoreOperation ( DefaultSymbolType ( alphabet::RankedSymbol < > { symbol } ), ext::vector < DefaultSymbolType > ( 1, DefaultSymbolType ( 'S' ) ), ext::vector < DefaultSymbolType > { } );
res.setPushdownStoreOperation ( DefaultSymbolType ( alphabet::RankedSymbol < > { symbol } ), ext::vector < DefaultSymbolType > { }, ext::vector < DefaultSymbolType > ( 1, DefaultSymbolType ( 'S' ) ) );
for ( const common::ranked_symbol < > & symbol : pattern.getAlphabet ( ) ) {
res.addTransition ( DefaultStateType ( 0 ), DefaultSymbolType ( alphabet::RankedSymbol < > { symbol } ), DefaultStateType ( 0 ) );
for ( const common::ranked_symbol < > & symbol : pattern.getContent ( ) ) {
res.addState ( DefaultStateType ( i ) );
res.addTransition ( DefaultStateType ( i - 1 ), DefaultSymbolType ( alphabet::RankedSymbol < > { symbol } ), DefaultStateType ( i ) );
res.addFinalState ( DefaultStateType ( i - 1 ) );
auto ExactSubtreeMatchingAutomatonPrefixRankedBarTree = registration::AbstractRegister < ExactSubtreeMatchingAutomaton, automaton::InputDrivenNPDA < >, const tree::PrefixRankedBarTree < > & > ( ExactSubtreeMatchingAutomaton::construct );
DefaultStateType constructRecursive ( const ext::tree < common::ranked_symbol < > > & node, automaton::NFTA < > & res, int & nextState ) {
states.reserve ( ( size_t ) node.getData ( ).getRank ( ) );
for ( const ext::tree < common::ranked_symbol < > > & child : node.getChildren ( ) )
states.push_back ( constructRecursive ( child, res, nextState ) );
DefaultStateType state = DefaultStateType ( nextState++ );
res.addTransition ( node.getData ( ), states, state );
automaton::NFTA < > ExactSubtreeMatchingAutomaton::construct ( const tree::RankedTree < > & pattern ) {
automaton::NFTA < > res;
res.setInputAlphabet ( pattern.getAlphabet ( ) );
res.addFinalState ( constructRecursive ( pattern.getContent ( ), res, nextState ) );
auto ExactSubtreeMatchingAutomatonRankedTree = registration::AbstractRegister < ExactSubtreeMatchingAutomaton, automaton::NFTA < >, const tree::RankedTree < > & > ( ExactSubtreeMatchingAutomaton::construct );
} /* namespace exact */
} /* namespace arbology */