/*
 * ExactNonlinearTreePatternAutomaton.h
 *
 *  Created on: 7. 4. 2015
 *      Author: Jan Travnicek
 */

#ifndef _EXACT_NONLINEAR_TREE_PATTERN_AUTOMATON_H__
#define _EXACT_NONLINEAR_TREE_PATTERN_AUTOMATON_H__

#include <automaton/AutomatonFeatures.h>
#include <tree/TreeFeatures.h>
#include <core/multipleDispatch.hpp>
#include <alphabet/RankedSymbol.h>

#include <vector>

namespace arbology {

namespace exact {

class ExactNonlinearTreePatternAutomaton : public std::SingleDispatch < ExactNonlinearTreePatternAutomaton, automaton::Automaton, const tree::TreeBase &, const DefaultSymbolType &, const std::set < DefaultSymbolType > & > {
	static automaton::InputDrivenNPDA < > constructInternal ( const tree::PrefixRankedTree < > & tree, const DefaultSymbolType & subtreeWildcard, const DefaultSymbolType & currentNonlinearVariable, const std::set < DefaultSymbolType > & nonlinearVariables );

	static void constructTail ( automaton::InputDrivenNPDA < > & res, const tree::PrefixRankedTree < > & tree, const DefaultSymbolType & subtreeWildcard, const DefaultSymbolType & currentNonlinearVariable, const std::set < DefaultSymbolType > & nonlinearVariables, const std::ranked_symbol < > & subtreeSettings, unsigned subtreeId, std::vector < std::ranked_symbol < > >::const_iterator rankedSymbolsIter, int i, std::vector < std::ranked_symbol < > >::const_iterator subtreeRepeatsIter );

public:
	/**
	 * Performs conversion.
	 * @return left regular grammar equivalent to source automaton.
	 */
	static automaton::Automaton construct ( const tree::Tree & tree, const DefaultSymbolType & subtreeWildcard, const std::set < DefaultSymbolType > & nonlinearVariables );

	static automaton::InputDrivenNPDA < > construct ( const tree::PrefixRankedTree < > & tree, const DefaultSymbolType & subtreeWildcard, const std::set < DefaultSymbolType > & nonlinearVariables );
};

} /* namespace exact */

} /* namespace arbology */

#endif /* _EXACT_NONLINEAR_TREE_PATTERN_AUTOMATON_H__ */