Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
ExactSubtreeMatchingAutomaton.h
Go to the documentation of this file.
1
6#pragma once
7
13
15#include <automaton/TA/NFTA.h>
18
20
21namespace arbology {
22
23namespace exact {
24
26public:
31 template < class SymbolType >
33
34 template < class SymbolType >
36
37 template < class SymbolType >
39
40 template < class SymbolType >
42
43 template < class SymbolType >
45};
46
47template < class SymbolType >
50
51 for ( const common::ranked_symbol < SymbolType > & symbol : pattern.getAlphabet ( ) ) {
52 res.addInputSymbol ( symbol );
53 res.setPushdownStoreOperation ( symbol, ext::vector < char > ( 1, 'S' ), ext::vector < char > ( symbol.getRank ( ), 'S' ) );
54 }
55
56 for ( const common::ranked_symbol < SymbolType > & symbol : pattern.getAlphabet ( ) ) {
57 res.addTransition ( 0, symbol, 0 );
58 }
59
60 unsigned i = 1;
61
62 for ( const common::ranked_symbol < SymbolType > & symbol : pattern.getContent ( ) ) {
63 res.addState ( i );
64 res.addTransition ( i - 1, symbol, i );
65 i++;
66 }
67
68 res.addFinalState ( i - 1 );
69 return res;
70}
71
72template < class SymbolType >
74 automaton::InputDrivenNPDA < common::ranked_symbol < SymbolType >, char, unsigned > res ( 0, alphabet::BottomOfTheStackSymbol::instance < char > ( ) );
75
76 res.setPushdownStoreAlphabet ( { alphabet::BottomOfTheStackSymbol::instance < char > ( ), 'S' } );
77
78 for ( const common::ranked_symbol < SymbolType > & symbol : pattern.getAlphabet ( ) ) {
79 res.addInputSymbol ( symbol );
80
81 if ( pattern.getBars ( ).count ( symbol ) )
82 res.setPushdownStoreOperation ( symbol, ext::vector < char > ( 1, 'S' ), ext::vector < char > { } );
83 else
84 res.setPushdownStoreOperation ( symbol, ext::vector < char > { }, ext::vector < char > ( 1, 'S' ) );
85 }
86
87 for ( const common::ranked_symbol < SymbolType > & symbol : pattern.getAlphabet ( ) ) {
88 res.addTransition ( 0, symbol, 0 );
89 }
90
91 unsigned i = 1;
92
93 for ( const common::ranked_symbol < SymbolType > & symbol : pattern.getContent ( ) ) {
94 res.addState ( i );
95 res.addTransition ( i - 1, symbol, i );
96 i++;
97 }
98
99 res.addFinalState ( i - 1 );
100 return res;
101}
102
103template < class SymbolType >
106
107 states.reserve ( node.getData ( ).getRank ( ) );
108
109 for ( const ext::tree < common::ranked_symbol < SymbolType > > & child : node.getChildren ( ) )
110 states.push_back ( constructRecursive ( child, res, nextState ) );
111
112 unsigned state = nextState++;
113 res.addState ( state );
114 res.addTransition ( node.getData ( ), states, state );
115 return state;
116}
117
118template < class SymbolType >
121
122 res.setInputAlphabet ( pattern.getAlphabet ( ) );
123 unsigned nextState = 0;
124 res.addFinalState ( constructRecursive ( pattern.getContent ( ), res, nextState ) );
125 return res;
126}
127
128template < class SymbolType >
131
132 for ( const ext::tree < common::ranked_symbol < SymbolType > > & child : node.getChildren ( ) )
133 states.insert ( constructRecursive ( child, res, nextState ) );
134
135 unsigned state = nextState++;
136 res.addState ( state );
137 res.addTransition ( node.getData ( ), states, state );
138 return state;
139}
140
141template < class SymbolType >
144
145 res.setInputAlphabet ( pattern.getAlphabet ( ) );
146 unsigned nextState = 0;
147 res.addFinalState ( constructRecursive ( pattern.getContent ( ), res, nextState ) );
148 return res;
149}
150
151template < class SymbolType >
154
155 for ( const ext::tree < SymbolType > & child : node.getChildren ( ) )
156 states.push_back ( constructRecursive ( child, res, nextState ) );
157
158 unsigned state = nextState++;
159 res.addState ( state );
160 res.addTransition ( node.getData ( ), states, state );
161 return state;
162}
163
164template < class SymbolType >
167
168 res.setInputAlphabet ( pattern.getAlphabet ( ) );
169 unsigned nextState = 0;
170 res.addFinalState ( constructRecursive ( pattern.getContent ( ), res, nextState ) );
171 return res;
172}
173
174} /* namespace exact */
175
176} /* namespace arbology */
177
Definition: ExactSubtreeMatchingAutomaton.h:25
static automaton::InputDrivenNPDA< common::ranked_symbol< SymbolType >, char, unsigned > construct(const tree::PrefixRankedTree< SymbolType > &pattern)
Definition: ExactSubtreeMatchingAutomaton.h:48
Nondeterministic input driven pushdown automaton. Accepts subset of context free languages.
Definition: InputDrivenNPDA.h:79
Nondeterministic finite tree automaton without epsilon transitions. Accepts regular tree languages.
Definition: NFTA.h:72
Nondeterministic Z-Automaton. Computation model for unranked regular tree languages.
Definition: NondeterministicZAutomaton.h:68
Nondeterministic unordered finite tree automaton without epsilon transitions. Accepts regular tree la...
Definition: UnorderedNFTA.h:72
Definition: ranked_symbol.hpp:20
Definition: multiset.hpp:44
Class introducing a tree with interface trying to be close to the interface of standard library conta...
Definition: tree.hpp:52
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
const ext::vector< common::ranked_symbol< SymbolType > > & getContent() const &
Definition: PrefixRankedBarTree.h:273
const ext::set< common::ranked_symbol< SymbolType > > & getAlphabet() const &
Definition: PrefixRankedBarTree.h:129
const ext::set< common::ranked_symbol< SymbolType > > & getBars() const &
Definition: PrefixRankedBarTree.h:156
Tree structure represented as linear sequece as result of preorder traversal. The representation is s...
Definition: PrefixRankedTree.h:71
const ext::set< common::ranked_symbol< SymbolType > > & getAlphabet() const &
Definition: PrefixRankedTree.h:119
const ext::vector< common::ranked_symbol< SymbolType > > & getContent() const &
Definition: PrefixRankedTree.h:235
Tree structure represented in its natural representation. The representation is so called ranked,...
Definition: RankedTree.h:72
const ext::set< common::ranked_symbol< SymbolType > > & getAlphabet() const &
Definition: RankedTree.h:138
const ext::tree< common::ranked_symbol< SymbolType > > & getContent() const &
Definition: RankedTree.h:252
Tree structure represented in its natural representation. The representation is so called ranked,...
Definition: UnorderedRankedTree.h:70
const ext::set< common::ranked_symbol< SymbolType > > & getAlphabet() const &
Definition: UnorderedRankedTree.h:122
const ext::tree< common::ranked_symbol< SymbolType > > & getContent() const &
Definition: UnorderedRankedTree.h:228
Tree represented in its natural representation. The representation is so called unranked,...
Definition: UnrankedTree.h:69
const ext::set< SymbolType > & getAlphabet() const &
Definition: UnrankedTree.h:112
const ext::tree< SymbolType > & getContent() const &
Definition: UnrankedTree.h:217
unsigned constructRecursive(const ext::tree< common::ranked_symbol< SymbolType > > &node, automaton::NFTA< SymbolType, unsigned > &res, unsigned &nextState)
Definition: ExactSubtreeMatchingAutomaton.h:104
Definition: BoyerMooreHorspool.h:22
int i
Definition: AllEpsilonClosure.h:118
return res
Definition: MinimizeByPartitioning.h:145
Definition: Node.cpp:11