Skip to content
Snippets Groups Projects
Commit 7e05ff37 authored by Štěpán Plachý's avatar Štěpán Plachý
Browse files

ExactSubtreeMatchingAutomaton TA

parent 4388418d
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <container/Container.h> #include <container/Container.h>
   
#include <arbology/exact/ExactSubtreeMatch.h> #include <arbology/exact/ExactSubtreeMatch.h>
#include <arbology/exact/ExactSubtreeMatchingAutomaton.h>
   
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
try { try {
...@@ -21,6 +22,7 @@ int main(int argc, char* argv[]) { ...@@ -21,6 +22,7 @@ int main(int argc, char* argv[]) {
   
std::vector<std::string> allowed; std::vector<std::string> allowed;
allowed.push_back("exactSubtreeMatch"); allowed.push_back("exactSubtreeMatch");
allowed.push_back("exactSubtreeMatchingAutomaton");
TCLAP::ValuesConstraint<std::string> allowedVals( allowed ); TCLAP::ValuesConstraint<std::string> allowedVals( allowed );
   
TCLAP::ValueArg<std::string> algorithm( "a", "algorithm", "Execute algorithm", false, "exactSubtreeMatch", &allowedVals); TCLAP::ValueArg<std::string> algorithm( "a", "algorithm", "Execute algorithm", false, "exactSubtreeMatch", &allowedVals);
...@@ -38,6 +40,8 @@ int main(int argc, char* argv[]) { ...@@ -38,6 +40,8 @@ int main(int argc, char* argv[]) {
int needSubject = 0; int needSubject = 0;
if( algorithm.getValue() == "exactSubtreeMatch") { if( algorithm.getValue() == "exactSubtreeMatch") {
needPattern = needSubject = 1; needPattern = needSubject = 1;
} else if( algorithm.getValue() == "exactSubtreeMatchingAutomaton") {
needPattern = 1;
} else { } else {
} }
   
...@@ -81,6 +85,11 @@ int main(int argc, char* argv[]) { ...@@ -81,6 +85,11 @@ int main(int argc, char* argv[]) {
std::set<unsigned> res = arbology::exact::ExactSubtreeMatch::match(subject, pattern); std::set<unsigned> res = arbology::exact::ExactSubtreeMatch::match(subject, pattern);
alib::XmlDataFactory::toStdout(res); alib::XmlDataFactory::toStdout(res);
return 0; return 0;
} else if( algorithm.getValue() == "exactSubtreeMatchingAutomaton") {
tree::Tree pattern = alib::XmlDataFactory::fromTokens<tree::Tree>(patternTokens.front());
automaton::Automaton res = arbology::exact::ExactSubtreeMatchingAutomaton::construct(pattern);
alib::XmlDataFactory::toStdout(res);
return 0;
} else { } else {
throw exception::AlibException( "Invalid algorithm" ); throw exception::AlibException( "Invalid algorithm" );
return 1; return 1;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "ExactSubtreeMatchingAutomaton.h" #include "ExactSubtreeMatchingAutomaton.h"
#include <exception/AlibException.h> #include <exception/AlibException.h>
#include <tree/ranked/PrefixRankedTree.h> #include <tree/ranked/PrefixRankedTree.h>
#include <tree/ranked/RankedTree.h>
   
#include <deque> #include <deque>
   
...@@ -44,8 +45,29 @@ automaton::InputDrivenNPDA ExactSubtreeMatchingAutomaton::construct(const tree:: ...@@ -44,8 +45,29 @@ automaton::InputDrivenNPDA ExactSubtreeMatchingAutomaton::construct(const tree::
return res; return res;
} }
   
void ExactSubtreeMatchingAutomaton::Visit(void*, const tree::RankedTree&) const { automaton::State constructRecursive(const tree::RankedNode & node, automaton::NFTA & res, int & nextState) {
throw exception::AlibException("Unsupported tree type RankedTree"); std::vector<automaton::State> states;
states.reserve(node.getSymbol().getRank().getData());
for(const auto & child : node.getChildren()) {
states.push_back(constructRecursive(*child, res, nextState));
}
automaton::State state (nextState++);
res.addState(state);
res.addTransition(node.getSymbol(), states, state);
return state;
}
automaton::NFTA ExactSubtreeMatchingAutomaton::construct(const tree::RankedTree & pattern) {
automaton::NFTA res;
res.setInputSymbols(pattern.getAlphabet());
int nextState = 0;
res.addFinalState(constructRecursive(pattern.getRoot(), res, nextState));
return res;
}
void ExactSubtreeMatchingAutomaton::Visit(void* data, const tree::RankedTree& pattern) const {
automaton::Automaton* & out = *((automaton::Automaton**) data);
out = new automaton::Automaton(this->construct(pattern));
} }
   
void ExactSubtreeMatchingAutomaton::Visit(void* data, const tree::PrefixRankedTree& pattern) const { void ExactSubtreeMatchingAutomaton::Visit(void* data, const tree::PrefixRankedTree& pattern) const {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
   
#include <automaton/Automaton.h> #include <automaton/Automaton.h>
#include <automaton/PDA/InputDrivenNPDA.h> #include <automaton/PDA/InputDrivenNPDA.h>
#include <automaton/TA/NFTA.h>
#include <tree/Tree.h> #include <tree/Tree.h>
   
namespace arbology { namespace arbology {
...@@ -27,6 +28,7 @@ public: ...@@ -27,6 +28,7 @@ public:
static automaton::Automaton construct(const tree::Tree& pattern); static automaton::Automaton construct(const tree::Tree& pattern);
   
static automaton::InputDrivenNPDA construct(const tree::PrefixRankedTree& pattern); static automaton::InputDrivenNPDA construct(const tree::PrefixRankedTree& pattern);
static automaton::NFTA construct(const tree::RankedTree& pattern);
private: private:
void Visit(void*, const tree::RankedTree& pattern) const; void Visit(void*, const tree::RankedTree& pattern) const;
void Visit(void*, const tree::RankedPattern& subject) const; void Visit(void*, const tree::RankedPattern& subject) const;
......
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