Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* ExactSubtreeMatchingAutomaton.cpp
*
* Created on: 9. 2. 2014
* Author: Jan Travnicek
*/
#include "ExactSubtreeMatchingAutomaton.h"
#include <exception/AlibException.h>
#include <tree/ranked/PrefixRankedNotation.h>
#include <deque>
namespace arbology {
namespace exact {
automaton::Automaton ExactSubtreeMatchingAutomaton::construct(const tree::Tree& pattern) {
automaton::Automaton* out = NULL;
pattern.getData().Accept((void*) &out, ExactSubtreeMatchingAutomaton::EXACT_SUBTREE_MATCHING_AUTOMATON);
automaton::Automaton res = std::move(*out);
delete out;
return res;
}
automaton::InputDrivenNPDA ExactSubtreeMatchingAutomaton::construct(const tree::PrefixRankedNotation& 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;
}
void ExactSubtreeMatchingAutomaton::Visit(void*, const tree::RankedTree&) const {
throw exception::AlibException("Unsupported tree type RankedTree");
}
void ExactSubtreeMatchingAutomaton::Visit(void* data, const tree::PrefixRankedNotation& pattern) const {
automaton::Automaton* & out = *((automaton::Automaton**) data);
out = new automaton::Automaton(this->construct(pattern));
}
void ExactSubtreeMatchingAutomaton::Visit(void*, const tree::RankedPattern&) const {
throw exception::AlibException("Unsupported tree type RankedPattern");
}
void ExactSubtreeMatchingAutomaton::Visit(void*, const tree::UnrankedTree&) const {
throw exception::AlibException("Unsupported tree type UnrankedTree");
}
void ExactSubtreeMatchingAutomaton::Visit(void*, const tree::UnrankedPattern&) const {
throw exception::AlibException("Unsupported tree type UnrankedPattern");
}
const ExactSubtreeMatchingAutomaton ExactSubtreeMatchingAutomaton::EXACT_SUBTREE_MATCHING_AUTOMATON;
} /* namespace exact */
} /* namespace arbology */