Newer
Older
/*
* ExactSubtreeMatchingAutomaton.cpp
*
* Created on: 9. 2. 2014
* Author: Jan Travnicek
*/
#include "ExactSubtreeMatchingAutomaton.h"
#include <exception/AlibException.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::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;
}
void ExactSubtreeMatchingAutomaton::Visit(void*, const tree::RankedTree&) const {
throw exception::AlibException("Unsupported tree type RankedTree");
}
void ExactSubtreeMatchingAutomaton::Visit(void* data, const tree::PrefixRankedTree& pattern) const {
automaton::Automaton* & out = *((automaton::Automaton**) data);
out = new automaton::Automaton(this->construct(pattern));
}
void ExactSubtreeMatchingAutomaton::Visit(void*, const tree::PrefixRankedBarTree&) const {
throw exception::AlibException("Unsupported tree type PrefixRankedBarTree");
}
void ExactSubtreeMatchingAutomaton::Visit(void*, const tree::RankedPattern&) const {
throw exception::AlibException("Unsupported tree type RankedPattern");
}
void ExactSubtreeMatchingAutomaton::Visit(void*, const tree::PrefixRankedPattern&) const {
throw exception::AlibException("Unsupported tree type PrefixRankedPattern");
}
void ExactSubtreeMatchingAutomaton::Visit(void*, const tree::PrefixRankedBarPattern&) const {
throw exception::AlibException("Unsupported tree type PrefixRankedBarPattern");
}
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 */