Skip to content
Snippets Groups Projects
Commit af9faf1a authored by Jan Trávníček's avatar Jan Trávníček
Browse files

+ExactSubtreeMatchingAutomaton

parent e35af02c
No related branches found
No related tags found
No related merge requests found
/*
* 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::UnrankedTree&) const {
throw exception::AlibException("Unsupported tree type UnrankedTree");
}
const ExactSubtreeMatchingAutomaton ExactSubtreeMatchingAutomaton::EXACT_SUBTREE_MATCHING_AUTOMATON;
} /* namespace exact */
} /* namespace arbology */
/*
* ExactSubtreeMatchingAutomaton.h
*
* Created on: 9. 2. 2014
* Author: Jan Travnicek
*/
#ifndef _EXACT_SUBTREE_MATCHING_AUTOMATON_H__
#define _EXACT_SUBTREE_MATCHING_AUTOMATON_H__
#include <automaton/Automaton.h>
#include <automaton/PDA/InputDrivenNPDA.h>
#include <tree/Tree.h>
namespace arbology {
namespace exact {
class ExactSubtreeMatchingAutomaton : public tree::VisitableTreeBase::const_visitor_type {
public:
/**
* Performs conversion.
* @return left regular grammar equivalent to source automaton.
*/
static automaton::Automaton construct(const tree::Tree& pattern);
static automaton::InputDrivenNPDA construct(const tree::PrefixRankedNotation& pattern);
private:
void Visit(void*, const tree::RankedTree& pattern) const;
void Visit(void*, const tree::PrefixRankedNotation& pattern) const;
void Visit(void*, const tree::UnrankedTree& pattern) const;
static const ExactSubtreeMatchingAutomaton EXACT_SUBTREE_MATCHING_AUTOMATON;
};
} /* namespace exact */
} /* namespace arbology */
#endif /* _EXACT_SUBTREE_MATCHING_AUTOMATON_H__ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment