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

ranked bar notation to tree pattern automaton

parent 244d6662
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -14,6 +14,8 @@ namespace exact {
 
auto ExactTreePatternAutomatonPrefixRankedTree = registration::AbstractRegister < ExactTreePatternAutomaton, automaton::InputDrivenNPDA < common::ranked_symbol < DefaultSymbolType, DefaultRankType >, char, unsigned >, const tree::PrefixRankedTree < > &, const common::ranked_symbol < DefaultSymbolType, DefaultRankType > & > ( ExactTreePatternAutomaton::construct );
 
auto ExactTreePatternAutomatonPrefixRankedBarTree = registration::AbstractRegister < ExactTreePatternAutomaton, automaton::InputDrivenNPDA < common::ranked_symbol < DefaultSymbolType, DefaultRankType >, char, unsigned >, const tree::PrefixRankedBarTree < > &, const common::ranked_symbol < DefaultSymbolType, DefaultRankType > &, const common::ranked_symbol < DefaultSymbolType, DefaultRankType > & > ( ExactTreePatternAutomaton::construct );
} /* namespace exact */
 
} /* namespace arbology */
......@@ -9,7 +9,10 @@
#define _EXACT_TREE_PATTERN_AUTOMATON_H__
 
#include <alphabet/SubtreeWildcardSymbol.h>
#include <tree/ranked/PrefixRankedTree.h>
#include <tree/ranked/PrefixRankedBarTree.h>
#include <automaton/PDA/InputDrivenNPDA.h>
 
#include <alib/deque>
......@@ -21,13 +24,64 @@ namespace exact {
class ExactTreePatternAutomaton {
public:
/**
* Performs conversion.
* @return left regular grammar equivalent to source automaton.
* Construct a tree pattern automaton.
* @return input driven automaton implementing an index for tree patterns.
*/
template < class SymbolType, class RankType >
static automaton::InputDrivenNPDA < common::ranked_symbol < SymbolType, RankType >, char, unsigned > construct ( const tree::PrefixRankedBarTree < SymbolType, RankType > & tree, const common::ranked_symbol < SymbolType, RankType > & subtreeWildcard, const common::ranked_symbol < SymbolType, RankType > & variablesBar );
/**
* Construct a tree pattern automaton.
* @return input driven automaton implementing an index for tree patterns.
*/
template < class SymbolType, class RankType >
static automaton::InputDrivenNPDA < common::ranked_symbol < SymbolType, RankType >, char, unsigned > construct ( const tree::PrefixRankedTree < SymbolType, RankType > & tree, const common::ranked_symbol < SymbolType, RankType > & subtreeWildcard );
};
 
template < class SymbolType, class RankType >
automaton::InputDrivenNPDA < common::ranked_symbol < SymbolType, RankType >, char, unsigned > ExactTreePatternAutomaton::construct ( const tree::PrefixRankedBarTree < SymbolType, RankType > & tree, const common::ranked_symbol < SymbolType, RankType > & subtreeWildcard, const common::ranked_symbol < SymbolType, RankType > & variablesBar ) {
char S = alphabet::SubtreeWildcardSymbol::instance < char > ( );
automaton::InputDrivenNPDA < common::ranked_symbol < SymbolType, RankType >, char, unsigned > res ( 0, S );
for ( const common::ranked_symbol < SymbolType, RankType > & symbol : tree.getAlphabet ( ) ) {
res.addInputSymbol ( symbol );
if ( tree.getBars ( ).count ( symbol ) )
res.setPushdownStoreOperation ( symbol, ext::vector < char > ( 1, S ), ext::vector < char > { } );
else
res.setPushdownStoreOperation ( symbol, ext::vector < char > { }, ext::vector < char > ( 1, S ) );
}
res.addInputSymbol ( subtreeWildcard );
res.setPushdownStoreOperation ( subtreeWildcard, ext::vector < char > ( 1, S ), ext::vector < char > { } );
res.addInputSymbol ( variablesBar );
res.setPushdownStoreOperation ( variablesBar, ext::vector < char > { }, ext::vector < char > ( 1, S ) );
unsigned i = 1;
ext::deque < unsigned > subtreeJumps;
for ( const common::ranked_symbol < SymbolType, RankType > & symbol : tree.getContent ( ) ) {
res.addState ( i );
res.addTransition ( i - 1, symbol, i );
res.addTransition ( 0, std::move ( symbol ), i );
if ( tree.getBars ( ).count ( symbol ) ) {
unsigned source = subtreeJumps.back ( );
subtreeJumps.pop_back ( );
res.addState ( ~0 - i );
res.addTransition ( source, subtreeWildcard, ~0 - i );
res.addTransition ( ~0 - i, variablesBar, i );
} else {
subtreeJumps.push_back ( i - 1 );
}
i++;
}
return res;
}
template < class SymbolType, class RankType >
automaton::InputDrivenNPDA < common::ranked_symbol < SymbolType, RankType >, char, unsigned > ExactTreePatternAutomaton::construct ( const tree::PrefixRankedTree < SymbolType, RankType > & tree, const common::ranked_symbol < SymbolType, RankType > & subtreeWildcard ) {
char S = alphabet::SubtreeWildcardSymbol::instance < char > ( );
......
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