Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
ExactTreePatternAutomaton.h
Go to the documentation of this file.
1
6#pragma once
7
9
12
14
15#include <alib/deque>
16
17namespace arbology {
18
19namespace exact {
20
22public:
27 template < class SymbolType >
29
34 template < class SymbolType >
36};
37
38template < class SymbolType >
40 char S = alphabet::WildcardSymbol::instance < char > ( );
42
43 for ( const common::ranked_symbol < SymbolType > & symbol : tree.getAlphabet ( ) ) {
44 res.addInputSymbol ( symbol );
45 if ( tree.getBars ( ).count ( symbol ) )
46 res.setPushdownStoreOperation ( symbol, ext::vector < char > ( 1, S ), ext::vector < char > { } );
47 else
48 res.setPushdownStoreOperation ( symbol, ext::vector < char > { }, ext::vector < char > ( 1, S ) );
49 }
50
51 res.addInputSymbol ( subtreeWildcard );
52 res.setPushdownStoreOperation ( subtreeWildcard, ext::vector < char > { }, ext::vector < char > ( 1, S ) );
53
54 res.addInputSymbol ( variablesBar );
55 res.setPushdownStoreOperation ( variablesBar, ext::vector < char > ( 1, S ), ext::vector < char > { } );
56
57 unsigned i = 1;
58 ext::deque < unsigned > subtreeJumps;
59
60 for ( const common::ranked_symbol < SymbolType > & symbol : tree.getContent ( ) ) {
61 res.addState ( i );
62 res.addTransition ( i - 1, symbol, i );
63
64 if ( tree.getBars ( ).count ( symbol ) ) {
65 unsigned source = subtreeJumps.back ( );
66 subtreeJumps.pop_back ( );
67
68 res.addState ( ~0 - i );
69 res.addTransition ( source, subtreeWildcard, ~0 - i );
70 res.addTransition ( ~0 - i, variablesBar, i );
71 } else {
72 res.addTransition ( res.getInitialState ( ), symbol, i ); // transition from the initial state only allowed for nonbar symbols
73
74 subtreeJumps.push_back ( i - 1 );
75 }
76
77 i++;
78 }
79
80 return res;
81}
82
83template < class SymbolType >
85 char S = alphabet::WildcardSymbol::instance < char > ( );
87
88 for ( const common::ranked_symbol < SymbolType > & symbol : tree.getAlphabet ( ) ) {
89 res.addInputSymbol ( symbol );
90 res.setPushdownStoreOperation ( symbol, ext::vector < char > ( 1, S ), ext::vector < char > ( symbol.getRank ( ), S ) );
91 }
92
93 res.addInputSymbol ( subtreeWildcard );
94 res.setPushdownStoreOperation ( subtreeWildcard, ext::vector < char > ( 1, S ), ext::vector < char > { } );
95
96 unsigned i = 1;
98
99 for ( const common::ranked_symbol < SymbolType > & symbol : tree.getContent ( ) ) {
100 subtreeJumps.push_back ( std::make_pair ( symbol.getRank ( ), i - 1 ) );
101
102 res.addState ( i );
103 res.addTransition ( i - 1, symbol, i );
104 res.addTransition ( 0, std::move ( symbol ), i );
105
106 while ( !subtreeJumps.empty ( ) && subtreeJumps.back ( ).first == 0 ) {
107 res.addTransition ( subtreeJumps.back ( ).second, subtreeWildcard, i );
108 subtreeJumps.pop_back ( );
109 }
110
111 if ( !subtreeJumps.empty ( ) ) subtreeJumps.back ( ).first--;
112
113 i++;
114 }
115
116 return res;
117}
118
119} /* namespace exact */
120
121} /* namespace arbology */
122
Definition: ExactTreePatternAutomaton.h:21
static automaton::InputDrivenNPDA< common::ranked_symbol< SymbolType >, char, unsigned > construct(const tree::PrefixRankedBarTree< SymbolType > &tree, const common::ranked_symbol< SymbolType > &subtreeWildcard, const common::ranked_symbol< SymbolType > &variablesBar)
Definition: ExactTreePatternAutomaton.h:39
Nondeterministic input driven pushdown automaton. Accepts subset of context free languages.
Definition: InputDrivenNPDA.h:79
Definition: ranked_symbol.hpp:20
Class extending the deque class from the standard library. Original reason is to allow printing of th...
Definition: deque.hpp:44
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
Tree structure represented as linear sequece as result of preorder traversal with additional bar symb...
Definition: PrefixRankedBarTree.h:78
Tree structure represented as linear sequece as result of preorder traversal. The representation is s...
Definition: PrefixRankedTree.h:71
Definition: BoyerMooreHorspool.h:22
int i
Definition: AllEpsilonClosure.h:118
return res
Definition: MinimizeByPartitioning.h:145
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: BackwardOccurrenceTest.h:17