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

ranked tree to dot

parent 396618ec
No related branches found
No related tags found
1 merge request!134Merge jt
...@@ -33,5 +33,6 @@ auto DotConverterSinglePopNPDA = registration::AbstractRegister < convert::DotCo ...@@ -33,5 +33,6 @@ auto DotConverterSinglePopNPDA = registration::AbstractRegister < convert::DotCo
auto DotConverterOneTapeDTM = registration::AbstractRegister < convert::DotConverter, std::string, const automaton::OneTapeDTM < > & > ( convert::DotConverter::convert ); auto DotConverterOneTapeDTM = registration::AbstractRegister < convert::DotConverter, std::string, const automaton::OneTapeDTM < > & > ( convert::DotConverter::convert );
auto DotConverterExtendedNFTA = registration::AbstractRegister < convert::DotConverter, std::string, const automaton::ExtendedNFTA < > & > ( convert::DotConverter::convert ); auto DotConverterExtendedNFTA = registration::AbstractRegister < convert::DotConverter, std::string, const automaton::ExtendedNFTA < > & > ( convert::DotConverter::convert );
auto DotConverterFormalRTE = registration::AbstractRegister < convert::DotConverter, std::string, const rte::FormalRTE < > & > ( convert::DotConverter::convert ); auto DotConverterFormalRTE = registration::AbstractRegister < convert::DotConverter, std::string, const rte::FormalRTE < > & > ( convert::DotConverter::convert );
auto DotConverterRankedTree = registration::AbstractRegister < convert::DotConverter, std::string, const tree::RankedTree < > & > ( convert::DotConverter::convert );
   
} /* namespace */ } /* namespace */
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include <string/string/LinearString.h> #include <string/string/LinearString.h>
#include <regexp/string/UnboundedRegExp.h> #include <regexp/string/UnboundedRegExp.h>
   
#include "DotConverterTreePart.hxx"
#include "DotConverterRTEPart.hxx" #include "DotConverterRTEPart.hxx"
   
namespace convert { namespace convert {
...@@ -181,6 +182,9 @@ public: ...@@ -181,6 +182,9 @@ public:
template < class SymbolType > template < class SymbolType >
static void convert(std::ostream& out, const rte::FormalRTE < SymbolType > & e ); static void convert(std::ostream& out, const rte::FormalRTE < SymbolType > & e );
   
template < class SymbolType >
static void convert(std::ostream& out, const tree::RankedTree < SymbolType > & e );
template < class T > template < class T >
static std::string convert ( const T & automaton ) { static std::string convert ( const T & automaton ) {
std::stringstream ss; std::stringstream ss;
...@@ -892,8 +896,15 @@ void DotConverter::transitions(const automaton::EpsilonNFA < SymbolType, StateTy ...@@ -892,8 +896,15 @@ void DotConverter::transitions(const automaton::EpsilonNFA < SymbolType, StateTy
template < class SymbolType > template < class SymbolType >
void DotConverter::convert(std::ostream& out, const rte::FormalRTE < SymbolType > & e ) { void DotConverter::convert(std::ostream& out, const rte::FormalRTE < SymbolType > & e ) {
out << "digraph rte {\n"; out << "digraph rte {\n";
out << DotConverterRTE::convertInternal ( e ) << '\n'; DotConverterRTE::convertInternal ( out, e );
out << "}" << std::endl; out << '\n' << "}" << std::endl;
}
template < class SymbolType >
void DotConverter::convert(std::ostream& out, const tree::RankedTree < SymbolType > & e ) {
out << "digraph tree {\n";
DotConverterTree::convertInternal ( out, e );
out << '\n' << "}" << std::endl;
} }
   
template < class SymbolType, class StateType > template < class SymbolType, class StateType >
...@@ -1071,7 +1082,7 @@ void DotConverter::transitions(const automaton::ExtendedNFTA < SymbolType, State ...@@ -1071,7 +1082,7 @@ void DotConverter::transitions(const automaton::ExtendedNFTA < SymbolType, State
out << "subgraph cluster_rte_" << auxNodeCnt << "{" << '\n'; out << "subgraph cluster_rte_" << auxNodeCnt << "{" << '\n';
out << "label=\"rte_" << auxNodeCnt << "\"\n"; out << "label=\"rte_" << auxNodeCnt << "\"\n";
out << "color = blue;\n"; out << "color = blue;\n";
out << convert::DotConverterRTE::convertInternal ( rte::FormalRTE < ext::variant < SymbolType, StateType > > ( transition.first.first ), "x" + ext::to_string ( auxNodeCnt ) + "x" ); convert::DotConverterRTE::convertInternal ( out, rte::FormalRTE < ext::variant < SymbolType, StateType > > ( transition.first.first ), "x" + ext::to_string ( auxNodeCnt ) + "x" );
out << "}\n" << std::endl; out << "}\n" << std::endl;
   
out << "node [shape = point, label=\"\"]; Aux" << auxNodeCnt << ";\n"; out << "node [shape = point, label=\"\"]; Aux" << auxNodeCnt << ";\n";
......
...@@ -16,30 +16,28 @@ namespace convert { ...@@ -16,30 +16,28 @@ namespace convert {
class DotConverterRTE { class DotConverterRTE {
public: public:
template < class SymbolType > template < class SymbolType >
static std::string convertInternal ( const rte::FormalRTE < SymbolType > & rte, const std::string & nodePrefix = "" ); static void convertInternal ( std::ostream & oss, const rte::FormalRTE < SymbolType > & rte, const std::string & nodePrefix = "" );
   
template < class SymbolType > template < class SymbolType >
class Formal { class Formal {
public: public:
static unsigned visit ( const rte::FormalRTEAlternation < SymbolType > & node, std::stringstream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ); static unsigned visit ( const rte::FormalRTEAlternation < SymbolType > & node, std::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix );
static unsigned visit ( const rte::FormalRTESubstitution < SymbolType > & node, std::stringstream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ); static unsigned visit ( const rte::FormalRTESubstitution < SymbolType > & node, std::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix );
static unsigned visit ( const rte::FormalRTEIteration < SymbolType > & node, std::stringstream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ); static unsigned visit ( const rte::FormalRTEIteration < SymbolType > & node, std::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix );
static unsigned visit ( const rte::FormalRTESymbolAlphabet < SymbolType > & node, std::stringstream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ); static unsigned visit ( const rte::FormalRTESymbolAlphabet < SymbolType > & node, std::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix );
static unsigned visit ( const rte::FormalRTESymbolSubst < SymbolType > & node, std::stringstream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ); static unsigned visit ( const rte::FormalRTESymbolSubst < SymbolType > & node, std::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix );
static unsigned visit ( const rte::FormalRTEEmpty < SymbolType > & node, std::stringstream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ); static unsigned visit ( const rte::FormalRTEEmpty < SymbolType > & node, std::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix );
}; };
}; };
   
template < class SymbolType > template < class SymbolType >
std::string DotConverterRTE::convertInternal ( const rte::FormalRTE < SymbolType > & rte, const std::string & nodePrefix ) { void DotConverterRTE::convertInternal ( std::ostream & oss, const rte::FormalRTE < SymbolType > & rte, const std::string & nodePrefix ) {
std::stringstream oss;
unsigned nodeIdCounter = 0; unsigned nodeIdCounter = 0;
rte.getRTE ( ).getStructure ( ).template accept < unsigned, DotConverterRTE::Formal < SymbolType > > ( oss, nodeIdCounter, nodePrefix ); rte.getRTE ( ).getStructure ( ).template accept < unsigned, DotConverterRTE::Formal < SymbolType > > ( oss, nodeIdCounter, nodePrefix );
return oss.str ( );
} }
   
template < class SymbolType > template < class SymbolType >
unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTEAlternation < SymbolType > & node, std::stringstream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ) { unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTEAlternation < SymbolType > & node, std::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ) {
unsigned id = nodeIdCounter ++; unsigned id = nodeIdCounter ++;
   
oss << nodePrefix << id << "[label=\"+\", shape=plaintext];" << std::endl; oss << nodePrefix << id << "[label=\"+\", shape=plaintext];" << std::endl;
...@@ -53,7 +51,7 @@ unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTEAlt ...@@ -53,7 +51,7 @@ unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTEAlt
} }
   
template < class SymbolType > template < class SymbolType >
unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTESubstitution < SymbolType > & node, std::stringstream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ) { unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTESubstitution < SymbolType > & node, std::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ) {
unsigned id = nodeIdCounter ++; unsigned id = nodeIdCounter ++;
   
oss << nodePrefix << id << "[label=\". " << node.getSubstitutionSymbol( ).getSymbol ( ).getSymbol ( ) << "\", shape=plaintext];" << std::endl; oss << nodePrefix << id << "[label=\". " << node.getSubstitutionSymbol( ).getSymbol ( ).getSymbol ( ) << "\", shape=plaintext];" << std::endl;
...@@ -67,7 +65,7 @@ unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTESub ...@@ -67,7 +65,7 @@ unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTESub
} }
   
template < class SymbolType > template < class SymbolType >
unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTEIteration < SymbolType > & node, std::stringstream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ) { unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTEIteration < SymbolType > & node, std::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ) {
unsigned id = nodeIdCounter ++; unsigned id = nodeIdCounter ++;
   
oss << nodePrefix << id << "[label=\"* " << node.getSubstitutionSymbol( ).getSymbol ( ).getSymbol ( ) << "\", shape=plaintext];" << std::endl; oss << nodePrefix << id << "[label=\"* " << node.getSubstitutionSymbol( ).getSymbol ( ).getSymbol ( ) << "\", shape=plaintext];" << std::endl;
...@@ -79,7 +77,7 @@ unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTEIte ...@@ -79,7 +77,7 @@ unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTEIte
} }
   
template < class SymbolType > template < class SymbolType >
unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTESymbolAlphabet < SymbolType > & node, std::stringstream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ) { unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTESymbolAlphabet < SymbolType > & node, std::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ) {
unsigned id = nodeIdCounter ++; unsigned id = nodeIdCounter ++;
   
oss << nodePrefix << id << "[label=\"" << node.getSymbol( ).getSymbol ( ) << "\", shape=plaintext];" << std::endl; oss << nodePrefix << id << "[label=\"" << node.getSymbol( ).getSymbol ( ) << "\", shape=plaintext];" << std::endl;
...@@ -93,13 +91,13 @@ unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTESym ...@@ -93,13 +91,13 @@ unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTESym
} }
   
template < class SymbolType > template < class SymbolType >
unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTESymbolSubst < SymbolType > & node, std::stringstream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ) { unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTESymbolSubst < SymbolType > & node, std::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ) {
oss << nodePrefix << nodeIdCounter << "[label=\"" << node.getSymbol ( ).getSymbol ( ) << "\", shape=plaintext];" << std::endl; oss << nodePrefix << nodeIdCounter << "[label=\"" << node.getSymbol ( ).getSymbol ( ) << "\", shape=plaintext];" << std::endl;
return nodeIdCounter ++; return nodeIdCounter ++;
} }
   
template < class SymbolType > template < class SymbolType >
unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTEEmpty < SymbolType > & , std::stringstream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ) { unsigned DotConverterRTE::Formal < SymbolType >::visit ( const rte::FormalRTEEmpty < SymbolType > & , std::ostream & oss, unsigned & nodeIdCounter, const std::string & nodePrefix ) {
oss << nodePrefix << nodeIdCounter << "[label=\"#0\", shape=plaintext];" << std::endl; oss << nodePrefix << nodeIdCounter << "[label=\"#0\", shape=plaintext];" << std::endl;
return nodeIdCounter ++; return nodeIdCounter ++;
} }
......
/*
* DotConverterTree.h
*
* Created on: 15. 3. 2019
* Author: Tomas Pecka
*/
#ifndef _DOT_CONVERTER_TREE_H_
#define _DOT_CONVERTER_TREE_H_
#include <alphabet/string/RankedSymbol.h>
#include <tree/ranked/RankedTree.h>
namespace convert {
class DotConverterTree {
template < class SymbolType >
static unsigned convertRecursive ( const ext::tree < SymbolType > & node, std::ostream & oss, unsigned & nodeIdCounter );
public:
template < class SymbolType >
static void convertInternal ( std::ostream & oss, const tree::RankedTree < SymbolType > & tree );
};
template < class SymbolType >
void DotConverterTree::convertInternal ( std::ostream & oss, const tree::RankedTree < SymbolType > & tree ) {
unsigned nodeIdCounter = 0;
convertRecursive ( tree.getContent ( ), oss, nodeIdCounter );
}
template < class SymbolType >
unsigned DotConverterTree::convertRecursive ( const ext::tree < SymbolType > & node, std::ostream & oss, unsigned & nodeIdCounter ) {
unsigned id = nodeIdCounter ++;
oss << id << "[label=\"" + factory::StringDataFactory::toString ( node.getData ( ) ) + "\", shape=plaintext];" << std::endl;
for ( const ext::tree < SymbolType > & child : node.getChildren ( ) ) {
size_t childId = convertRecursive ( child, oss, nodeIdCounter );
oss << id << " -> " << childId << ";" << std::endl;
}
return id;
}
} /* namespace convert */
#endif /* _DOT_CONVERTER_TREE_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