From 6412194470e85c0ef77ea275cc1bd818026c86a3 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Fri, 6 May 2016 09:04:28 +0200
Subject: [PATCH] simplify constructors of tree structures

---
 alib2data/src/tree/common/TreeAuxiliary.cpp   | 25 ++++++++++++++++
 alib2data/src/tree/common/TreeAuxiliary.h     | 29 +++++++++++++++++++
 .../tree/ranked/PrefixRankedBarPattern.cpp    |  9 ++----
 .../src/tree/ranked/PrefixRankedBarPattern.h  |  1 -
 .../src/tree/ranked/PrefixRankedBarTree.cpp   |  9 ++----
 .../src/tree/ranked/PrefixRankedBarTree.h     |  1 -
 .../src/tree/ranked/PrefixRankedPattern.cpp   | 19 +++++++-----
 .../src/tree/ranked/PrefixRankedPattern.h     |  3 +-
 .../src/tree/ranked/PrefixRankedTree.cpp      | 15 ++++++----
 alib2data/src/tree/ranked/PrefixRankedTree.h  |  3 +-
 alib2data/src/tree/ranked/RankedNode.cpp      |  6 ++++
 alib2data/src/tree/ranked/RankedNode.h        |  5 ++++
 .../tree/ranked/RankedNonlinearPattern.cpp    |  8 ++---
 .../src/tree/ranked/RankedNonlinearPattern.h  |  1 -
 alib2data/src/tree/ranked/RankedPattern.cpp   | 13 +++------
 alib2data/src/tree/ranked/RankedPattern.h     |  3 +-
 alib2data/src/tree/ranked/RankedTree.cpp      | 13 +++------
 alib2data/src/tree/ranked/RankedTree.h        |  3 +-
 alib2data/src/tree/unranked/UnrankedNode.cpp  |  6 ++++
 alib2data/src/tree/unranked/UnrankedNode.h    |  5 ++++
 .../unranked/UnrankedNonlinearPattern.cpp     |  8 ++---
 .../tree/unranked/UnrankedNonlinearPattern.h  |  1 -
 .../src/tree/unranked/UnrankedPattern.cpp     | 16 ++++------
 alib2data/src/tree/unranked/UnrankedPattern.h |  5 ++--
 alib2data/src/tree/unranked/UnrankedTree.cpp  | 16 ++++------
 alib2data/src/tree/unranked/UnrankedTree.h    |  7 +++--
 26 files changed, 138 insertions(+), 92 deletions(-)
 create mode 100644 alib2data/src/tree/common/TreeAuxiliary.cpp
 create mode 100644 alib2data/src/tree/common/TreeAuxiliary.h

diff --git a/alib2data/src/tree/common/TreeAuxiliary.cpp b/alib2data/src/tree/common/TreeAuxiliary.cpp
new file mode 100644
index 0000000000..8d68d3b0ab
--- /dev/null
+++ b/alib2data/src/tree/common/TreeAuxiliary.cpp
@@ -0,0 +1,25 @@
+/*
+ * TreeAuxiliary.cpp
+ *
+ *  Created on: May 5, 2016
+ *      Author: Jan Travnicek
+ */
+
+#include "TreeAuxiliary.h"
+#include <algorithm>
+
+namespace tree {
+
+std::set < alphabet::Symbol > TreeAuxiliary::unrankSymbols ( const std::set < alphabet::RankedSymbol > & alphabet ) {
+	return std::transform < alphabet::Symbol > ( alphabet, [&] ( const alphabet::RankedSymbol & symbol) {
+			return symbol.getSymbol ( );
+	} );
+}
+
+std::set < alphabet::RankedSymbol > TreeAuxiliary::computeBars ( const std::set < alphabet::RankedSymbol > & alphabet, const alphabet::Symbol & barBase ) {
+	return std::transform < alphabet::RankedSymbol > ( alphabet, [&] ( const alphabet::RankedSymbol & symbol) {
+			return alphabet::RankedSymbol ( barBase, symbol.getRank ( ) );
+	} );
+}
+
+} /* namespace tree */
diff --git a/alib2data/src/tree/common/TreeAuxiliary.h b/alib2data/src/tree/common/TreeAuxiliary.h
new file mode 100644
index 0000000000..581c72ee63
--- /dev/null
+++ b/alib2data/src/tree/common/TreeAuxiliary.h
@@ -0,0 +1,29 @@
+/*
+ * TreeAuxiliary.h
+ *
+ *  Created on: May 5, 2016
+ *      Author: Jan Travnicek
+ */
+
+#ifndef TREE_AUXILIARY_H_
+#define TREE_AUXILIARY_H_
+
+#include <set>
+#include "../../alphabet/RankedSymbol.h"
+#include "../../alphabet/Symbol.h"
+
+namespace tree {
+
+/**
+ * Parser used to get tree from XML parsed into list of Tokens.
+ */
+class TreeAuxiliary {
+public:
+	static std::set < alphabet::Symbol > unrankSymbols ( const std::set < alphabet::RankedSymbol > & alphabet );
+	static std::set < alphabet::RankedSymbol > computeBars ( const std::set < alphabet::RankedSymbol > & alphabet, const alphabet::Symbol & barBase );
+
+};
+
+} /* namespace tree */
+
+#endif /* TREE_AUXILIARY_H_ */
diff --git a/alib2data/src/tree/ranked/PrefixRankedBarPattern.cpp b/alib2data/src/tree/ranked/PrefixRankedBarPattern.cpp
index bbdcc5dc1f..443bd4cd13 100644
--- a/alib2data/src/tree/ranked/PrefixRankedBarPattern.cpp
+++ b/alib2data/src/tree/ranked/PrefixRankedBarPattern.cpp
@@ -18,6 +18,7 @@
 #include <sax/FromXMLParserHelper.h>
 #include "../common/TreeFromXMLParser.h"
 #include "../common/TreeToXMLComposer.h"
+#include "../common/TreeAuxiliary.h"
 #include "../Tree.h"
 #include "../RankedTreeWrapper.h"
 #include <object/Object.h>
@@ -37,7 +38,7 @@ PrefixRankedBarPattern::PrefixRankedBarPattern ( std::set < alphabet::RankedSymb
 PrefixRankedBarPattern::PrefixRankedBarPattern ( std::set < alphabet::RankedSymbol > bars, alphabet::RankedSymbol variablesBar, alphabet::RankedSymbol subtreeWildcard, std::vector < alphabet::RankedSymbol > data ) : PrefixRankedBarPattern ( bars, variablesBar, subtreeWildcard, std::set < alphabet::RankedSymbol > ( data.begin ( ), data.end ( ) ) + bars + std::set < alphabet::RankedSymbol > { variablesBar, subtreeWildcard }, data ) {
 }
 
-PrefixRankedBarPattern::PrefixRankedBarPattern ( alphabet::Symbol barBase, alphabet::RankedSymbol variablesBar, const RankedPattern & tree ) : PrefixRankedBarPattern ( computeBars ( tree.getAlphabet ( ), barBase ) + std::set < alphabet::RankedSymbol > { variablesBar }, variablesBar, tree.getSubtreeWildcard ( ), tree.getAlphabet ( ) + computeBars ( tree.getAlphabet ( ), barBase ) + std::set < alphabet::RankedSymbol > { variablesBar, tree.getSubtreeWildcard ( ) }, toPrefixRankedBar ( tree.getRoot ( ), tree.getSubtreeWildcard ( ), barBase, variablesBar ) ) {
+PrefixRankedBarPattern::PrefixRankedBarPattern ( alphabet::Symbol barBase, alphabet::RankedSymbol variablesBar, const RankedPattern & tree ) : PrefixRankedBarPattern ( TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + std::set < alphabet::RankedSymbol > { variablesBar }, variablesBar, tree.getSubtreeWildcard ( ), tree.getAlphabet ( ) + TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + std::set < alphabet::RankedSymbol > { variablesBar, tree.getSubtreeWildcard ( ) }, toPrefixRankedBar ( tree.getRoot ( ), tree.getSubtreeWildcard ( ), barBase, variablesBar ) ) {
 }
 
 PrefixRankedBarPattern::PrefixRankedBarPattern ( const PrefixRankedBarTree & tree ) : PrefixRankedBarPattern ( tree.getBars() + std::set < alphabet::RankedSymbol > { alphabet::VariablesBarSymbol::RANKED_BAR_SYMBOL }, alphabet::VariablesBarSymbol::RANKED_BAR_SYMBOL, alphabet::SubtreeWildcardSymbol::RANKED_SUBTREE_WILDCARD_SYMBOL, tree.getAlphabet ( ) + std::set < alphabet::RankedSymbol > { alphabet::VariablesBarSymbol::RANKED_BAR_SYMBOL, alphabet::SubtreeWildcardSymbol::RANKED_SUBTREE_WILDCARD_SYMBOL }, tree.getContent ( ) ) {
@@ -46,12 +47,6 @@ PrefixRankedBarPattern::PrefixRankedBarPattern ( const PrefixRankedBarTree & tre
 PrefixRankedBarPattern::PrefixRankedBarPattern ( const RankedPattern & tree ) : PrefixRankedBarPattern ( alphabet::BarSymbol::BAR_SYMBOL, alphabet::VariablesBarSymbol::RANKED_BAR_SYMBOL, tree ) {
 }
 
-std::set < alphabet::RankedSymbol > PrefixRankedBarPattern::computeBars ( const std::set < alphabet::RankedSymbol > & alphabet, const alphabet::Symbol & barBase ) {
-	return std::transform < alphabet::RankedSymbol > ( alphabet, [&] ( const alphabet::RankedSymbol & symbol) {
-			return alphabet::RankedSymbol ( barBase, symbol.getRank ( ) );
-	} );
-}
-
 std::vector < alphabet::RankedSymbol > PrefixRankedBarPattern::toPrefixRankedBar ( const RankedNode & node, const alphabet::RankedSymbol & subtreeWildcard, const alphabet::Symbol & barBase, const alphabet::RankedSymbol & variablesBar ) {
 	std::vector < alphabet::RankedSymbol > res;
 	toPrefixRankedBar ( node, subtreeWildcard, barBase, variablesBar, res );
diff --git a/alib2data/src/tree/ranked/PrefixRankedBarPattern.h b/alib2data/src/tree/ranked/PrefixRankedBarPattern.h
index bb297428e3..9aeaf0a5e9 100644
--- a/alib2data/src/tree/ranked/PrefixRankedBarPattern.h
+++ b/alib2data/src/tree/ranked/PrefixRankedBarPattern.h
@@ -32,7 +32,6 @@ class VariablesBarSymbol;
 class PrefixRankedBarPattern : public RankedTreeBase, public std::Components < PrefixRankedBarPattern, alphabet::RankedSymbol, std::tuple < GeneralAlphabet, BarSymbols >, std::tuple < SubtreeWildcard, VariablesBarSymbol > > {
 	std::vector < alphabet::RankedSymbol > m_Data;
 
-	static std::set < alphabet::RankedSymbol > computeBars ( const std::set < alphabet::RankedSymbol > & alphabet, const alphabet::Symbol & barBase );
 	static void toPrefixRankedBar ( const RankedNode & node, const alphabet::RankedSymbol & subtreeWildcard, const alphabet::Symbol & barBase, const alphabet::RankedSymbol & variablesBar, std::vector < alphabet::RankedSymbol > & linearNotation );
 	static std::vector < alphabet::RankedSymbol > toPrefixRankedBar ( const RankedNode & node, const alphabet::RankedSymbol & subtreeWildcard, const alphabet::Symbol & barBase, const alphabet::RankedSymbol & variablesBar );
 
diff --git a/alib2data/src/tree/ranked/PrefixRankedBarTree.cpp b/alib2data/src/tree/ranked/PrefixRankedBarTree.cpp
index 93ecf8c81f..5f159cd3a1 100644
--- a/alib2data/src/tree/ranked/PrefixRankedBarTree.cpp
+++ b/alib2data/src/tree/ranked/PrefixRankedBarTree.cpp
@@ -17,6 +17,7 @@
 #include <sax/FromXMLParserHelper.h>
 #include "../common/TreeFromXMLParser.h"
 #include "../common/TreeToXMLComposer.h"
+#include "../common/TreeAuxiliary.h"
 #include "../Tree.h"
 #include "../RankedTreeWrapper.h"
 #include <object/Object.h>
@@ -34,18 +35,12 @@ PrefixRankedBarTree::PrefixRankedBarTree ( std::set < alphabet::RankedSymbol > b
 PrefixRankedBarTree::PrefixRankedBarTree ( std::set < alphabet::RankedSymbol > bars, std::vector < alphabet::RankedSymbol > data ) : PrefixRankedBarTree ( bars, bars + std::set < alphabet::RankedSymbol > ( data.begin ( ), data.end ( ) ), data ) {
 }
 
-PrefixRankedBarTree::PrefixRankedBarTree ( alphabet::Symbol barBase, const RankedTree & tree ) : PrefixRankedBarTree ( computeBars ( tree.getAlphabet ( ), barBase ), tree.getAlphabet ( ) + computeBars ( tree.getAlphabet ( ), barBase ), toPrefixRankedBar ( tree.getRoot ( ), barBase ) ) {
+PrefixRankedBarTree::PrefixRankedBarTree ( alphabet::Symbol barBase, const RankedTree & tree ) : PrefixRankedBarTree ( TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ), tree.getAlphabet ( ) + TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ), toPrefixRankedBar ( tree.getRoot ( ), barBase ) ) {
 }
 
 PrefixRankedBarTree::PrefixRankedBarTree ( const RankedTree & tree ) : PrefixRankedBarTree ( alphabet::BarSymbol::BAR_SYMBOL, tree ) {
 }
 
-std::set < alphabet::RankedSymbol > PrefixRankedBarTree::computeBars ( const std::set < alphabet::RankedSymbol > & alphabet, const alphabet::Symbol & barBase ) {
-	return std::transform < alphabet::RankedSymbol > ( alphabet, [&] ( const alphabet::RankedSymbol & symbol) {
-			return alphabet::RankedSymbol ( barBase, symbol.getRank ( ) );
-	} );
-}
-
 std::vector < alphabet::RankedSymbol > PrefixRankedBarTree::toPrefixRankedBar ( const RankedNode & node, const alphabet::Symbol & barBase ) {
 	std::vector < alphabet::RankedSymbol > res;
 	toPrefixRankedBar ( node, barBase, res );
diff --git a/alib2data/src/tree/ranked/PrefixRankedBarTree.h b/alib2data/src/tree/ranked/PrefixRankedBarTree.h
index 7f90319748..5f47cee80e 100644
--- a/alib2data/src/tree/ranked/PrefixRankedBarTree.h
+++ b/alib2data/src/tree/ranked/PrefixRankedBarTree.h
@@ -29,7 +29,6 @@ class BarSymbols;
 class PrefixRankedBarTree : public RankedTreeBase, public std::Components < PrefixRankedBarTree, alphabet::RankedSymbol, std::tuple < GeneralAlphabet, BarSymbols >, std::tuple < > > {
 	std::vector < alphabet::RankedSymbol > m_Data;
 
-	static std::set < alphabet::RankedSymbol > computeBars ( const std::set < alphabet::RankedSymbol > & alphabet, const alphabet::Symbol & barBase );
 	static void toPrefixRankedBar ( const RankedNode & node, const alphabet::Symbol & barBase, std::vector < alphabet::RankedSymbol > & linearNotation );
 	static std::vector < alphabet::RankedSymbol > toPrefixRankedBar ( const RankedNode & node, const alphabet::Symbol & barBase );
 
diff --git a/alib2data/src/tree/ranked/PrefixRankedPattern.cpp b/alib2data/src/tree/ranked/PrefixRankedPattern.cpp
index 1ba063ce60..2394bd862c 100644
--- a/alib2data/src/tree/ranked/PrefixRankedPattern.cpp
+++ b/alib2data/src/tree/ranked/PrefixRankedPattern.cpp
@@ -38,18 +38,23 @@ PrefixRankedPattern::PrefixRankedPattern ( alphabet::RankedSymbol subtreeWildcar
 PrefixRankedPattern::PrefixRankedPattern ( const PrefixRankedTree & tree ) : PrefixRankedPattern ( alphabet::SubtreeWildcardSymbol::RANKED_SUBTREE_WILDCARD_SYMBOL, tree.getAlphabet ( ), tree.getContent ( ) ) {
 }
 
-PrefixRankedPattern::PrefixRankedPattern ( const RankedPattern & tree ) : std::Components < PrefixRankedPattern, alphabet::RankedSymbol, std::tuple < GeneralAlphabet >, std::tuple < SubtreeWildcard > > ( std::make_tuple ( std::set < alphabet::RankedSymbol > ( tree.getAlphabet ( ) ) ), std::make_tuple ( tree.getSubtreeWildcard ( ) ) ) {
-	toPrefixRanked ( tree.getRoot ( ) );
+PrefixRankedPattern::PrefixRankedPattern ( const RankedPattern & tree ) : PrefixRankedPattern ( tree.getSubtreeWildcard ( ), tree.getAlphabet ( ), toPrefixRanked ( tree.getRoot ( ), tree.getSubtreeWildcard ( ) ) ) {
 }
 
-void PrefixRankedPattern::toPrefixRanked ( const RankedNode & node ) {
-	if ( node.getSymbol ( ) == accessElement < tree::SubtreeWildcard > ( ).get ( ) ) {
-		m_Data.push_back ( node.getSymbol ( ) );
+std::vector < alphabet::RankedSymbol > PrefixRankedPattern::toPrefixRanked ( const RankedNode & node, const alphabet::RankedSymbol & subtreeWildcard ) {
+	std::vector < alphabet::RankedSymbol > res;
+	toPrefixRanked ( node, subtreeWildcard, res );
+	return res;
+}
+
+void PrefixRankedPattern::toPrefixRanked ( const RankedNode & node, const alphabet::RankedSymbol & subtreeWildcard, std::vector < alphabet::RankedSymbol > & linearNotation ) {
+	if ( node.getSymbol ( ) == subtreeWildcard ) {
+		linearNotation.push_back ( node.getSymbol ( ) );
 	} else {
-		m_Data.push_back ( node.getSymbol ( ) );
+		linearNotation.push_back ( node.getSymbol ( ) );
 
 		for ( const std::smart_ptr < const RankedNode > & child : node.getChildren ( ) )
-			toPrefixRanked ( * child );
+			toPrefixRanked ( * child, subtreeWildcard, linearNotation );
 	}
 }
 
diff --git a/alib2data/src/tree/ranked/PrefixRankedPattern.h b/alib2data/src/tree/ranked/PrefixRankedPattern.h
index 9b9683fc5d..ca8d7b3317 100644
--- a/alib2data/src/tree/ranked/PrefixRankedPattern.h
+++ b/alib2data/src/tree/ranked/PrefixRankedPattern.h
@@ -30,7 +30,8 @@ class SubtreeWildcard;
 class PrefixRankedPattern : public RankedTreeBase, public std::Components < PrefixRankedPattern, alphabet::RankedSymbol, std::tuple < GeneralAlphabet >, std::tuple < SubtreeWildcard > > {
 	std::vector < alphabet::RankedSymbol > m_Data;
 
-	void toPrefixRanked ( const RankedNode & node );
+	static std::vector < alphabet::RankedSymbol > toPrefixRanked ( const RankedNode & node, const alphabet::RankedSymbol & subtreeWildcard );
+	static void toPrefixRanked ( const RankedNode & node, const alphabet::RankedSymbol & subtreeWildcard, std::vector < alphabet::RankedSymbol > & linearNotation ) ;
 
 public:
 	explicit PrefixRankedPattern ( alphabet::RankedSymbol subtreeWildcard, std::set < alphabet::RankedSymbol > alphabet, std::vector < alphabet::RankedSymbol > data );
diff --git a/alib2data/src/tree/ranked/PrefixRankedTree.cpp b/alib2data/src/tree/ranked/PrefixRankedTree.cpp
index abfee11826..4df9d7fd6b 100644
--- a/alib2data/src/tree/ranked/PrefixRankedTree.cpp
+++ b/alib2data/src/tree/ranked/PrefixRankedTree.cpp
@@ -32,15 +32,20 @@ PrefixRankedTree::PrefixRankedTree ( std::set < alphabet::RankedSymbol > alphabe
 PrefixRankedTree::PrefixRankedTree ( std::vector < alphabet::RankedSymbol > data ) : PrefixRankedTree ( std::set < alphabet::RankedSymbol > ( data.begin ( ), data.end ( ) ), std::move ( data ) ) {
 }
 
-PrefixRankedTree::PrefixRankedTree ( const RankedTree & tree ) : std::Components < PrefixRankedTree, alphabet::RankedSymbol, std::tuple < GeneralAlphabet >, std::tuple < > > ( std::make_tuple ( std::set < alphabet::RankedSymbol > ( tree.getAlphabet ( ) ) ), std::tuple < > ( ) ) {
-	toPrefixRanked ( tree.getRoot ( ) );
+PrefixRankedTree::PrefixRankedTree ( const RankedTree & tree ) : PrefixRankedTree ( tree.getAlphabet ( ), toPrefixRanked ( tree.getRoot ( ) ) ) {
 }
 
-void PrefixRankedTree::toPrefixRanked ( const RankedNode & node ) {
-	m_Data.push_back ( node.getSymbol ( ) );
+std::vector < alphabet::RankedSymbol > PrefixRankedTree::toPrefixRanked ( const RankedNode & node ) {
+	std::vector < alphabet::RankedSymbol > res;
+	toPrefixRanked ( node, res );
+	return res;
+}
+
+void PrefixRankedTree::toPrefixRanked ( const RankedNode & node, std::vector < alphabet::RankedSymbol > & linearNotation ) {
+	linearNotation.push_back ( node.getSymbol ( ) );
 
 	for ( const std::smart_ptr < const RankedNode > & child : node.getChildren ( ) )
-		toPrefixRanked ( * child );
+		toPrefixRanked ( * child, linearNotation );
 }
 
 RankedTreeBase * PrefixRankedTree::clone ( ) const {
diff --git a/alib2data/src/tree/ranked/PrefixRankedTree.h b/alib2data/src/tree/ranked/PrefixRankedTree.h
index c6df0a2b96..1090d5205c 100644
--- a/alib2data/src/tree/ranked/PrefixRankedTree.h
+++ b/alib2data/src/tree/ranked/PrefixRankedTree.h
@@ -28,7 +28,8 @@ class GeneralAlphabet;
 class PrefixRankedTree : public RankedTreeBase, public std::Components < PrefixRankedTree, alphabet::RankedSymbol, std::tuple < GeneralAlphabet >, std::tuple < > > {
 	std::vector < alphabet::RankedSymbol > m_Data;
 
-	void toPrefixRanked ( const RankedNode & node );
+	static std::vector < alphabet::RankedSymbol > toPrefixRanked ( const RankedNode & node );
+	static void toPrefixRanked ( const RankedNode & node, std::vector < alphabet::RankedSymbol > & linearNotation ) ;
 
 public:
 	explicit PrefixRankedTree ( std::set < alphabet::RankedSymbol > alphabet, std::vector < alphabet::RankedSymbol > data );
diff --git a/alib2data/src/tree/ranked/RankedNode.cpp b/alib2data/src/tree/ranked/RankedNode.cpp
index 74aa02e3a8..3398317c07 100644
--- a/alib2data/src/tree/ranked/RankedNode.cpp
+++ b/alib2data/src/tree/ranked/RankedNode.cpp
@@ -149,6 +149,12 @@ bool RankedNode::attachAlphabet ( const std::set < alphabet::RankedSymbol > * al
 	return true;
 }
 
+std::set < alphabet::RankedSymbol > RankedNode::computeMinimalAlphabet ( ) const {
+	std::set < alphabet::RankedSymbol > res;
+	computeMinimalAlphabet ( res );
+	return res;
+}
+
 void RankedNode::computeMinimalAlphabet ( std::set < alphabet::RankedSymbol > & alphabet ) const {
 	alphabet.insert ( this->symbol );
 
diff --git a/alib2data/src/tree/ranked/RankedNode.h b/alib2data/src/tree/ranked/RankedNode.h
index 6709235867..251a861ce7 100644
--- a/alib2data/src/tree/ranked/RankedNode.h
+++ b/alib2data/src/tree/ranked/RankedNode.h
@@ -43,6 +43,11 @@ protected:
 	 */
 	void computeMinimalAlphabet ( std::set < alphabet::RankedSymbol > & alphabet ) const;
 
+	/**
+	 * @copydoc RankedNode::computeMinimalAlphabet()
+	 */
+	std::set < alphabet::RankedSymbol > computeMinimalAlphabet ( ) const;
+
 public:
 	explicit RankedNode ( alphabet::RankedSymbol symbol, std::vector < std::smart_ptr < RankedNode > > children );
 
diff --git a/alib2data/src/tree/ranked/RankedNonlinearPattern.cpp b/alib2data/src/tree/ranked/RankedNonlinearPattern.cpp
index 6b4962fedf..47e2dbc57d 100644
--- a/alib2data/src/tree/ranked/RankedNonlinearPattern.cpp
+++ b/alib2data/src/tree/ranked/RankedNonlinearPattern.cpp
@@ -29,14 +29,10 @@ RankedNonlinearPattern::RankedNonlinearPattern ( alphabet::RankedSymbol subtreeW
 	setTree ( std::move ( pattern ) );
 }
 
-RankedNonlinearPattern::RankedNonlinearPattern ( alphabet::RankedSymbol subtreeWildcard, std::set < alphabet::RankedSymbol > nonlinearVariables, RankedNode pattern ) : std::Components < RankedNonlinearPattern, alphabet::RankedSymbol, std::tuple < GeneralAlphabet, NonlinearAlphabet >, std::tuple < SubtreeWildcard > > ( std::make_tuple ( nonlinearVariables + std::set < alphabet::RankedSymbol > { subtreeWildcard }, nonlinearVariables ), std::make_tuple ( subtreeWildcard ) ), pattern ( nullptr ) {
-	pattern.computeMinimalAlphabet ( accessComponent < GeneralAlphabet > ( ).get ( ) );
-	setTree ( std::move ( pattern ) );
+RankedNonlinearPattern::RankedNonlinearPattern ( alphabet::RankedSymbol subtreeWildcard, std::set < alphabet::RankedSymbol > nonlinearVariables, RankedNode pattern ) : RankedNonlinearPattern ( subtreeWildcard, nonlinearVariables, pattern.computeMinimalAlphabet() + nonlinearVariables + std::set < alphabet::RankedSymbol > { subtreeWildcard }, pattern ) {
 }
 
-RankedNonlinearPattern::RankedNonlinearPattern ( alphabet::RankedSymbol subtreeWildcard, RankedNode pattern ) : std::Components < RankedNonlinearPattern, alphabet::RankedSymbol, std::tuple < GeneralAlphabet, NonlinearAlphabet >, std::tuple < SubtreeWildcard > > ( std::make_tuple ( std::set < alphabet::RankedSymbol > { subtreeWildcard }, std::set < alphabet::RankedSymbol > { } ), std::make_tuple ( subtreeWildcard ) ), pattern ( nullptr ) {
-	pattern.computeMinimalAlphabet ( accessComponent < GeneralAlphabet > ( ).get ( ) );
-	setTree ( std::move ( pattern ) );
+RankedNonlinearPattern::RankedNonlinearPattern ( alphabet::RankedSymbol subtreeWildcard, RankedNode pattern ) : RankedNonlinearPattern ( subtreeWildcard, std::set < alphabet::RankedSymbol > { }, pattern ) {
 }
 
 RankedNonlinearPattern::RankedNonlinearPattern ( const RankedNonlinearPattern & other ) : std::Components < RankedNonlinearPattern, alphabet::RankedSymbol, std::tuple < GeneralAlphabet, NonlinearAlphabet >, std::tuple < SubtreeWildcard > > ( std::make_tuple ( other.getAlphabet ( ), other.getNonlinearVariables ( ) ), std::make_tuple ( other.getSubtreeWildcard ( ) ) ), pattern ( other.pattern ) {
diff --git a/alib2data/src/tree/ranked/RankedNonlinearPattern.h b/alib2data/src/tree/ranked/RankedNonlinearPattern.h
index 3f2410327c..922bf2f89d 100644
--- a/alib2data/src/tree/ranked/RankedNonlinearPattern.h
+++ b/alib2data/src/tree/ranked/RankedNonlinearPattern.h
@@ -28,7 +28,6 @@ class NonlinearAlphabet;
  * as a pattern of RegExpElement.
  */
 class RankedNonlinearPattern : public RankedTreeBase, public std::Components < RankedNonlinearPattern, alphabet::RankedSymbol, std::tuple < GeneralAlphabet, NonlinearAlphabet >, std::tuple < SubtreeWildcard > > {
-protected:
 	std::smart_ptr < RankedNode > pattern;
 
 public:
diff --git a/alib2data/src/tree/ranked/RankedPattern.cpp b/alib2data/src/tree/ranked/RankedPattern.cpp
index 6e997bf164..bb46e7534d 100644
--- a/alib2data/src/tree/ranked/RankedPattern.cpp
+++ b/alib2data/src/tree/ranked/RankedPattern.cpp
@@ -25,19 +25,14 @@
 
 namespace tree {
 
-RankedPattern::RankedPattern ( const UnrankedPattern & other ) : std::Components < RankedPattern, alphabet::RankedSymbol, std::tuple < GeneralAlphabet >, std::tuple < SubtreeWildcard > > ( std::make_tuple ( std::set < alphabet::RankedSymbol > { alphabet::RankedSymbol ( other.getSubtreeWildcard ( ), 0 ) } ), std::make_tuple ( alphabet::RankedSymbol ( other.getSubtreeWildcard ( ), 0 ) ) ), pattern ( std::make_smart < RankedNode > ( other.getRoot ( ).asRanked ( ) ) ) {
-	pattern->computeMinimalAlphabet ( accessComponent < GeneralAlphabet > ( ).get ( ) );
-
-	this->pattern->attachAlphabet ( & ( this->getAlphabet ( ) ) );
-}
-
 RankedPattern::RankedPattern ( alphabet::RankedSymbol subtreeWildcard, std::set < alphabet::RankedSymbol > alphabet, RankedNode pattern ) : std::Components < RankedPattern, alphabet::RankedSymbol, std::tuple < GeneralAlphabet >, std::tuple < SubtreeWildcard > > ( std::make_tuple ( std::move ( alphabet ) ), std::make_tuple ( std::move ( subtreeWildcard ) ) ), pattern ( nullptr ) {
 	setTree ( std::move ( pattern ) );
 }
 
-RankedPattern::RankedPattern ( alphabet::RankedSymbol subtreeWildcard, RankedNode pattern ) : std::Components < RankedPattern, alphabet::RankedSymbol, std::tuple < GeneralAlphabet >, std::tuple < SubtreeWildcard > > ( std::make_tuple ( std::set < alphabet::RankedSymbol > { subtreeWildcard } ), std::make_tuple ( subtreeWildcard ) ), pattern ( nullptr ) {
-	pattern.computeMinimalAlphabet ( accessComponent < GeneralAlphabet > ( ).get ( ) );
-	setTree ( std::move ( pattern ) );
+RankedPattern::RankedPattern ( alphabet::RankedSymbol subtreeWildcard, RankedNode pattern ) : RankedPattern ( subtreeWildcard, pattern.computeMinimalAlphabet() + std::set < alphabet::RankedSymbol > { subtreeWildcard }, pattern ) {
+}
+
+RankedPattern::RankedPattern ( const UnrankedPattern & other ) : RankedPattern ( alphabet::RankedSymbol ( other.getSubtreeWildcard ( ), 0 ), other.getRoot ( ).asRanked ( ) ) {
 }
 
 RankedPattern::RankedPattern ( const RankedPattern & other ) : std::Components < RankedPattern, alphabet::RankedSymbol, std::tuple < GeneralAlphabet >, std::tuple < SubtreeWildcard > > ( std::make_tuple ( other.getAlphabet ( ) ), std::make_tuple ( other.getSubtreeWildcard ( ) ) ), pattern ( other.pattern ) {
diff --git a/alib2data/src/tree/ranked/RankedPattern.h b/alib2data/src/tree/ranked/RankedPattern.h
index 931dc8abbe..6588504793 100644
--- a/alib2data/src/tree/ranked/RankedPattern.h
+++ b/alib2data/src/tree/ranked/RankedPattern.h
@@ -27,7 +27,6 @@ class SubtreeWildcard;
  * as a pattern of RegExpElement.
  */
 class RankedPattern : public RankedTreeBase, public std::Components < RankedPattern, alphabet::RankedSymbol, std::tuple < GeneralAlphabet >, std::tuple < SubtreeWildcard > > {
-protected:
 	std::smart_ptr < RankedNode > pattern;
 
 public:
@@ -41,9 +40,9 @@ public:
 	 */
 	virtual RankedTreeBase * plunder ( ) &&;
 
-	explicit RankedPattern ( const UnrankedPattern & other );
 	explicit RankedPattern ( alphabet::RankedSymbol subtreeWildcard, std::set < alphabet::RankedSymbol > alphabet, RankedNode pattern );
 	explicit RankedPattern ( alphabet::RankedSymbol subtreeWildcard, RankedNode pattern );
+	explicit RankedPattern ( const UnrankedPattern & other );
 
 	/**
 	 * Copy constructor.
diff --git a/alib2data/src/tree/ranked/RankedTree.cpp b/alib2data/src/tree/ranked/RankedTree.cpp
index 309f645b32..2242b76399 100644
--- a/alib2data/src/tree/ranked/RankedTree.cpp
+++ b/alib2data/src/tree/ranked/RankedTree.cpp
@@ -25,19 +25,14 @@
 
 namespace tree {
 
-RankedTree::RankedTree ( const UnrankedTree & other ) : std::Components < RankedTree, alphabet::RankedSymbol, std::tuple < GeneralAlphabet >, std::tuple < > > ( std::make_tuple ( std::set < alphabet::RankedSymbol > { } ), std::tuple < > ( ) ), tree ( std::make_smart < RankedNode > ( other.getRoot ( ).asRanked ( ) ) ) {
-	tree->computeMinimalAlphabet ( accessComponent < GeneralAlphabet > ( ).get ( ) );
-
-	this->tree->attachAlphabet ( & ( this->getAlphabet ( ) ) );
-}
-
 RankedTree::RankedTree ( std::set < alphabet::RankedSymbol > alphabet, RankedNode tree ) : std::Components < RankedTree, alphabet::RankedSymbol, std::tuple < GeneralAlphabet >, std::tuple < > > ( std::make_tuple ( std::move ( alphabet ) ), std::tuple < > ( ) ), tree ( nullptr ) {
 	setTree ( std::move ( tree ) );
 }
 
-RankedTree::RankedTree ( RankedNode tree ) : std::Components < RankedTree, alphabet::RankedSymbol, std::tuple < GeneralAlphabet >, std::tuple < > > ( std::make_tuple ( std::set < alphabet::RankedSymbol > { } ), std::tuple < > ( ) ), tree ( nullptr ) {
-	tree.computeMinimalAlphabet ( accessComponent < GeneralAlphabet > ( ).get ( ) );
-	setTree ( std::move ( tree ) );
+RankedTree::RankedTree ( RankedNode tree ) : RankedTree ( tree.computeMinimalAlphabet ( ), tree ) {
+}
+
+RankedTree::RankedTree ( const UnrankedTree & other ) : RankedTree ( other.getRoot ( ).asRanked ( ) ) {
 }
 
 RankedTree::RankedTree ( const RankedTree & other ) : std::Components < RankedTree, alphabet::RankedSymbol, std::tuple < GeneralAlphabet >, std::tuple < > > ( std::make_tuple ( other.getAlphabet ( ) ), std::tuple < > ( ) ), tree ( other.tree ) {
diff --git a/alib2data/src/tree/ranked/RankedTree.h b/alib2data/src/tree/ranked/RankedTree.h
index 3727d052fc..c7612b84b8 100644
--- a/alib2data/src/tree/ranked/RankedTree.h
+++ b/alib2data/src/tree/ranked/RankedTree.h
@@ -26,7 +26,6 @@ class GeneralAlphabet;
  * as a tree of RegExpElement.
  */
 class RankedTree : public RankedTreeBase, public std::Components < RankedTree, alphabet::RankedSymbol, std::tuple < GeneralAlphabet >, std::tuple < > > {
-protected:
 	std::smart_ptr < RankedNode > tree;
 
 public:
@@ -40,9 +39,9 @@ public:
 	 */
 	virtual RankedTreeBase * plunder ( ) &&;
 
-	explicit RankedTree ( const UnrankedTree & other );
 	explicit RankedTree ( std::set < alphabet::RankedSymbol > alphabet, RankedNode tree );
 	explicit RankedTree ( RankedNode tree );
+	explicit RankedTree ( const UnrankedTree & other );
 
 	/**
 	 * Copy constructor.
diff --git a/alib2data/src/tree/unranked/UnrankedNode.cpp b/alib2data/src/tree/unranked/UnrankedNode.cpp
index 7163f5d7d5..82f31c7ca9 100644
--- a/alib2data/src/tree/unranked/UnrankedNode.cpp
+++ b/alib2data/src/tree/unranked/UnrankedNode.cpp
@@ -154,6 +154,12 @@ bool UnrankedNode::attachAlphabet ( const std::set < alphabet::Symbol > * alphab
 	return true;
 }
 
+std::set < alphabet::Symbol > UnrankedNode::computeMinimalAlphabet ( ) const {
+	std::set < alphabet::Symbol > res;
+	computeMinimalAlphabet ( res );
+	return res;
+}
+
 void UnrankedNode::computeMinimalAlphabet ( std::set < alphabet::Symbol > & alphabet ) const {
 	alphabet.insert ( this->symbol );
 
diff --git a/alib2data/src/tree/unranked/UnrankedNode.h b/alib2data/src/tree/unranked/UnrankedNode.h
index 30de24cb55..cf4c2b0645 100644
--- a/alib2data/src/tree/unranked/UnrankedNode.h
+++ b/alib2data/src/tree/unranked/UnrankedNode.h
@@ -43,6 +43,11 @@ protected:
 	 */
 	void computeMinimalAlphabet ( std::set < alphabet::Symbol > & alphabet ) const;
 
+	/**
+	 * @copydoc RankedNode::computeMinimalAlphabet()
+	 */
+	std::set < alphabet::Symbol > computeMinimalAlphabet ( ) const;
+
 public:
 	explicit UnrankedNode ( alphabet::Symbol symbol, std::vector < std::smart_ptr < UnrankedNode > > children );
 
diff --git a/alib2data/src/tree/unranked/UnrankedNonlinearPattern.cpp b/alib2data/src/tree/unranked/UnrankedNonlinearPattern.cpp
index 8732a8fcc8..5bb1120de0 100644
--- a/alib2data/src/tree/unranked/UnrankedNonlinearPattern.cpp
+++ b/alib2data/src/tree/unranked/UnrankedNonlinearPattern.cpp
@@ -29,14 +29,10 @@ UnrankedNonlinearPattern::UnrankedNonlinearPattern ( alphabet::Symbol subtreeWil
 	setTree ( std::move ( pattern ) );
 }
 
-UnrankedNonlinearPattern::UnrankedNonlinearPattern ( alphabet::Symbol subtreeWildcard, std::set < alphabet::Symbol > nonlinearVariables, UnrankedNode pattern ) : std::Components < UnrankedNonlinearPattern, alphabet::Symbol, std::tuple < GeneralAlphabet, NonlinearAlphabet >, std::tuple < SubtreeWildcard > > ( std::make_tuple ( nonlinearVariables + std::set < alphabet::Symbol > { subtreeWildcard }, nonlinearVariables ), std::make_tuple ( subtreeWildcard ) ), pattern ( nullptr ) {
-	pattern.computeMinimalAlphabet ( accessComponent < GeneralAlphabet > ( ).get ( ) );
-	setTree ( std::move ( pattern ) );
+UnrankedNonlinearPattern::UnrankedNonlinearPattern ( alphabet::Symbol subtreeWildcard, std::set < alphabet::Symbol > nonlinearVariables, UnrankedNode pattern ) : UnrankedNonlinearPattern ( subtreeWildcard, nonlinearVariables, pattern.computeMinimalAlphabet() + nonlinearVariables + std::set < alphabet::Symbol > { subtreeWildcard }, pattern ) {
 }
 
-UnrankedNonlinearPattern::UnrankedNonlinearPattern ( alphabet::Symbol subtreeWildcard, UnrankedNode pattern ) : std::Components < UnrankedNonlinearPattern, alphabet::Symbol, std::tuple < GeneralAlphabet, NonlinearAlphabet >, std::tuple < SubtreeWildcard > > ( std::make_tuple ( std::set < alphabet::Symbol > { subtreeWildcard }, std::set < alphabet::Symbol > { } ), std::make_tuple ( subtreeWildcard ) ), pattern ( NULL ) {
-	pattern.computeMinimalAlphabet ( accessComponent < GeneralAlphabet > ( ).get ( ) );
-	setTree ( std::move ( pattern ) );
+UnrankedNonlinearPattern::UnrankedNonlinearPattern ( alphabet::Symbol subtreeWildcard, UnrankedNode pattern ) : UnrankedNonlinearPattern ( subtreeWildcard, std::set < alphabet::Symbol > { }, pattern ) {
 }
 
 UnrankedNonlinearPattern::UnrankedNonlinearPattern ( const UnrankedNonlinearPattern & other ) : std::Components < UnrankedNonlinearPattern, alphabet::Symbol, std::tuple < GeneralAlphabet, NonlinearAlphabet >, std::tuple < SubtreeWildcard > > ( std::make_tuple ( other.getAlphabet ( ), other.getNonlinearVariables ( ) ), std::make_tuple ( other.getSubtreeWildcard ( ) ) ), pattern ( other.pattern ) {
diff --git a/alib2data/src/tree/unranked/UnrankedNonlinearPattern.h b/alib2data/src/tree/unranked/UnrankedNonlinearPattern.h
index e0e5613756..f896e933cc 100644
--- a/alib2data/src/tree/unranked/UnrankedNonlinearPattern.h
+++ b/alib2data/src/tree/unranked/UnrankedNonlinearPattern.h
@@ -28,7 +28,6 @@ class NonlinearAlphabet;
  * as a pattern of RegExpElement.
  */
 class UnrankedNonlinearPattern : public UnrankedTreeBase, public std::Components < UnrankedNonlinearPattern, alphabet::Symbol, std::tuple < GeneralAlphabet, NonlinearAlphabet >, std::tuple < SubtreeWildcard > > {
-protected:
 	std::smart_ptr < UnrankedNode > pattern;
 
 public:
diff --git a/alib2data/src/tree/unranked/UnrankedPattern.cpp b/alib2data/src/tree/unranked/UnrankedPattern.cpp
index bda841f24b..b0151f7877 100644
--- a/alib2data/src/tree/unranked/UnrankedPattern.cpp
+++ b/alib2data/src/tree/unranked/UnrankedPattern.cpp
@@ -17,6 +17,7 @@
 #include <sax/FromXMLParserHelper.h>
 #include "../common/TreeFromXMLParser.h"
 #include "../common/TreeToXMLComposer.h"
+#include "../common/TreeAuxiliary.h"
 #include "../Tree.h"
 #include "../UnrankedTreeWrapper.h"
 #include <object/Object.h>
@@ -25,21 +26,14 @@
 
 namespace tree {
 
-UnrankedPattern::UnrankedPattern ( const RankedPattern & other ) : std::Components < UnrankedPattern, alphabet::Symbol, std::tuple < GeneralAlphabet >, std::tuple < SubtreeWildcard > > ( std::make_tuple ( std::set < alphabet::Symbol > { other.getSubtreeWildcard ( ).getSymbol ( ) } ), std::make_tuple ( other.getSubtreeWildcard ( ).getSymbol ( ) ) ), pattern ( std::make_smart < UnrankedNode > ( other.getRoot ( ).asUnranked ( ) ) ) {
-	std::transform ( other.getAlphabet ( ).begin ( ), other.getAlphabet ( ).end ( ), std::inserter ( accessComponent < GeneralAlphabet > ( ).get ( ), getAlphabet ( ).begin ( ) ), [] ( const alphabet::RankedSymbol & symbol ) {
-			return symbol.getSymbol ( );
-		} );
-
-	this->pattern->attachAlphabet ( & ( this->getAlphabet ( ) ) );
-}
-
 UnrankedPattern::UnrankedPattern ( alphabet::Symbol subtreeWildcard, std::set < alphabet::Symbol > alphabet, UnrankedNode pattern ) : std::Components < UnrankedPattern, alphabet::Symbol, std::tuple < GeneralAlphabet >, std::tuple < SubtreeWildcard > > ( std::make_tuple ( std::move ( alphabet ) ), std::make_tuple ( std::move ( subtreeWildcard ) ) ), pattern ( nullptr ) {
 	setTree ( std::move ( pattern ) );
 }
 
-UnrankedPattern::UnrankedPattern ( alphabet::Symbol subtreeWildcard, UnrankedNode pattern ) : std::Components < UnrankedPattern, alphabet::Symbol, std::tuple < GeneralAlphabet >, std::tuple < SubtreeWildcard > > ( std::make_tuple ( std::set < alphabet::Symbol > { subtreeWildcard } ), std::make_tuple ( subtreeWildcard ) ), pattern ( nullptr ) {
-	pattern.computeMinimalAlphabet ( accessComponent < GeneralAlphabet > ( ).get ( ) );
-	setTree ( std::move ( pattern ) );
+UnrankedPattern::UnrankedPattern ( alphabet::Symbol subtreeWildcard, UnrankedNode pattern ) : UnrankedPattern ( subtreeWildcard, pattern.computeMinimalAlphabet() + std::set < alphabet::Symbol > { subtreeWildcard }, pattern ) {
+}
+
+UnrankedPattern::UnrankedPattern ( const RankedPattern & other ) : UnrankedPattern ( other.getSubtreeWildcard ( ).getSymbol ( ), TreeAuxiliary::unrankSymbols ( other.getAlphabet ( ) ), other.getRoot ( ).asUnranked ( ) ) {
 }
 
 UnrankedPattern::UnrankedPattern ( const UnrankedPattern & other ) : std::Components < UnrankedPattern, alphabet::Symbol, std::tuple < GeneralAlphabet >, std::tuple < SubtreeWildcard > > ( std::make_tuple ( other.getAlphabet ( ) ), std::make_tuple ( other.getSubtreeWildcard ( ) ) ), pattern ( other.pattern ) {
diff --git a/alib2data/src/tree/unranked/UnrankedPattern.h b/alib2data/src/tree/unranked/UnrankedPattern.h
index f720a759c8..a817d626b0 100644
--- a/alib2data/src/tree/unranked/UnrankedPattern.h
+++ b/alib2data/src/tree/unranked/UnrankedPattern.h
@@ -15,6 +15,8 @@
 #include "UnrankedNode.h"
 #include "../UnrankedTreeBase.h"
 
+#include "../../alphabet/RankedSymbol.h"
+
 namespace tree {
 
 class UnrankedNode;
@@ -27,7 +29,6 @@ class SubtreeWildcard;
  * as a pattern of RegExpElement.
  */
 class UnrankedPattern : public UnrankedTreeBase, public std::Components < UnrankedPattern, alphabet::Symbol, std::tuple < GeneralAlphabet >, std::tuple < SubtreeWildcard > > {
-protected:
 	std::smart_ptr < UnrankedNode > pattern;
 
 public:
@@ -41,9 +42,9 @@ public:
 	 */
 	virtual UnrankedTreeBase * plunder ( ) &&;
 
-	explicit UnrankedPattern ( const RankedPattern & other );
 	explicit UnrankedPattern ( alphabet::Symbol subtreeWildcard, std::set < alphabet::Symbol > alphabet, UnrankedNode pattern );
 	explicit UnrankedPattern ( alphabet::Symbol subtreeWildcard, UnrankedNode pattern );
+	explicit UnrankedPattern ( const RankedPattern & other );
 
 	/**
 	 * Copy constructor.
diff --git a/alib2data/src/tree/unranked/UnrankedTree.cpp b/alib2data/src/tree/unranked/UnrankedTree.cpp
index 5c1a0f75cb..dbbba96be6 100644
--- a/alib2data/src/tree/unranked/UnrankedTree.cpp
+++ b/alib2data/src/tree/unranked/UnrankedTree.cpp
@@ -17,6 +17,7 @@
 #include <sax/FromXMLParserHelper.h>
 #include "../common/TreeFromXMLParser.h"
 #include "../common/TreeToXMLComposer.h"
+#include "../common/TreeAuxiliary.h"
 #include "../Tree.h"
 #include "../UnrankedTreeWrapper.h"
 #include <object/Object.h>
@@ -25,21 +26,14 @@
 
 namespace tree {
 
-UnrankedTree::UnrankedTree ( const RankedTree & other ) : std::Components < UnrankedTree, alphabet::Symbol, std::tuple < GeneralAlphabet >, std::tuple < > > ( std::make_tuple ( std::set < alphabet::Symbol > { } ), std::tuple < > ( ) ), tree ( std::make_smart < UnrankedNode > ( other.getRoot ( ).asUnranked ( ) ) ) {
-	std::transform ( other.getAlphabet ( ).begin ( ), other.getAlphabet ( ).end ( ), std::inserter ( accessComponent < GeneralAlphabet > ( ).get ( ), getAlphabet ( ).begin ( ) ), [] ( const alphabet::RankedSymbol & symbol ) {
-			return symbol.getSymbol ( );
-		} );
-
-	this->tree->attachAlphabet ( & ( this->getAlphabet ( ) ) );
-}
-
 UnrankedTree::UnrankedTree ( std::set < alphabet::Symbol > alphabet, UnrankedNode tree ) : std::Components < UnrankedTree, alphabet::Symbol, std::tuple < GeneralAlphabet >, std::tuple < > > ( std::make_tuple ( std::move ( alphabet ) ), std::tuple < > ( ) ), tree ( nullptr ) {
 	setTree ( std::move ( tree ) );
 }
 
-UnrankedTree::UnrankedTree ( UnrankedNode tree ) : std::Components < UnrankedTree, alphabet::Symbol, std::tuple < GeneralAlphabet >, std::tuple < > > ( std::make_tuple ( std::set < alphabet::Symbol > { } ), std::tuple < > ( ) ), tree ( nullptr ) {
-	tree.computeMinimalAlphabet ( accessComponent < GeneralAlphabet > ( ).get ( ) );
-	setTree ( std::move ( tree ) );
+UnrankedTree::UnrankedTree ( UnrankedNode pattern ) : UnrankedTree ( pattern.computeMinimalAlphabet(), pattern ) {
+}
+
+UnrankedTree::UnrankedTree ( const RankedTree & other ) : UnrankedTree ( TreeAuxiliary::unrankSymbols ( other.getAlphabet ( ) ), other.getRoot ( ).asUnranked ( ) ) {
 }
 
 UnrankedTree::UnrankedTree ( const UnrankedTree & other ) : std::Components < UnrankedTree, alphabet::Symbol, std::tuple < GeneralAlphabet >, std::tuple < > > ( std::make_tuple ( other.getAlphabet ( ) ), std::tuple < > ( ) ), tree ( other.tree ) {
diff --git a/alib2data/src/tree/unranked/UnrankedTree.h b/alib2data/src/tree/unranked/UnrankedTree.h
index 12da03ddcb..90201ee177 100644
--- a/alib2data/src/tree/unranked/UnrankedTree.h
+++ b/alib2data/src/tree/unranked/UnrankedTree.h
@@ -15,6 +15,8 @@
 #include "UnrankedNode.h"
 #include "../UnrankedTreeBase.h"
 
+#include "../../alphabet/RankedSymbol.h"
+
 namespace tree {
 
 class UnrankedNode;
@@ -26,9 +28,10 @@ class GeneralAlphabet;
  * as a tree of RegExpElement.
  */
 class UnrankedTree : public UnrankedTreeBase, public std::Components < UnrankedTree, alphabet::Symbol, std::tuple < GeneralAlphabet >, std::tuple < > > {
-protected:
 	std::smart_ptr < UnrankedNode > tree;
 
+	static std::set < alphabet::Symbol > unrankSymbols ( const std::set < alphabet::RankedSymbol > & alphabet );
+
 public:
 	/**
 	 * @copydoc UnrankedNode::clone() const
@@ -40,9 +43,9 @@ public:
 	 */
 	virtual UnrankedTreeBase * plunder ( ) &&;
 
-	explicit UnrankedTree ( const RankedTree & other );
 	explicit UnrankedTree ( std::set < alphabet::Symbol > alphabet, UnrankedNode tree );
 	explicit UnrankedTree ( UnrankedNode tree );
+	explicit UnrankedTree ( const RankedTree & other );
 
 	/**
 	 * Copy constructor.
-- 
GitLab