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

simplify glushkov rte implementation

parent b1e231d4
No related branches found
No related tags found
No related merge requests found
Pipeline #30834 passed
......@@ -10,6 +10,7 @@
 
#include <alib/set>
#include <alib/variant>
#include <alib/algorithm>
 
#include <global/GlobalData.h>
 
......@@ -46,14 +47,6 @@ private:
return common::ranked_symbol < SymbolType, RankType > ( symbol.getSymbol ( ).first, symbol.getRank ( ) );
}
 
template < class SymbolType, class RankType >
static bool isSubstSymbolPresent ( const ext::set < common::ranked_symbol < ext::pair < SymbolType, unsigned >, RankType > > & container, const TAlphabet < SymbolType, RankType > & substAlphabet ) {
ext::vector < common::ranked_symbol < ext::pair < SymbolType, unsigned >, RankType > > intersection;
std::set_intersection ( container.begin ( ), container.end ( ), substAlphabet.begin ( ), substAlphabet.end ( ), std::back_inserter ( intersection ) );
return intersection.size ( ) > 0;
}
public:
/**
* Implements conversion of the regular tree expressions to a real-time height-deterministic pushdown automaton usign algorithm similar to Glushkov's method of neighbours.
......@@ -87,7 +80,7 @@ automaton::NPDA < ext::variant < common::ranked_symbol < SymbolType, RankType >,
followSet.insert ( std::make_pair ( symbol, rte::GlushkovFollow::follow ( indexedRTE, symbol, substMapTree ) ) );
 
/* check for exceptions -> there must be NO substitution symbol in first set */
if ( isSubstSymbolPresent ( firstSet, indexedRTE.getSubstitutionAlphabet ( ) ) )
if ( ! ext::excludes ( firstSet.begin ( ), firstSet.end ( ), indexedRTE.getSubstitutionAlphabet ( ).begin ( ), indexedRTE.getSubstitutionAlphabet ( ).end ( ) ) )
throw exception::CommonException ( "GlushkovRTE: Substitution symbol appeared in the first set" );
/* check end */
 
......@@ -95,7 +88,7 @@ automaton::NPDA < ext::variant < common::ranked_symbol < SymbolType, RankType >,
for ( const std::pair < const common::ranked_symbol < ext::pair < SymbolType, unsigned >, RankType >, ext::set < GlushkovFollow::TFollowTuple < SymbolType, RankType > > > & kv : followSet )
for ( const GlushkovFollow::TFollowTuple < SymbolType, RankType > & followTuple : kv.second ) // TFollowTuple = vector < set < ranked_symbol > >
for ( const ext::set < common::ranked_symbol < ext::pair < SymbolType, unsigned >, RankType > > & followTupleElem : followTuple )
if ( isSubstSymbolPresent ( followTupleElem, indexedRTE.getSubstitutionAlphabet ( ) ) )
if ( ! ext::excludes ( followTupleElem.begin ( ), followTupleElem.end ( ), indexedRTE.getSubstitutionAlphabet ( ).begin ( ), indexedRTE.getSubstitutionAlphabet ( ).end ( ) ) )
throw exception::CommonException ( "GlushkovRTE: Substitution symbol appeared in a follow set" );
/* check end */
 
......
......@@ -35,13 +35,6 @@ class ToPostfixPushdownAutomatonGlushkovNaive {
return common::ranked_symbol < SymbolType, RankType > ( symbol.getSymbol ( ).first, symbol.getRank ( ) );
}
 
template < class SymbolType, class RankType >
static bool isSubstSymbolPresent ( const ext::set < common::ranked_symbol < ext::pair < SymbolType, unsigned >, RankType > > & container, const ext::set < common::ranked_symbol < ext::pair < SymbolType, unsigned >, RankType > > & substAlphabet ) {
ext::vector < common::ranked_symbol < ext::pair < SymbolType, unsigned >, RankType > > intersection;
std::set_intersection ( container.begin ( ), container.end ( ), substAlphabet.begin ( ), substAlphabet.end ( ), std::back_inserter ( intersection ) );
return intersection.size ( ) > 0;
}
public:
/**
* Implements conversion of the regular tree expressions to a real-time height-deterministic pushdown automaton usign algorithm similar to Glushkov's method of neighbours.
......@@ -74,13 +67,14 @@ automaton::NPDA < ext::variant < common::ranked_symbol < SymbolType, RankType >,
followSet.insert ( std::make_pair ( symbol, rte::GlushkovFollowNaive::follow ( indexedRTE, symbol ) ) );
 
/* check for exceptions -> there must be NO substitution symbol in first or follow sets */
if ( isSubstSymbolPresent ( firstSet, indexedRTE.getSubstitutionAlphabet ( ) ) )
if ( ! ext::excludes ( firstSet.begin ( ), firstSet.end ( ), indexedRTE.getSubstitutionAlphabet ( ).begin ( ), indexedRTE.getSubstitutionAlphabet ( ).end ( ) ) )
throw exception::CommonException ( "GlushkovRTE: Substitution symbol appeared in the first set" );
 
for ( const auto & kv : followSet )
for ( const auto & followTuple : kv.second )
if ( isSubstSymbolPresent ( ext::set < common::ranked_symbol < ext::pair < SymbolType, unsigned >, RankType > > ( followTuple.begin ( ), followTuple.end ( ) ), indexedRTE.getSubstitutionAlphabet ( ) ) )
throw exception::CommonException ( "GlushkovRTE: Substitution symbol appeared in a follow set" );
for ( const common::ranked_symbol < ext::pair < SymbolType, unsigned >, RankType > & followTupleElem : followTuple )
if ( indexedRTE.getSubstitutionAlphabet ( ).count ( followTupleElem ) )
throw exception::CommonException ( "GlushkovRTE: Substitution symbol appeared in a follow set" );
 
/* check end */
 
......
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