From 35edd8096c2ec1991156ada718472ba1ebe43cd0 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Tue, 11 Oct 2016 10:50:51 +0200 Subject: [PATCH] template PrefixRankedBarPattern tree --- .../arbology/exact/BadCharacterShiftTable.cpp | 4 +- .../arbology/exact/BadCharacterShiftTable.h | 2 +- .../src/arbology/exact/BorderArrayNaive.cpp | 6 +- .../src/arbology/exact/BorderArrayNaive.h | 4 +- .../src/arbology/exact/BoyerMooreHorspool.cpp | 6 +- .../src/arbology/exact/BoyerMooreHorspool.h | 2 +- ...neUsingBadCharacterShiftAndBorderArray.cpp | 8 +- ...ZoneUsingBadCharacterShiftAndBorderArray.h | 4 +- .../src/arbology/exact/ExactPatternMatch.cpp | 4 +- .../src/arbology/exact/ExactPatternMatch.h | 2 +- .../exact/ExactPatternMatchingAutomaton.cpp | 4 +- .../exact/ExactPatternMatchingAutomaton.h | 2 +- .../src/arbology/exact/KnuthMorrisPratt.cpp | 6 +- .../src/arbology/exact/KnuthMorrisPratt.h | 2 +- .../exact/ReversedBadCharacterShiftTable.cpp | 4 +- .../exact/ReversedBadCharacterShiftTable.h | 2 +- .../exact/ReversedBoyerMooreHorspool.cpp | 6 +- .../exact/ReversedBoyerMooreHorspool.h | 2 +- .../src/arbology/exact/SubtreeJumpTable.cpp | 4 +- .../src/arbology/exact/SubtreeJumpTable.h | 2 +- alib2data/src/string/LinearString.cpp | 2 +- alib2data/src/string/LinearString.h | 4 +- alib2data/src/tree/TreeFeatures.h | 1 + .../PrefixRankedBarNonlinearPattern.cpp | 4 +- .../ranked/PrefixRankedBarNonlinearPattern.h | 2 +- .../tree/ranked/PrefixRankedBarPattern.cpp | 168 +---------- .../src/tree/ranked/PrefixRankedBarPattern.h | 263 +++++++++++++++--- alib2data/test-src/tree/PatternTest.cpp | 4 +- 28 files changed, 271 insertions(+), 253 deletions(-) diff --git a/alib2algo/src/arbology/exact/BadCharacterShiftTable.cpp b/alib2algo/src/arbology/exact/BadCharacterShiftTable.cpp index e6e3297bc6..2020a16611 100644 --- a/alib2algo/src/arbology/exact/BadCharacterShiftTable.cpp +++ b/alib2algo/src/arbology/exact/BadCharacterShiftTable.cpp @@ -18,11 +18,11 @@ std::map < std::ranked_symbol < >, size_t > BadCharacterShiftTable::bcs ( const return dispatch ( pattern.getData ( ) ); } -std::map < std::ranked_symbol < >, size_t > BadCharacterShiftTable::bcs ( const tree::PrefixRankedBarPattern & pattern ) { +std::map < std::ranked_symbol < >, size_t > BadCharacterShiftTable::bcs ( const tree::PrefixRankedBarPattern < > & pattern ) { return bcs ( tree::PrefixRankedBarNonlinearPattern ( pattern ) ); } -auto BadCharacterShiftTablePrefixRankedBarPattern = BadCharacterShiftTable::RegistratorWrapper < std::map < std::ranked_symbol < >, size_t >, tree::PrefixRankedBarPattern > ( BadCharacterShiftTable::bcs ); +auto BadCharacterShiftTablePrefixRankedBarPattern = BadCharacterShiftTable::RegistratorWrapper < std::map < std::ranked_symbol < >, size_t >, tree::PrefixRankedBarPattern < > > ( BadCharacterShiftTable::bcs ); std::map < std::ranked_symbol < >, size_t > BadCharacterShiftTable::bcs ( const tree::PrefixRankedBarNonlinearPattern & pattern ) { const std::set < std::ranked_symbol < > > & alphabet = pattern.getAlphabet ( ); diff --git a/alib2algo/src/arbology/exact/BadCharacterShiftTable.h b/alib2algo/src/arbology/exact/BadCharacterShiftTable.h index d15fab152b..f33aa278d1 100644 --- a/alib2algo/src/arbology/exact/BadCharacterShiftTable.h +++ b/alib2algo/src/arbology/exact/BadCharacterShiftTable.h @@ -32,7 +32,7 @@ public: */ static std::map < std::ranked_symbol < >, size_t > bcs ( const tree::RankedTreeWrapper & pattern ); - static std::map < std::ranked_symbol < >, size_t > bcs ( const tree::PrefixRankedBarPattern & pattern ); + static std::map < std::ranked_symbol < >, size_t > bcs ( const tree::PrefixRankedBarPattern < > & pattern ); static std::map < std::ranked_symbol < >, size_t > bcs ( const tree::PrefixRankedBarNonlinearPattern & pattern ); }; diff --git a/alib2algo/src/arbology/exact/BorderArrayNaive.cpp b/alib2algo/src/arbology/exact/BorderArrayNaive.cpp index aa91f08b8a..14d3f367ff 100644 --- a/alib2algo/src/arbology/exact/BorderArrayNaive.cpp +++ b/alib2algo/src/arbology/exact/BorderArrayNaive.cpp @@ -21,7 +21,7 @@ std::vector < size_t > BorderArrayNaive::ba ( const tree::Tree & pattern ) { return dispatch ( pattern.getData ( ) ); } -bool BorderArrayNaive::matches ( const tree::PrefixRankedBarPattern & pattern, const std::vector < int > & subtreeJumpTable, int stop, int offset ) { +bool BorderArrayNaive::matches ( const tree::PrefixRankedBarPattern < > & pattern, const std::vector < int > & subtreeJumpTable, int stop, int offset ) { unsigned i = 0; while ( offset < stop && i < pattern.getContent ( ).size ( ) ) @@ -38,7 +38,7 @@ bool BorderArrayNaive::matches ( const tree::PrefixRankedBarPattern & pattern, c return true; } -std::vector < size_t > BorderArrayNaive::ba ( const tree::PrefixRankedBarPattern & pattern ) { +std::vector < size_t > BorderArrayNaive::ba ( const tree::PrefixRankedBarPattern < > & pattern ) { std::vector < int > patternSubtreeJumpTable = SubtreeJumpTable::compute ( pattern ); std::vector < size_t > res; @@ -65,7 +65,7 @@ std::vector < size_t > BorderArrayNaive::ba ( const tree::PrefixRankedBarPattern return res; } -auto BorderArrayPrefixRankedBarPattern = BorderArrayNaive::RegistratorWrapper < std::vector < size_t >, tree::PrefixRankedBarPattern > ( BorderArrayNaive::ba ); +auto BorderArrayPrefixRankedBarPattern = BorderArrayNaive::RegistratorWrapper < std::vector < size_t >, tree::PrefixRankedBarPattern < > > ( BorderArrayNaive::ba ); bool BorderArrayNaive::matches ( const tree::PrefixRankedPattern < > & pattern, const std::vector < int > & subtreeJumpTable, int stop, int offset ) { unsigned i = 0; diff --git a/alib2algo/src/arbology/exact/BorderArrayNaive.h b/alib2algo/src/arbology/exact/BorderArrayNaive.h index 30e8cbca21..575af1b841 100644 --- a/alib2algo/src/arbology/exact/BorderArrayNaive.h +++ b/alib2algo/src/arbology/exact/BorderArrayNaive.h @@ -22,7 +22,7 @@ namespace exact { * To get rid of zeros in BCS table we ignore last haystack character */ class BorderArrayNaive : public std::SingleDispatch < BorderArrayNaive, std::vector < size_t >, const tree::TreeBase & > { - static bool matches ( const tree::PrefixRankedBarPattern & pattern, const std::vector < int > & subtreeJumpTable, int stop, int offset ); + static bool matches ( const tree::PrefixRankedBarPattern < > & pattern, const std::vector < int > & subtreeJumpTable, int stop, int offset ); static bool matches ( const tree::PrefixRankedPattern < > & pattern, const std::vector < int > & subtreeJumpTable, int stop, int offset ); @@ -37,7 +37,7 @@ public: * Search for pattern in linear string. * @return set set of occurences */ - static std::vector < size_t > ba ( const tree::PrefixRankedBarPattern & pattern ); + static std::vector < size_t > ba ( const tree::PrefixRankedBarPattern < > & pattern ); /** * Search for pattern in linear string. diff --git a/alib2algo/src/arbology/exact/BoyerMooreHorspool.cpp b/alib2algo/src/arbology/exact/BoyerMooreHorspool.cpp index 0d34c100b4..4e65daebb1 100644 --- a/alib2algo/src/arbology/exact/BoyerMooreHorspool.cpp +++ b/alib2algo/src/arbology/exact/BoyerMooreHorspool.cpp @@ -27,12 +27,12 @@ std::set < unsigned > BoyerMooreHorspool::match ( const tree::Tree & subject, co } std::set < unsigned > BoyerMooreHorspool::match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarTree < > & pattern ) { - return match ( subject, tree::PrefixRankedBarPattern ( pattern ) ); + return match ( subject, tree::PrefixRankedBarPattern < > ( pattern ) ); } auto BoyerMooreHorspoolPrefixRankedBarTreePrefixRankedBarTree = BoyerMooreHorspool::RegistratorWrapper < std::set < unsigned >, tree::PrefixRankedBarTree < >, tree::PrefixRankedBarTree < > > ( BoyerMooreHorspool::match ); -std::set < unsigned > BoyerMooreHorspool::match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern & pattern ) { +std::set < unsigned > BoyerMooreHorspool::match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern < > & pattern ) { std::set < unsigned > occ; std::map < std::ranked_symbol < >, size_t > bcs = BadCharacterShiftTable::bcs ( pattern ); //NOTE: the subjects alphabet must be a subset or equal to the pattern std::vector < int > subjectSubtreeJumpTable = SubtreeJumpTable::compute ( subject ); @@ -73,7 +73,7 @@ std::set < unsigned > BoyerMooreHorspool::match ( const tree::PrefixRankedBarTre return occ; } -auto BoyerMooreHorspoolPrefixRankedBarTreePrefixRankedBarPattern = BoyerMooreHorspool::RegistratorWrapper < std::set < unsigned >, tree::PrefixRankedBarTree < >, tree::PrefixRankedBarPattern > ( BoyerMooreHorspool::match ); +auto BoyerMooreHorspoolPrefixRankedBarTreePrefixRankedBarPattern = BoyerMooreHorspool::RegistratorWrapper < std::set < unsigned >, tree::PrefixRankedBarTree < >, tree::PrefixRankedBarPattern < > > ( BoyerMooreHorspool::match ); std::set < unsigned > BoyerMooreHorspool::match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarNonlinearPattern & pattern ) { std::set < unsigned > occ; diff --git a/alib2algo/src/arbology/exact/BoyerMooreHorspool.h b/alib2algo/src/arbology/exact/BoyerMooreHorspool.h index 85ea032321..72d16c5ad6 100644 --- a/alib2algo/src/arbology/exact/BoyerMooreHorspool.h +++ b/alib2algo/src/arbology/exact/BoyerMooreHorspool.h @@ -29,7 +29,7 @@ public: static std::set < unsigned > match ( const tree::Tree & subject, const tree::Tree & pattern ); static std::set < unsigned > match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarTree < > & pattern ); - static std::set < unsigned > match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern & pattern ); + static std::set < unsigned > match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern < > & pattern ); static std::set < unsigned > match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarNonlinearPattern & pattern ); }; diff --git a/alib2algo/src/arbology/exact/DeadZoneUsingBadCharacterShiftAndBorderArray.cpp b/alib2algo/src/arbology/exact/DeadZoneUsingBadCharacterShiftAndBorderArray.cpp index ce7d64bde4..e7ceb02e94 100644 --- a/alib2algo/src/arbology/exact/DeadZoneUsingBadCharacterShiftAndBorderArray.cpp +++ b/alib2algo/src/arbology/exact/DeadZoneUsingBadCharacterShiftAndBorderArray.cpp @@ -28,12 +28,12 @@ std::set < unsigned > DeadZoneUsingBadCharacterShiftAndBorderArray::match ( cons } std::set < unsigned > DeadZoneUsingBadCharacterShiftAndBorderArray::match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarTree < > & pattern ) { - return match ( subject, tree::PrefixRankedBarPattern ( pattern ) ); + return match ( subject, tree::PrefixRankedBarPattern < > ( pattern ) ); } auto DeadZoneUsingBadCharacterShiftAndBorderArrayPrefixRankedBarTreePrefixRankedBarTree = DeadZoneUsingBadCharacterShiftAndBorderArray::RegistratorWrapper < std::set < unsigned >, tree::PrefixRankedBarTree < >, tree::PrefixRankedBarTree < > > ( DeadZoneUsingBadCharacterShiftAndBorderArray::match ); -std::set < unsigned > DeadZoneUsingBadCharacterShiftAndBorderArray::match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern & pattern ) { +std::set < unsigned > DeadZoneUsingBadCharacterShiftAndBorderArray::match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern < > & pattern ) { std::set < unsigned > occ; std::map < std::ranked_symbol < >, size_t > bbcs = ReversedBadCharacterShiftTable::bcs ( pattern ); // NOTE: the subjects alphabet must be a subset or equal to the pattern std::vector < size_t > fba = BorderArrayNaive::ba ( pattern ); @@ -43,7 +43,7 @@ std::set < unsigned > DeadZoneUsingBadCharacterShiftAndBorderArray::match ( cons return occ; } -void DeadZoneUsingBadCharacterShiftAndBorderArray::match_rec ( std::set < unsigned > & occ, const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern & pattern, std::vector < size_t > & fba, std::map < std::ranked_symbol < >, size_t > & bbcs, std::vector < int > & subjectSubtreeJumpTable, int low, int high ) { +void DeadZoneUsingBadCharacterShiftAndBorderArray::match_rec ( std::set < unsigned > & occ, const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern < > & pattern, std::vector < size_t > & fba, std::map < std::ranked_symbol < >, size_t > & bbcs, std::vector < int > & subjectSubtreeJumpTable, int low, int high ) { if ( low >= high ) return; int i = ( low + high ) / 2; @@ -75,7 +75,7 @@ void DeadZoneUsingBadCharacterShiftAndBorderArray::match_rec ( std::set < unsign match_rec ( occ, subject, pattern, fba, bbcs, subjectSubtreeJumpTable, i + j - fba[j], high ); } -auto DeadZoneUsingBadCharacterShiftAndBorderArrayPrefixRankedBarTreePrefixRankedBarPattern = DeadZoneUsingBadCharacterShiftAndBorderArray::RegistratorWrapper < std::set < unsigned >, tree::PrefixRankedBarTree < >, tree::PrefixRankedBarPattern > ( DeadZoneUsingBadCharacterShiftAndBorderArray::match ); +auto DeadZoneUsingBadCharacterShiftAndBorderArrayPrefixRankedBarTreePrefixRankedBarPattern = DeadZoneUsingBadCharacterShiftAndBorderArray::RegistratorWrapper < std::set < unsigned >, tree::PrefixRankedBarTree < >, tree::PrefixRankedBarPattern < > > ( DeadZoneUsingBadCharacterShiftAndBorderArray::match ); std::set < unsigned > DeadZoneUsingBadCharacterShiftAndBorderArray::match ( const tree::PrefixRankedTree < > & subject, const tree::PrefixRankedTree < > & pattern ) { return match ( subject, tree::PrefixRankedPattern < > ( pattern ) ); diff --git a/alib2algo/src/arbology/exact/DeadZoneUsingBadCharacterShiftAndBorderArray.h b/alib2algo/src/arbology/exact/DeadZoneUsingBadCharacterShiftAndBorderArray.h index 12606c4dad..16c2498691 100644 --- a/alib2algo/src/arbology/exact/DeadZoneUsingBadCharacterShiftAndBorderArray.h +++ b/alib2algo/src/arbology/exact/DeadZoneUsingBadCharacterShiftAndBorderArray.h @@ -30,8 +30,8 @@ public: static std::set < unsigned > match ( const tree::Tree & subject, const tree::Tree & pattern ); static std::set < unsigned > match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarTree < > & pattern ); - static std::set < unsigned > match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern & pattern ); - static void match_rec ( std::set < unsigned > & occ, const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern & pattern, std::vector < size_t > & fba, std::map < std::ranked_symbol < >, size_t > & bbcs, std::vector < int > & subjectSubtreeJumpTable, int low, int high ); + static std::set < unsigned > match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern < > & pattern ); + static void match_rec ( std::set < unsigned > & occ, const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern < > & pattern, std::vector < size_t > & fba, std::map < std::ranked_symbol < >, size_t > & bbcs, std::vector < int > & subjectSubtreeJumpTable, int low, int high ); static std::set < unsigned > match ( const tree::PrefixRankedTree < > & subject, const tree::PrefixRankedTree < > & pattern ); static std::set < unsigned > match ( const tree::PrefixRankedTree < > & subject, const tree::PrefixRankedPattern < > & pattern ); diff --git a/alib2algo/src/arbology/exact/ExactPatternMatch.cpp b/alib2algo/src/arbology/exact/ExactPatternMatch.cpp index e3bf64a03f..5ef915c2a4 100644 --- a/alib2algo/src/arbology/exact/ExactPatternMatch.cpp +++ b/alib2algo/src/arbology/exact/ExactPatternMatch.cpp @@ -205,7 +205,7 @@ std::set < unsigned > ExactPatternMatch::match ( const tree::PrefixRankedTree < auto ExactPatternMatchPrefixRankedNonlinearPattern = ExactPatternMatch::RegistratorWrapper < std::set < unsigned >, tree::PrefixRankedTree < >, tree::PrefixRankedNonlinearPattern > ( ExactPatternMatch::match ); -std::set < unsigned > ExactPatternMatch::match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern & pattern ) { +std::set < unsigned > ExactPatternMatch::match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern < > & pattern ) { std::vector < int > subjectSubtreeJumpTable = SubtreeJumpTable::compute ( subject ); std::set < unsigned > occ; @@ -232,7 +232,7 @@ std::set < unsigned > ExactPatternMatch::match ( const tree::PrefixRankedBarTree return occ; } -auto ExactPatternMatchPrefixRankedBarPattern = ExactPatternMatch::RegistratorWrapper < std::set < unsigned >, tree::PrefixRankedBarTree < >, tree::PrefixRankedBarPattern > ( ExactPatternMatch::match ); +auto ExactPatternMatchPrefixRankedBarPattern = ExactPatternMatch::RegistratorWrapper < std::set < unsigned >, tree::PrefixRankedBarTree < >, tree::PrefixRankedBarPattern < > > ( ExactPatternMatch::match ); std::set < unsigned > ExactPatternMatch::match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarNonlinearPattern & pattern ) { std::vector < int > subjectSubtreeJumpTable = SubtreeJumpTable::compute ( subject ); diff --git a/alib2algo/src/arbology/exact/ExactPatternMatch.h b/alib2algo/src/arbology/exact/ExactPatternMatch.h index a726e6574d..2005a1a473 100644 --- a/alib2algo/src/arbology/exact/ExactPatternMatch.h +++ b/alib2algo/src/arbology/exact/ExactPatternMatch.h @@ -36,7 +36,7 @@ public: static std::set < unsigned > match ( const tree::PrefixRankedTree < > & subject, const tree::PrefixRankedPattern < > & pattern ); static std::set < unsigned > match ( const tree::PrefixRankedTree < > & subject, const tree::PrefixRankedNonlinearPattern & pattern ); - static std::set < unsigned > match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern & pattern ); + static std::set < unsigned > match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern < > & pattern ); static std::set < unsigned > match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarNonlinearPattern & pattern ); private: diff --git a/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.cpp b/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.cpp index 129e3f8986..f5ecd771fa 100644 --- a/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.cpp +++ b/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.cpp @@ -122,7 +122,7 @@ automaton::InputDrivenNPDA < > ExactPatternMatchingAutomaton::construct ( const auto ExactPatternMatchingAutomatonPrefixRankedBarTree = ExactPatternMatchingAutomaton::RegistratorWrapper < automaton::InputDrivenNPDA < >, tree::PrefixRankedBarTree < > > ( ExactPatternMatchingAutomaton::construct ); -automaton::VisiblyPushdownNPDA < > ExactPatternMatchingAutomaton::construct ( const tree::PrefixRankedBarPattern & pattern ) { +automaton::VisiblyPushdownNPDA < > ExactPatternMatchingAutomaton::construct ( const tree::PrefixRankedBarPattern < > & pattern ) { automaton::VisiblyPushdownNPDA < > res ( alphabet::Symbol { alphabet::BottomOfTheStackSymbol::BOTTOM_OF_THE_STACK } ); res.addState ( label::labelFrom ( 0 ) ); @@ -187,7 +187,7 @@ automaton::VisiblyPushdownNPDA < > ExactPatternMatchingAutomaton::construct ( co return res; } -auto ExactPatternMatchingAutomatonPrefixRankedBarPattern = ExactPatternMatchingAutomaton::RegistratorWrapper < automaton::VisiblyPushdownNPDA < >, tree::PrefixRankedBarPattern > ( ExactPatternMatchingAutomaton::construct ); +auto ExactPatternMatchingAutomatonPrefixRankedBarPattern = ExactPatternMatchingAutomaton::RegistratorWrapper < automaton::VisiblyPushdownNPDA < >, tree::PrefixRankedBarPattern < > > ( ExactPatternMatchingAutomaton::construct ); automaton::NFTA ExactPatternMatchingAutomaton::construct ( const tree::RankedTree < > & pattern ) { return ExactSubtreeMatchingAutomaton::construct ( pattern ); diff --git a/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.h b/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.h index 344461d66e..0c9c24ef82 100644 --- a/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.h +++ b/alib2algo/src/arbology/exact/ExactPatternMatchingAutomaton.h @@ -27,7 +27,7 @@ public: static automaton::NPDA < > construct ( const tree::PrefixRankedPattern < > & pattern ); static automaton::InputDrivenNPDA < > construct ( const tree::PrefixRankedTree < > & pattern ); - static automaton::VisiblyPushdownNPDA < > construct ( const tree::PrefixRankedBarPattern & pattern ); + static automaton::VisiblyPushdownNPDA < > construct ( const tree::PrefixRankedBarPattern < > & pattern ); static automaton::InputDrivenNPDA < > construct ( const tree::PrefixRankedBarTree < > & pattern ); static automaton::NFTA construct ( const tree::RankedTree < > & pattern ); static automaton::NFTA construct ( const tree::RankedPattern < > & pattern ); diff --git a/alib2algo/src/arbology/exact/KnuthMorrisPratt.cpp b/alib2algo/src/arbology/exact/KnuthMorrisPratt.cpp index e548d5836d..a9cd1448dc 100644 --- a/alib2algo/src/arbology/exact/KnuthMorrisPratt.cpp +++ b/alib2algo/src/arbology/exact/KnuthMorrisPratt.cpp @@ -26,12 +26,12 @@ std::set < unsigned > KnuthMorrisPratt::match ( const tree::Tree & subject, cons } std::set < unsigned > KnuthMorrisPratt::match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarTree < > & pattern ) { - return match ( subject, tree::PrefixRankedBarPattern ( pattern ) ); + return match ( subject, tree::PrefixRankedBarPattern < > ( pattern ) ); } auto KnuthMorrisPrattPrefixRankedBarTreePrefixRankedBarTree = KnuthMorrisPratt::RegistratorWrapper < std::set < unsigned >, tree::PrefixRankedBarTree < >, tree::PrefixRankedBarTree < > > ( KnuthMorrisPratt::match ); -std::set < unsigned > KnuthMorrisPratt::match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern & pattern ) { +std::set < unsigned > KnuthMorrisPratt::match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern < > & pattern ) { std::set < unsigned > occ; std::vector < size_t > ba = BorderArrayNaive::ba ( pattern ); std::vector < int > subjectSubtreeJumpTable = SubtreeJumpTable::compute ( subject ); @@ -72,7 +72,7 @@ std::set < unsigned > KnuthMorrisPratt::match ( const tree::PrefixRankedBarTree return occ; } -auto KnuthMorrisPrattPrefixRankedBarTreePrefixRankedBarPattern = KnuthMorrisPratt::RegistratorWrapper < std::set < unsigned >, tree::PrefixRankedBarTree < >, tree::PrefixRankedBarPattern > ( KnuthMorrisPratt::match ); +auto KnuthMorrisPrattPrefixRankedBarTreePrefixRankedBarPattern = KnuthMorrisPratt::RegistratorWrapper < std::set < unsigned >, tree::PrefixRankedBarTree < >, tree::PrefixRankedBarPattern < > > ( KnuthMorrisPratt::match ); std::set < unsigned > KnuthMorrisPratt::match ( const tree::PrefixRankedTree < > & subject, const tree::PrefixRankedTree < > & pattern ) { return match ( subject, tree::PrefixRankedPattern < > ( pattern ) ); diff --git a/alib2algo/src/arbology/exact/KnuthMorrisPratt.h b/alib2algo/src/arbology/exact/KnuthMorrisPratt.h index 537acff371..cdbed66212 100644 --- a/alib2algo/src/arbology/exact/KnuthMorrisPratt.h +++ b/alib2algo/src/arbology/exact/KnuthMorrisPratt.h @@ -29,7 +29,7 @@ public: static std::set < unsigned > match ( const tree::Tree & subject, const tree::Tree & pattern ); static std::set < unsigned > match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarTree < > & pattern ); - static std::set < unsigned > match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern & pattern ); + static std::set < unsigned > match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern < > & pattern ); static std::set < unsigned > match ( const tree::PrefixRankedTree < > & subject, const tree::PrefixRankedTree < > & pattern ); static std::set < unsigned > match ( const tree::PrefixRankedTree < > & subject, const tree::PrefixRankedPattern < > & pattern ); diff --git a/alib2algo/src/arbology/exact/ReversedBadCharacterShiftTable.cpp b/alib2algo/src/arbology/exact/ReversedBadCharacterShiftTable.cpp index 66494a0642..bf2e886b2c 100644 --- a/alib2algo/src/arbology/exact/ReversedBadCharacterShiftTable.cpp +++ b/alib2algo/src/arbology/exact/ReversedBadCharacterShiftTable.cpp @@ -20,11 +20,11 @@ std::map < std::ranked_symbol < >, size_t > ReversedBadCharacterShiftTable::bcs return dispatch ( pattern.getData ( ) ); } -std::map < std::ranked_symbol < >, size_t > ReversedBadCharacterShiftTable::bcs ( const tree::PrefixRankedBarPattern & pattern ) { +std::map < std::ranked_symbol < >, size_t > ReversedBadCharacterShiftTable::bcs ( const tree::PrefixRankedBarPattern < > & pattern ) { return bcs ( tree::PrefixRankedBarNonlinearPattern ( pattern ) ); } -auto ReversedBadCharacterShiftTablePrefixRankedBarPattern = ReversedBadCharacterShiftTable::RegistratorWrapper < std::map < std::ranked_symbol < >, size_t >, tree::PrefixRankedBarPattern > ( ReversedBadCharacterShiftTable::bcs ); +auto ReversedBadCharacterShiftTablePrefixRankedBarPattern = ReversedBadCharacterShiftTable::RegistratorWrapper < std::map < std::ranked_symbol < >, size_t >, tree::PrefixRankedBarPattern < > > ( ReversedBadCharacterShiftTable::bcs ); std::map < std::ranked_symbol < >, size_t > ReversedBadCharacterShiftTable::bcs ( const tree::PrefixRankedBarNonlinearPattern & pattern ) { const std::set < std::ranked_symbol < > > & alphabet = pattern.getAlphabet ( ); diff --git a/alib2algo/src/arbology/exact/ReversedBadCharacterShiftTable.h b/alib2algo/src/arbology/exact/ReversedBadCharacterShiftTable.h index d2c0441bb2..c2d414e8e4 100644 --- a/alib2algo/src/arbology/exact/ReversedBadCharacterShiftTable.h +++ b/alib2algo/src/arbology/exact/ReversedBadCharacterShiftTable.h @@ -32,7 +32,7 @@ public: */ static std::map < std::ranked_symbol < >, size_t > bcs ( const tree::RankedTreeWrapper & pattern ); - static std::map < std::ranked_symbol < >, size_t > bcs ( const tree::PrefixRankedBarPattern & pattern ); + static std::map < std::ranked_symbol < >, size_t > bcs ( const tree::PrefixRankedBarPattern < > & pattern ); static std::map < std::ranked_symbol < >, size_t > bcs ( const tree::PrefixRankedBarNonlinearPattern & pattern ); static std::map < std::ranked_symbol < >, size_t > bcs ( const tree::PrefixRankedPattern < > & pattern ); static std::map < std::ranked_symbol < >, size_t > bcs ( const tree::PrefixRankedNonlinearPattern & pattern ); diff --git a/alib2algo/src/arbology/exact/ReversedBoyerMooreHorspool.cpp b/alib2algo/src/arbology/exact/ReversedBoyerMooreHorspool.cpp index ed2df5417c..77b374b7e7 100644 --- a/alib2algo/src/arbology/exact/ReversedBoyerMooreHorspool.cpp +++ b/alib2algo/src/arbology/exact/ReversedBoyerMooreHorspool.cpp @@ -30,12 +30,12 @@ std::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::Tree & sub } std::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarTree < > & pattern ) { - return match ( subject, tree::PrefixRankedBarPattern ( pattern ) ); + return match ( subject, tree::PrefixRankedBarPattern < > ( pattern ) ); } auto ReversedBoyerMooreHorspoolPrefixRankedBarTreePrefixRankedBarTree = ReversedBoyerMooreHorspool::RegistratorWrapper < std::set < unsigned >, tree::PrefixRankedBarTree < >, tree::PrefixRankedBarTree < > > ( ReversedBoyerMooreHorspool::match ); -std::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern & pattern ) { +std::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern < > & pattern ) { std::set < unsigned > occ; std::map < std::ranked_symbol < >, size_t > bcs = ReversedBadCharacterShiftTable::bcs ( pattern ); // NOTE: the subjects alphabet must be a subset or equal to the pattern std::vector < int > subjectSubtreeJumpTable = SubtreeJumpTable::compute ( subject ); @@ -76,7 +76,7 @@ std::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRank return occ; } -auto ReversedBoyerMooreHorspoolPrefixRankedBarTreePrefixRankedBarPattern = ReversedBoyerMooreHorspool::RegistratorWrapper < std::set < unsigned >, tree::PrefixRankedBarTree < >, tree::PrefixRankedBarPattern > ( ReversedBoyerMooreHorspool::match ); +auto ReversedBoyerMooreHorspoolPrefixRankedBarTreePrefixRankedBarPattern = ReversedBoyerMooreHorspool::RegistratorWrapper < std::set < unsigned >, tree::PrefixRankedBarTree < >, tree::PrefixRankedBarPattern < > > ( ReversedBoyerMooreHorspool::match ); std::set < unsigned > ReversedBoyerMooreHorspool::match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarNonlinearPattern & pattern ) { std::set < unsigned > occ; diff --git a/alib2algo/src/arbology/exact/ReversedBoyerMooreHorspool.h b/alib2algo/src/arbology/exact/ReversedBoyerMooreHorspool.h index 44376adfa2..ca6d55881d 100644 --- a/alib2algo/src/arbology/exact/ReversedBoyerMooreHorspool.h +++ b/alib2algo/src/arbology/exact/ReversedBoyerMooreHorspool.h @@ -29,7 +29,7 @@ public: static std::set < unsigned > match ( const tree::Tree & subject, const tree::Tree & pattern ); static std::set < unsigned > match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarTree < > & pattern ); - static std::set < unsigned > match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern & pattern ); + static std::set < unsigned > match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarPattern < > & pattern ); static std::set < unsigned > match ( const tree::PrefixRankedBarTree < > & subject, const tree::PrefixRankedBarNonlinearPattern & pattern ); static std::set < unsigned > match ( const tree::PrefixRankedTree < > & subject, const tree::PrefixRankedTree < > & pattern ); static std::set < unsigned > match ( const tree::PrefixRankedTree < > & subject, const tree::PrefixRankedPattern < > & pattern ); diff --git a/alib2algo/src/arbology/exact/SubtreeJumpTable.cpp b/alib2algo/src/arbology/exact/SubtreeJumpTable.cpp index 424bff6988..f7b4022b48 100644 --- a/alib2algo/src/arbology/exact/SubtreeJumpTable.cpp +++ b/alib2algo/src/arbology/exact/SubtreeJumpTable.cpp @@ -32,7 +32,7 @@ std::vector < int > SubtreeJumpTable::compute ( const tree::PrefixRankedBarTree auto SubtreeSizesPrefixRankedBarTree = SubtreeJumpTable::RegistratorWrapper < std::vector < int >, tree::PrefixRankedBarTree < > > ( SubtreeJumpTable::compute ); -std::vector < int > SubtreeJumpTable::compute ( const tree::PrefixRankedBarPattern & pattern ) { +std::vector < int > SubtreeJumpTable::compute ( const tree::PrefixRankedBarPattern < > & pattern ) { std::vector < int > res; buildDataPointersBar ( res, pattern, 0 ); @@ -40,7 +40,7 @@ std::vector < int > SubtreeJumpTable::compute ( const tree::PrefixRankedBarPatte return res; } -auto SubtreeSizesPrefixRankedBarPattern = SubtreeJumpTable::RegistratorWrapper < std::vector < int >, tree::PrefixRankedBarPattern > ( SubtreeJumpTable::compute ); +auto SubtreeSizesPrefixRankedBarPattern = SubtreeJumpTable::RegistratorWrapper < std::vector < int >, tree::PrefixRankedBarPattern < > > ( SubtreeJumpTable::compute ); std::vector < int > SubtreeJumpTable::compute ( const tree::PrefixRankedTree < > & subject ) { std::vector < int > res; diff --git a/alib2algo/src/arbology/exact/SubtreeJumpTable.h b/alib2algo/src/arbology/exact/SubtreeJumpTable.h index a0a58a54fa..770b881477 100644 --- a/alib2algo/src/arbology/exact/SubtreeJumpTable.h +++ b/alib2algo/src/arbology/exact/SubtreeJumpTable.h @@ -30,7 +30,7 @@ public: static std::vector < int > compute ( const tree::RankedTreeWrapper & subject ); static std::vector < int > compute ( const tree::PrefixRankedBarTree < > & subject ); - static std::vector < int > compute ( const tree::PrefixRankedBarPattern & pattern ); + static std::vector < int > compute ( const tree::PrefixRankedBarPattern < > & pattern ); static std::vector < int > compute ( const tree::PrefixRankedTree < > & subject ); static std::vector < int > compute ( const tree::PrefixRankedPattern < > & pattern ); diff --git a/alib2data/src/string/LinearString.cpp b/alib2data/src/string/LinearString.cpp index 8fe8857de1..bd5fdf2e36 100644 --- a/alib2data/src/string/LinearString.cpp +++ b/alib2data/src/string/LinearString.cpp @@ -22,7 +22,7 @@ auto LinearStringFromPrefixRankedTree = castApi::CastRegister < string::LinearSt auto LinearStringFromPrefixRankedPattern = castApi::CastRegister < string::LinearString < >, tree::PrefixRankedPattern < > > ( ); auto LinearStringFromPrefixRankedNonlinearPattern = castApi::CastRegister < string::LinearString < >, tree::PrefixRankedNonlinearPattern > ( ); auto LinearStringFromPrefixRankedBarTree = castApi::CastRegister < string::LinearString < >, tree::PrefixRankedBarTree < > > ( ); -auto LinearStringFromPrefixRankedBarPattern = castApi::CastRegister < string::LinearString < >, tree::PrefixRankedBarPattern > ( ); +auto LinearStringFromPrefixRankedBarPattern = castApi::CastRegister < string::LinearString < >, tree::PrefixRankedBarPattern < > > ( ); auto LinearStringFromPrefixRankedBarNonlinearPattern = castApi::CastRegister < string::LinearString < >, tree::PrefixRankedBarNonlinearPattern > ( ); auto LinearStringFromPrefixBarTree = castApi::CastRegister < string::LinearString < >, tree::PrefixBarTree < > > ( ); auto LinearStringCastBinder = castApi::CastPoolStringBinder < string::LinearString < > > ( string::LinearString < >::getXmlTagName() ); diff --git a/alib2data/src/string/LinearString.h b/alib2data/src/string/LinearString.h index 24a2b88515..b15a6bf404 100644 --- a/alib2data/src/string/LinearString.h +++ b/alib2data/src/string/LinearString.h @@ -43,7 +43,7 @@ public: explicit LinearString ( const tree::PrefixRankedPattern < > & tree ); explicit LinearString ( const tree::PrefixRankedNonlinearPattern & tree ); explicit LinearString ( const tree::PrefixRankedBarTree < > & tree ); - explicit LinearString ( const tree::PrefixRankedBarPattern & tree ); + explicit LinearString ( const tree::PrefixRankedBarPattern < > & tree ); explicit LinearString ( const tree::PrefixRankedBarNonlinearPattern & tree ); explicit LinearString ( const tree::PrefixBarTree < SymbolType > & tree ); explicit LinearString ( std::set < SymbolType > alphabet, std::vector < SymbolType > data ); @@ -159,7 +159,7 @@ LinearString < SymbolType >::LinearString ( const tree::PrefixRankedBarTree < > } template < class SymbolType > -LinearString < SymbolType >::LinearString ( const tree::PrefixRankedBarPattern & tree ) : LinearString ( StringAuxiliary::wrapSymbols ( tree.getAlphabet ( ) ), StringAuxiliary::wrapSymbols ( tree.getContent ( ) ) ) { +LinearString < SymbolType >::LinearString ( const tree::PrefixRankedBarPattern < > & tree ) : LinearString ( StringAuxiliary::wrapSymbols ( tree.getAlphabet ( ) ), StringAuxiliary::wrapSymbols ( tree.getContent ( ) ) ) { } template < class SymbolType > diff --git a/alib2data/src/tree/TreeFeatures.h b/alib2data/src/tree/TreeFeatures.h index 982a564b0a..d140a65833 100644 --- a/alib2data/src/tree/TreeFeatures.h +++ b/alib2data/src/tree/TreeFeatures.h @@ -44,6 +44,7 @@ class PrefixRankedBarTree; template < class SymbolType = alphabet::Symbol, class RankType = primitive::Unsigned > class PrefixRankedPattern; class PrefixRankedNonlinearPattern; +template < class SymbolType = alphabet::Symbol, class RankType = primitive::Unsigned > class PrefixRankedBarPattern; class PrefixRankedBarNonlinearPattern; template < class SymbolType = alphabet::Symbol > diff --git a/alib2data/src/tree/ranked/PrefixRankedBarNonlinearPattern.cpp b/alib2data/src/tree/ranked/PrefixRankedBarNonlinearPattern.cpp index fc1cdac9db..b93b0e4913 100644 --- a/alib2data/src/tree/ranked/PrefixRankedBarNonlinearPattern.cpp +++ b/alib2data/src/tree/ranked/PrefixRankedBarNonlinearPattern.cpp @@ -52,7 +52,7 @@ PrefixRankedBarNonlinearPattern::PrefixRankedBarNonlinearPattern ( alphabet::Sym PrefixRankedBarNonlinearPattern::PrefixRankedBarNonlinearPattern ( const PrefixRankedBarTree < > & tree ) : PrefixRankedBarNonlinearPattern ( tree.getBars ( ) + std::set < std::ranked_symbol < > > { alphabet::VariablesBarSymbol::RANKED_BAR_SYMBOL }, alphabet::VariablesBarSymbol::RANKED_BAR_SYMBOL, alphabet::SubtreeWildcardSymbol::RANKED_SUBTREE_WILDCARD_SYMBOL, { }, tree.getAlphabet ( ) + std::set < std::ranked_symbol < > > { alphabet::VariablesBarSymbol::RANKED_BAR_SYMBOL, alphabet::SubtreeWildcardSymbol::RANKED_SUBTREE_WILDCARD_SYMBOL }, tree.getContent ( ) ) { } -PrefixRankedBarNonlinearPattern::PrefixRankedBarNonlinearPattern ( const PrefixRankedBarPattern & tree ) : PrefixRankedBarNonlinearPattern ( tree.getBars ( ), tree.getVariablesBar ( ), tree.getSubtreeWildcard ( ), { }, tree.getAlphabet ( ), tree.getContent ( ) ) { +PrefixRankedBarNonlinearPattern::PrefixRankedBarNonlinearPattern ( const PrefixRankedBarPattern < > & tree ) : PrefixRankedBarNonlinearPattern ( tree.getBars ( ), tree.getVariablesBar ( ), tree.getSubtreeWildcard ( ), { }, tree.getAlphabet ( ), tree.getContent ( ) ) { } PrefixRankedBarNonlinearPattern::PrefixRankedBarNonlinearPattern ( const RankedTree < > & tree ) : PrefixRankedBarNonlinearPattern ( alphabet::BarSymbol::BAR_SYMBOL, alphabet::VariablesBarSymbol::RANKED_BAR_SYMBOL, tree ) { @@ -198,7 +198,7 @@ auto PrefixRankedBarNonlinearPatternFromRankedTree = castApi::CastRegister < ::t auto PrefixRankedBarNonlinearPatternFromRankedPattern = castApi::CastRegister < ::tree::PrefixRankedBarNonlinearPattern, ::tree::RankedPattern < > > ( ); auto PrefixRankedBarNonlinearPatternFromRankedNonlinearPattern = castApi::CastRegister < ::tree::PrefixRankedBarNonlinearPattern, ::tree::RankedNonlinearPattern < > > ( ); auto PrefixRankedBarNonlinearPatternFromPrefixRankedBarTree = castApi::CastRegister < ::tree::PrefixRankedBarNonlinearPattern, ::tree::PrefixRankedBarTree < > > ( ); -auto PrefixRankedBarNonlinearPatternFromPrefixRankedBarPattern = castApi::CastRegister < ::tree::PrefixRankedBarNonlinearPattern, ::tree::PrefixRankedBarPattern > ( ); +auto PrefixRankedBarNonlinearPatternFromPrefixRankedBarPattern = castApi::CastRegister < ::tree::PrefixRankedBarNonlinearPattern, ::tree::PrefixRankedBarPattern < > > ( ); auto PrefixRankedBarNonlinearPatternCastBinder = castApi::CastPoolStringBinder < ::tree::PrefixRankedBarNonlinearPattern > ( ::tree::PrefixRankedBarNonlinearPattern::getXmlTagName ( ) ); } /* namespace alib */ diff --git a/alib2data/src/tree/ranked/PrefixRankedBarNonlinearPattern.h b/alib2data/src/tree/ranked/PrefixRankedBarNonlinearPattern.h index d2468f7561..7df108a32c 100644 --- a/alib2data/src/tree/ranked/PrefixRankedBarNonlinearPattern.h +++ b/alib2data/src/tree/ranked/PrefixRankedBarNonlinearPattern.h @@ -43,7 +43,7 @@ public: explicit PrefixRankedBarNonlinearPattern ( alphabet::Symbol barBase, std::ranked_symbol < > variablesBar, const RankedPattern < > & tree ); explicit PrefixRankedBarNonlinearPattern ( alphabet::Symbol barBase, std::ranked_symbol < > variablesBar, const RankedNonlinearPattern < > & tree ); explicit PrefixRankedBarNonlinearPattern ( const PrefixRankedBarTree < > & tree ); - explicit PrefixRankedBarNonlinearPattern ( const PrefixRankedBarPattern & tree ); + explicit PrefixRankedBarNonlinearPattern ( const PrefixRankedBarPattern < > & tree ); explicit PrefixRankedBarNonlinearPattern ( const RankedTree < > & tree ); explicit PrefixRankedBarNonlinearPattern ( const RankedPattern < > & tree ); explicit PrefixRankedBarNonlinearPattern ( const RankedNonlinearPattern < > & tree ); diff --git a/alib2data/src/tree/ranked/PrefixRankedBarPattern.cpp b/alib2data/src/tree/ranked/PrefixRankedBarPattern.cpp index c668ece43b..9c70251b31 100644 --- a/alib2data/src/tree/ranked/PrefixRankedBarPattern.cpp +++ b/alib2data/src/tree/ranked/PrefixRankedBarPattern.cpp @@ -6,176 +6,20 @@ */ #include "PrefixRankedBarPattern.h" - -#include <sstream> -#include <algorithm> -#include <deque> - -#include "RankedPattern.h" -#include "PrefixRankedBarTree.h" - -#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> #include <core/xmlApi.hpp> #include <core/castApi.hpp> -#include "../../alphabet/BarSymbol.h" -#include "../../alphabet/VariablesBarSymbol.h" -#include "../../alphabet/SubtreeWildcardSymbol.h" - -namespace tree { - -PrefixRankedBarPattern::PrefixRankedBarPattern ( std::set < std::ranked_symbol < > > bars, std::ranked_symbol < > variablesBar, std::ranked_symbol < > subtreeWildcard, std::set < std::ranked_symbol < > > alphabet, std::vector < std::ranked_symbol < > > data ) : std::Components < PrefixRankedBarPattern, std::ranked_symbol < >, std::tuple < GeneralAlphabet, BarSymbols >, std::tuple < SubtreeWildcard, VariablesBarSymbol > > ( std::make_tuple ( std::move ( alphabet ), std::move ( bars ) ), std::make_tuple ( std::move ( subtreeWildcard ), std::move ( variablesBar ) ) ) { - setContent ( std::move ( data ) ); -} - -PrefixRankedBarPattern::PrefixRankedBarPattern ( std::set < std::ranked_symbol < > > bars, std::ranked_symbol < > variablesBar, std::ranked_symbol < > subtreeWildcard, std::vector < std::ranked_symbol < > > data ) : PrefixRankedBarPattern ( bars, variablesBar, subtreeWildcard, std::set < std::ranked_symbol < > > ( data.begin ( ), data.end ( ) ) + bars + std::set < std::ranked_symbol < > > { variablesBar, subtreeWildcard }, data ) { -} - -PrefixRankedBarPattern::PrefixRankedBarPattern ( alphabet::Symbol barBase, std::ranked_symbol < > variablesBar, const RankedPattern < > & tree ) : PrefixRankedBarPattern ( TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + std::set < std::ranked_symbol < > > { variablesBar }, variablesBar, tree.getSubtreeWildcard ( ), tree.getAlphabet ( ) + TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + std::set < std::ranked_symbol < > > { variablesBar, tree.getSubtreeWildcard ( ) }, toPrefixRankedBar ( tree.getContent ( ), tree.getSubtreeWildcard ( ), barBase, variablesBar ) ) { -} - -PrefixRankedBarPattern::PrefixRankedBarPattern ( const PrefixRankedBarTree < > & tree ) : PrefixRankedBarPattern ( tree.getBars() + std::set < std::ranked_symbol < > > { alphabet::VariablesBarSymbol::RANKED_BAR_SYMBOL }, alphabet::VariablesBarSymbol::RANKED_BAR_SYMBOL, alphabet::SubtreeWildcardSymbol::RANKED_SUBTREE_WILDCARD_SYMBOL, tree.getAlphabet ( ) + std::set < std::ranked_symbol < > > { alphabet::VariablesBarSymbol::RANKED_BAR_SYMBOL, alphabet::SubtreeWildcardSymbol::RANKED_SUBTREE_WILDCARD_SYMBOL }, tree.getContent ( ) ) { -} - -PrefixRankedBarPattern::PrefixRankedBarPattern ( const RankedPattern < > & tree ) : PrefixRankedBarPattern ( alphabet::BarSymbol::BAR_SYMBOL, alphabet::VariablesBarSymbol::RANKED_BAR_SYMBOL, tree ) { -} - -std::vector < std::ranked_symbol < > > PrefixRankedBarPattern::toPrefixRankedBar ( const std::tree < std::ranked_symbol < > > & tree, const std::ranked_symbol < > & subtreeWildcard, const alphabet::Symbol & barBase, const std::ranked_symbol < > & variablesBar ) { - std::vector < std::ranked_symbol < > > res; - - for ( std::tree < std::ranked_symbol < > >::const_structure_iterator iter = tree.structure_begin ( ); iter != tree.structure_end ( ); ++iter ) - if ( iter.getVirtual ( ) ) - if ( ( * iter == subtreeWildcard ) ) - res.push_back ( variablesBar ); - else - res.push_back ( std::ranked_symbol < > ( barBase, iter->getRank ( ) ) ); - else - res.push_back ( * iter ); - - return res; -} - -RankedTreeBase * PrefixRankedBarPattern::clone ( ) const { - return new PrefixRankedBarPattern ( * this ); -} - -RankedTreeBase * PrefixRankedBarPattern::plunder ( ) && { - return new PrefixRankedBarPattern ( std::move ( * this ) ); -} - -const std::vector < std::ranked_symbol < > > & PrefixRankedBarPattern::getContent ( ) const { - return this->m_Data; -} - -void PrefixRankedBarPattern::setContent ( std::vector < std::ranked_symbol < > > data ) { - arityChecksum ( data ); - - std::set < std::ranked_symbol < > > minimalAlphabet ( data.begin ( ), data.end ( ) ); - std::set < std::ranked_symbol < > > unknownSymbols; - std::set_difference ( minimalAlphabet.begin ( ), minimalAlphabet.end ( ), getAlphabet().begin ( ), getAlphabet().end ( ), std::inserter ( unknownSymbols, unknownSymbols.end ( ) ) ); - - if ( unknownSymbols.size ( ) > 0 ) - throw TreeException ( "Input symbols not in the alphabet." ); - - this->m_Data = std::move ( data ); -} - -void PrefixRankedBarPattern::arityChecksum ( const std::vector < std::ranked_symbol < > > & data ) { - int arityChecksumTerminals = 1; - int arityChecksumBars = 1; - int arityChecksumTypes = 0; - - for ( const std::ranked_symbol < > & symbol : data ) { - if ( getBars ( ).count ( symbol ) || symbol == getVariablesBar ( ) ) { - arityChecksumBars += symbol.getRank ( ).getData ( ); - arityChecksumBars -= 1; - arityChecksumTypes -= 1; - } else { - arityChecksumTerminals += symbol.getRank ( ).getData ( ); - arityChecksumTerminals -= 1; - arityChecksumTypes += 1; - } - } - - if ( ( arityChecksumTerminals != 0 ) || ( arityChecksumBars != 0 ) || ( arityChecksumTypes != 0 ) ) throw TreeException ( "The string does not form a tree" ); - - for ( unsigned i = 1; i < data.size ( ); ++i ) - if ( data[i - 1] == getSubtreeWildcard ( ) && data[i] != getVariablesBar ( ) ) - throw TreeException ( "Inconsystency of SubtreeWildcard and variablesBar" ); - -} - -bool PrefixRankedBarPattern::isEmpty ( ) const { - return this->m_Data.size ( ) == 0; -} - -int PrefixRankedBarPattern::compare ( const PrefixRankedBarPattern & other ) const { - auto first = std::tie ( m_Data, getAlphabet(), getSubtreeWildcard(), getBars(), getVariablesBar() ); - auto second = std::tie ( other.m_Data, other.getAlphabet(), other.getSubtreeWildcard(), other.getBars(), other.getVariablesBar() ); - - std::compare < decltype ( first ) > comp; - - return comp ( first, second ); -} - -void PrefixRankedBarPattern::operator >>( std::ostream & out ) const { - out << "(PrefixRankedBarPattern "; - - for ( const std::ranked_symbol < > & symbol : this->m_Data ) - out << symbol; - - out << ")"; -} - -PrefixRankedBarPattern::operator std::string ( ) const { - std::stringstream ss; - ss << "\""; - - for ( const std::ranked_symbol < > & symbol : this->m_Data ) - ss << symbol; - - ss << "\""; - return std::move ( ss ).str ( ); -} - -PrefixRankedBarPattern PrefixRankedBarPattern::parse ( std::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, PrefixRankedBarPattern::getXmlTagName() ); - std::set < std::ranked_symbol < > > bars = TreeFromXMLParser::parseBars ( input ); - std::ranked_symbol < > variablesBarSymbol = TreeFromXMLParser::parseRankedVariablesBar ( input ); - std::ranked_symbol < > subtreeWildcardSymbol = TreeFromXMLParser::parseSubtreeWildcardRawRankedSymbol ( input ); - std::set < std::ranked_symbol < > > rankedAlphabet = TreeFromXMLParser::parseRankedAlphabet ( input ); - std::vector < std::ranked_symbol < > > data = TreeFromXMLParser::parseRankedLinearContent ( input ); - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, PrefixRankedBarPattern::getXmlTagName() ); - - return PrefixRankedBarPattern ( std::move ( bars ), std::move ( variablesBarSymbol ), std::move ( subtreeWildcardSymbol ), std::move ( rankedAlphabet ), std::move ( data ) ); -} - -void PrefixRankedBarPattern::compose ( std::deque < sax::Token > & out ) const { - out.emplace_back ( PrefixRankedBarPattern::getXmlTagName(), sax::Token::TokenType::START_ELEMENT ); - TreeToXMLComposer::composeBars ( out, getBars() ); - TreeToXMLComposer::composeVariablesBar ( out, getVariablesBar() ); - TreeToXMLComposer::composeSubtreeWildcard ( out, getSubtreeWildcard() ); - TreeToXMLComposer::composeAlphabet ( out, getAlphabet() ); - TreeToXMLComposer::composeContent ( out, m_Data ); - out.emplace_back ( PrefixRankedBarPattern::getXmlTagName(), sax::Token::TokenType::END_ELEMENT ); -} - -} /* namespace tree */ - namespace alib { -auto prefixRankedBarPatternParserRegister = xmlApi < ::tree::Tree >::ParserRegister < ::tree::PrefixRankedBarPattern > (); -auto prefixRankedBarPatternParserRegister2 = xmlApi < ::tree::RankedTreeWrapper >::ParserRegister < ::tree::PrefixRankedBarPattern > (); -auto prefixRankedBarPatternParserRegister3 = xmlApi < alib::Object >::ParserRegister < ::tree::PrefixRankedBarPattern > (); +auto prefixRankedBarPatternParserRegister = xmlApi < ::tree::Tree >::ParserRegister < ::tree::PrefixRankedBarPattern < > > (); +auto prefixRankedBarPatternParserRegister2 = xmlApi < ::tree::RankedTreeWrapper >::ParserRegister < ::tree::PrefixRankedBarPattern < > > (); +auto prefixRankedBarPatternParserRegister3 = xmlApi < alib::Object >::ParserRegister < ::tree::PrefixRankedBarPattern < > > (); -auto PrefixRankedBarPatternFromRankedPattern = castApi::CastRegister < ::tree::PrefixRankedBarPattern, ::tree::RankedPattern < > > ( ); -auto PrefixRankedBarPatternFromPrefixRankedBarTree = castApi::CastRegister < ::tree::PrefixRankedBarPattern, ::tree::PrefixRankedBarTree < > > ( ); -auto PrefixRankedBarPatternCastBinder = castApi::CastPoolStringBinder < ::tree::PrefixRankedBarPattern > ( ::tree::PrefixRankedBarPattern::getXmlTagName() ); +auto PrefixRankedBarPatternFromRankedPattern = castApi::CastRegister < ::tree::PrefixRankedBarPattern < >, ::tree::RankedPattern < > > ( ); +auto PrefixRankedBarPatternFromPrefixRankedBarTree = castApi::CastRegister < ::tree::PrefixRankedBarPattern < >, ::tree::PrefixRankedBarTree < > > ( ); +auto PrefixRankedBarPatternCastBinder = castApi::CastPoolStringBinder < ::tree::PrefixRankedBarPattern < > > ( ::tree::PrefixRankedBarPattern < >::getXmlTagName() ); } /* namespace alib */ diff --git a/alib2data/src/tree/ranked/PrefixRankedBarPattern.h b/alib2data/src/tree/ranked/PrefixRankedBarPattern.h index 470209d764..772bda0ca7 100644 --- a/alib2data/src/tree/ranked/PrefixRankedBarPattern.h +++ b/alib2data/src/tree/ranked/PrefixRankedBarPattern.h @@ -11,12 +11,24 @@ #include <set> #include <vector> #include <tree> +#include <sstream> +#include <algorithm> +#include <deque> + #include <core/components.hpp> +#include <sax/FromXMLParserHelper.h> +#include "alphabet/ranked_symbol.hpp" #include "../TreeFeatures.h" #include "../TreeException.h" -#include "alphabet/ranked_symbol.hpp" #include "../RankedTreeBase.h" +#include "../common/TreeFromXMLParser.h" +#include "../common/TreeToXMLComposer.h" +#include "../common/TreeAuxiliary.h" + +#include "../../alphabet/BarSymbol.h" +#include "../../alphabet/VariablesBarSymbol.h" +#include "../../alphabet/SubtreeWildcardSymbol.h" namespace tree { @@ -29,15 +41,16 @@ class VariablesBarSymbol; * Represents regular expression parsed from the XML. Regular expression is stored * as a tree of LinearStringElement. */ -class PrefixRankedBarPattern : public RankedTreeBase, public std::Components < PrefixRankedBarPattern, std::ranked_symbol < >, std::tuple < GeneralAlphabet, BarSymbols >, std::tuple < SubtreeWildcard, VariablesBarSymbol > > { - std::vector < std::ranked_symbol < > > m_Data; +template < class SymbolType, class RankType > +class PrefixRankedBarPattern : public RankedTreeBase, public std::Components < PrefixRankedBarPattern < SymbolType, RankType >, std::ranked_symbol < SymbolType, RankType >, std::tuple < GeneralAlphabet, BarSymbols >, std::tuple < SubtreeWildcard, VariablesBarSymbol > > { + std::vector < std::ranked_symbol < SymbolType, RankType > > m_Data; - static std::vector < std::ranked_symbol < > > toPrefixRankedBar ( const std::tree < std::ranked_symbol < > > & node, const std::ranked_symbol < > & subtreeWildcard, const alphabet::Symbol & barBase, const std::ranked_symbol < > & variablesBar ); + static std::vector < std::ranked_symbol < SymbolType, RankType > > toPrefixRankedBar ( const std::tree < std::ranked_symbol < SymbolType, RankType > > & node, const std::ranked_symbol < SymbolType, RankType > & subtreeWildcard, const alphabet::Symbol & barBase, const std::ranked_symbol < SymbolType, RankType > & variablesBar ); public: - explicit PrefixRankedBarPattern ( std::set < std::ranked_symbol < > > bar, std::ranked_symbol < > variablesBar, std::ranked_symbol < > subtreeWildcard, std::set < std::ranked_symbol < > > alphabet, std::vector < std::ranked_symbol < > > data ); - explicit PrefixRankedBarPattern ( std::set < std::ranked_symbol < > > bar, std::ranked_symbol < > variablesBar, std::ranked_symbol < > subtreeWildcard, std::vector < std::ranked_symbol < > > data ); - explicit PrefixRankedBarPattern ( alphabet::Symbol barBase, std::ranked_symbol < > variablesBar, const RankedPattern < > & tree ); + explicit PrefixRankedBarPattern ( std::set < std::ranked_symbol < SymbolType, RankType > > bar, std::ranked_symbol < SymbolType, RankType > variablesBar, std::ranked_symbol < SymbolType, RankType > subtreeWildcard, std::set < std::ranked_symbol < SymbolType, RankType > > alphabet, std::vector < std::ranked_symbol < SymbolType, RankType > > data ); + explicit PrefixRankedBarPattern ( std::set < std::ranked_symbol < SymbolType, RankType > > bar, std::ranked_symbol < SymbolType, RankType > variablesBar, std::ranked_symbol < SymbolType, RankType > subtreeWildcard, std::vector < std::ranked_symbol < SymbolType, RankType > > data ); + explicit PrefixRankedBarPattern ( alphabet::Symbol barBase, std::ranked_symbol < SymbolType, RankType > variablesBar, const RankedPattern < > & tree ); explicit PrefixRankedBarPattern ( const PrefixRankedBarTree < > & tree ); explicit PrefixRankedBarPattern ( const RankedPattern < > & tree ); @@ -47,31 +60,31 @@ public: /** * @return List of symbols forming tree (const version). */ - const std::vector < std::ranked_symbol < > > & getContent ( ) const; + const std::vector < std::ranked_symbol < SymbolType, RankType > > & getContent ( ) const; - const std::set < std::ranked_symbol < > > & getAlphabet ( ) const { - return accessComponent < GeneralAlphabet > ( ).get ( ); + const std::set < std::ranked_symbol < SymbolType, RankType > > & getAlphabet ( ) const { + return this->template accessComponent < GeneralAlphabet > ( ).get ( ); } - void extendAlphabet ( const std::set < std::ranked_symbol < > > & symbols ) { - accessComponent < GeneralAlphabet > ( ).add ( symbols ); + void extendAlphabet ( const std::set < std::ranked_symbol < SymbolType, RankType > > & symbols ) { + this->template accessComponent < GeneralAlphabet > ( ).add ( symbols ); } - const std::set < std::ranked_symbol < > > & getBars ( ) const { - return accessComponent < BarSymbols > ( ).get ( ); + const std::set < std::ranked_symbol < SymbolType, RankType > > & getBars ( ) const { + return this->template accessComponent < BarSymbols > ( ).get ( ); } - const std::ranked_symbol < > & getSubtreeWildcard ( ) const { - return accessElement < SubtreeWildcard > ( ).get ( ); + const std::ranked_symbol < SymbolType, RankType > & getSubtreeWildcard ( ) const { + return this->template accessElement < SubtreeWildcard > ( ).get ( ); } - const std::ranked_symbol < > & getVariablesBar ( ) const { - return accessElement < VariablesBarSymbol > ( ).get ( ); + const std::ranked_symbol < SymbolType, RankType > & getVariablesBar ( ) const { + return this->template accessElement < VariablesBarSymbol > ( ).get ( ); } - void setContent ( std::vector < std::ranked_symbol < > > data ); + void setContent ( std::vector < std::ranked_symbol < SymbolType, RankType > > data ); - void arityChecksum ( const std::vector < std::ranked_symbol < > > & data ); + void arityChecksum ( const std::vector < std::ranked_symbol < SymbolType, RankType > > & data ); /** * @return true if tree is an empty word (vector length is 0) @@ -103,63 +116,223 @@ public: } /* namespace tree */ +#include "RankedPattern.h" +#include "PrefixRankedBarTree.h" + +namespace tree { + +template < class SymbolType, class RankType > +PrefixRankedBarPattern < SymbolType, RankType >::PrefixRankedBarPattern ( std::set < std::ranked_symbol < SymbolType, RankType > > bars, std::ranked_symbol < SymbolType, RankType > variablesBar, std::ranked_symbol < SymbolType, RankType > subtreeWildcard, std::set < std::ranked_symbol < SymbolType, RankType > > alphabet, std::vector < std::ranked_symbol < SymbolType, RankType > > data ) : std::Components < PrefixRankedBarPattern, std::ranked_symbol < SymbolType, RankType >, std::tuple < GeneralAlphabet, BarSymbols >, std::tuple < SubtreeWildcard, VariablesBarSymbol > > ( std::make_tuple ( std::move ( alphabet ), std::move ( bars ) ), std::make_tuple ( std::move ( subtreeWildcard ), std::move ( variablesBar ) ) ) { + setContent ( std::move ( data ) ); +} + +template < class SymbolType, class RankType > +PrefixRankedBarPattern < SymbolType, RankType >::PrefixRankedBarPattern ( std::set < std::ranked_symbol < SymbolType, RankType > > bars, std::ranked_symbol < SymbolType, RankType > variablesBar, std::ranked_symbol < SymbolType, RankType > subtreeWildcard, std::vector < std::ranked_symbol < SymbolType, RankType > > data ) : PrefixRankedBarPattern ( bars, variablesBar, subtreeWildcard, std::set < std::ranked_symbol < SymbolType, RankType > > ( data.begin ( ), data.end ( ) ) + bars + std::set < std::ranked_symbol < SymbolType, RankType > > { variablesBar, subtreeWildcard }, data ) { +} + +template < class SymbolType, class RankType > +PrefixRankedBarPattern < SymbolType, RankType >::PrefixRankedBarPattern ( alphabet::Symbol barBase, std::ranked_symbol < SymbolType, RankType > variablesBar, const RankedPattern < > & tree ) : PrefixRankedBarPattern ( TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + std::set < std::ranked_symbol < SymbolType, RankType > > { variablesBar }, variablesBar, tree.getSubtreeWildcard ( ), tree.getAlphabet ( ) + TreeAuxiliary::computeBars ( tree.getAlphabet ( ), barBase ) + std::set < std::ranked_symbol < SymbolType, RankType > > { variablesBar, tree.getSubtreeWildcard ( ) }, toPrefixRankedBar ( tree.getContent ( ), tree.getSubtreeWildcard ( ), barBase, variablesBar ) ) { +} + +template < class SymbolType, class RankType > +PrefixRankedBarPattern < SymbolType, RankType >::PrefixRankedBarPattern ( const PrefixRankedBarTree < > & tree ) : PrefixRankedBarPattern ( tree.getBars() + std::set < std::ranked_symbol < SymbolType, RankType > > { alphabet::VariablesBarSymbol::RANKED_BAR_SYMBOL }, alphabet::VariablesBarSymbol::RANKED_BAR_SYMBOL, alphabet::SubtreeWildcardSymbol::RANKED_SUBTREE_WILDCARD_SYMBOL, tree.getAlphabet ( ) + std::set < std::ranked_symbol < SymbolType, RankType > > { alphabet::VariablesBarSymbol::RANKED_BAR_SYMBOL, alphabet::SubtreeWildcardSymbol::RANKED_SUBTREE_WILDCARD_SYMBOL }, tree.getContent ( ) ) { +} + +template < class SymbolType, class RankType > +PrefixRankedBarPattern < SymbolType, RankType >::PrefixRankedBarPattern ( const RankedPattern < > & tree ) : PrefixRankedBarPattern ( alphabet::BarSymbol::BAR_SYMBOL, alphabet::VariablesBarSymbol::RANKED_BAR_SYMBOL, tree ) { +} + +template < class SymbolType, class RankType > +std::vector < std::ranked_symbol < SymbolType, RankType > > PrefixRankedBarPattern < SymbolType, RankType >::toPrefixRankedBar ( const std::tree < std::ranked_symbol < SymbolType, RankType > > & tree, const std::ranked_symbol < SymbolType, RankType > & subtreeWildcard, const alphabet::Symbol & barBase, const std::ranked_symbol < SymbolType, RankType > & variablesBar ) { + std::vector < std::ranked_symbol < SymbolType, RankType > > res; + + for ( typename std::tree < std::ranked_symbol < SymbolType, RankType > >::const_structure_iterator iter = tree.structure_begin ( ); iter != tree.structure_end ( ); ++iter ) + if ( iter.getVirtual ( ) ) + if ( ( * iter == subtreeWildcard ) ) + res.push_back ( variablesBar ); + else + res.push_back ( std::ranked_symbol < SymbolType, RankType > ( barBase, iter->getRank ( ) ) ); + else + res.push_back ( * iter ); + + return res; +} + +template < class SymbolType, class RankType > +RankedTreeBase * PrefixRankedBarPattern < SymbolType, RankType >::clone ( ) const { + return new PrefixRankedBarPattern ( * this ); +} + +template < class SymbolType, class RankType > +RankedTreeBase * PrefixRankedBarPattern < SymbolType, RankType >::plunder ( ) && { + return new PrefixRankedBarPattern ( std::move ( * this ) ); +} + +template < class SymbolType, class RankType > +const std::vector < std::ranked_symbol < SymbolType, RankType > > & PrefixRankedBarPattern < SymbolType, RankType >::getContent ( ) const { + return this->m_Data; +} + +template < class SymbolType, class RankType > +void PrefixRankedBarPattern < SymbolType, RankType >::setContent ( std::vector < std::ranked_symbol < SymbolType, RankType > > data ) { + arityChecksum ( data ); + + std::set < std::ranked_symbol < SymbolType, RankType > > minimalAlphabet ( data.begin ( ), data.end ( ) ); + std::set < std::ranked_symbol < SymbolType, RankType > > unknownSymbols; + std::set_difference ( minimalAlphabet.begin ( ), minimalAlphabet.end ( ), getAlphabet().begin ( ), getAlphabet().end ( ), std::inserter ( unknownSymbols, unknownSymbols.end ( ) ) ); + + if ( unknownSymbols.size ( ) > 0 ) + throw TreeException ( "Input symbols not in the alphabet." ); + + this->m_Data = std::move ( data ); +} + +template < class SymbolType, class RankType > +void PrefixRankedBarPattern < SymbolType, RankType >::arityChecksum ( const std::vector < std::ranked_symbol < SymbolType, RankType > > & data ) { + int arityChecksumTerminals = 1; + int arityChecksumBars = 1; + int arityChecksumTypes = 0; + + for ( const std::ranked_symbol < SymbolType, RankType > & symbol : data ) { + if ( getBars ( ).count ( symbol ) || symbol == getVariablesBar ( ) ) { + arityChecksumBars += symbol.getRank ( ).getData ( ); + arityChecksumBars -= 1; + arityChecksumTypes -= 1; + } else { + arityChecksumTerminals += symbol.getRank ( ).getData ( ); + arityChecksumTerminals -= 1; + arityChecksumTypes += 1; + } + } + + if ( ( arityChecksumTerminals != 0 ) || ( arityChecksumBars != 0 ) || ( arityChecksumTypes != 0 ) ) throw TreeException ( "The string does not form a tree" ); + + for ( unsigned i = 1; i < data.size ( ); ++i ) + if ( data[i - 1] == getSubtreeWildcard ( ) && data[i] != getVariablesBar ( ) ) + throw TreeException ( "Inconsystency of SubtreeWildcard and variablesBar" ); + +} + +template < class SymbolType, class RankType > +bool PrefixRankedBarPattern < SymbolType, RankType >::isEmpty ( ) const { + return this->m_Data.size ( ) == 0; +} + +template < class SymbolType, class RankType > +int PrefixRankedBarPattern < SymbolType, RankType >::compare ( const PrefixRankedBarPattern & other ) const { + auto first = std::tie ( m_Data, getAlphabet(), getSubtreeWildcard(), getBars(), getVariablesBar() ); + auto second = std::tie ( other.m_Data, other.getAlphabet(), other.getSubtreeWildcard(), other.getBars(), other.getVariablesBar() ); + + std::compare < decltype ( first ) > comp; + + return comp ( first, second ); +} + +template < class SymbolType, class RankType > +void PrefixRankedBarPattern < SymbolType, RankType >::operator >>( std::ostream & out ) const { + out << "(PrefixRankedBarPattern "; + + for ( const std::ranked_symbol < SymbolType, RankType > & symbol : this->m_Data ) + out << symbol; + + out << ")"; +} + +template < class SymbolType, class RankType > +PrefixRankedBarPattern < SymbolType, RankType >::operator std::string ( ) const { + std::stringstream ss; + ss << "\""; + + for ( const std::ranked_symbol < SymbolType, RankType > & symbol : this->m_Data ) + ss << symbol; + + ss << "\""; + return std::move ( ss ).str ( ); +} + +template < class SymbolType, class RankType > +PrefixRankedBarPattern < SymbolType, RankType > PrefixRankedBarPattern < SymbolType, RankType >::parse ( std::deque < sax::Token >::iterator & input ) { + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, PrefixRankedBarPattern::getXmlTagName() ); + std::set < std::ranked_symbol < SymbolType, RankType > > bars = TreeFromXMLParser::parseBars ( input ); + std::ranked_symbol < SymbolType, RankType > variablesBarSymbol = TreeFromXMLParser::parseRankedVariablesBar ( input ); + std::ranked_symbol < SymbolType, RankType > subtreeWildcardSymbol = TreeFromXMLParser::parseSubtreeWildcardRawRankedSymbol ( input ); + std::set < std::ranked_symbol < SymbolType, RankType > > rankedAlphabet = TreeFromXMLParser::parseRankedAlphabet ( input ); + std::vector < std::ranked_symbol < SymbolType, RankType > > data = TreeFromXMLParser::parseRankedLinearContent ( input ); + sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, PrefixRankedBarPattern::getXmlTagName() ); + + return PrefixRankedBarPattern < SymbolType, RankType > ( std::move ( bars ), std::move ( variablesBarSymbol ), std::move ( subtreeWildcardSymbol ), std::move ( rankedAlphabet ), std::move ( data ) ); +} + +template < class SymbolType, class RankType > +void PrefixRankedBarPattern < SymbolType, RankType >::compose ( std::deque < sax::Token > & out ) const { + out.emplace_back ( PrefixRankedBarPattern::getXmlTagName(), sax::Token::TokenType::START_ELEMENT ); + TreeToXMLComposer::composeBars ( out, getBars() ); + TreeToXMLComposer::composeVariablesBar ( out, getVariablesBar() ); + TreeToXMLComposer::composeSubtreeWildcard ( out, getSubtreeWildcard() ); + TreeToXMLComposer::composeAlphabet ( out, getAlphabet() ); + TreeToXMLComposer::composeContent ( out, m_Data ); + out.emplace_back ( PrefixRankedBarPattern::getXmlTagName(), sax::Token::TokenType::END_ELEMENT ); +} + +} /* namespace tree */ + namespace std { -template < > -class ComponentConstraint< ::tree::PrefixRankedBarPattern, std::ranked_symbol < >, ::tree::GeneralAlphabet > { +template < class SymbolType, class RankType > +class ComponentConstraint< ::tree::PrefixRankedBarPattern < SymbolType, RankType >, std::ranked_symbol < SymbolType, RankType >, ::tree::GeneralAlphabet > { public: - static bool used ( const ::tree::PrefixRankedBarPattern & pattern, const std::ranked_symbol < > & symbol ) { - const std::vector < std::ranked_symbol < > > & content = pattern.getContent ( ); + static bool used ( const ::tree::PrefixRankedBarPattern < SymbolType, RankType > & pattern, const std::ranked_symbol < SymbolType, RankType > & symbol ) { + const std::vector < std::ranked_symbol < SymbolType, RankType > > & content = pattern.getContent ( ); - return std::find ( content.begin ( ), content.end ( ), symbol ) != content.end ( ) || pattern.accessElement < ::tree::VariablesBarSymbol > ( ).get ( ) == symbol || pattern.accessComponent < ::tree::BarSymbols > ( ).get ( ).count ( symbol ) || pattern.accessElement < ::tree::SubtreeWildcard > ( ).get ( ) == symbol; + return std::find ( content.begin ( ), content.end ( ), symbol ) != content.end ( ) || pattern.template accessElement < ::tree::VariablesBarSymbol > ( ).get ( ) == symbol || pattern.template accessComponent < ::tree::BarSymbols > ( ).get ( ).count ( symbol ) || pattern.template accessElement < ::tree::SubtreeWildcard > ( ).get ( ) == symbol; } - static bool available ( const ::tree::PrefixRankedBarPattern &, const std::ranked_symbol < > & ) { + static bool available ( const ::tree::PrefixRankedBarPattern < SymbolType, RankType > &, const std::ranked_symbol < SymbolType, RankType > & ) { return true; } - static void valid ( const ::tree::PrefixRankedBarPattern &, const std::ranked_symbol < > & ) { + static void valid ( const ::tree::PrefixRankedBarPattern < SymbolType, RankType > &, const std::ranked_symbol < SymbolType, RankType > & ) { } }; -template < > -class ComponentConstraint< ::tree::PrefixRankedBarPattern, std::ranked_symbol < >, ::tree::BarSymbols > { +template < class SymbolType, class RankType > +class ComponentConstraint< ::tree::PrefixRankedBarPattern < SymbolType, RankType >, std::ranked_symbol < SymbolType, RankType >, ::tree::BarSymbols > { public: - static bool used ( const ::tree::PrefixRankedBarPattern & pattern, const std::ranked_symbol < > & symbol ) { - const std::vector < std::ranked_symbol < > > & content = pattern.getContent ( ); + static bool used ( const ::tree::PrefixRankedBarPattern < SymbolType, RankType > & pattern, const std::ranked_symbol < SymbolType, RankType > & symbol ) { + const std::vector < std::ranked_symbol < SymbolType, RankType > > & content = pattern.getContent ( ); - return std::find ( content.begin ( ), content.end ( ), symbol ) != content.end ( ) || pattern.accessElement < ::tree::VariablesBarSymbol > ( ).get ( ) == symbol; + return std::find ( content.begin ( ), content.end ( ), symbol ) != content.end ( ) || pattern.template accessElement < ::tree::VariablesBarSymbol > ( ).get ( ) == symbol; } - static bool available ( const ::tree::PrefixRankedBarPattern & pattern, const std::ranked_symbol < > & symbol ) { - return pattern.accessComponent < ::tree::GeneralAlphabet > ( ).get ( ).count ( symbol ); + static bool available ( const ::tree::PrefixRankedBarPattern < SymbolType, RankType > & pattern, const std::ranked_symbol < SymbolType, RankType > & symbol ) { + return pattern.template accessComponent < ::tree::GeneralAlphabet > ( ).get ( ).count ( symbol ); } - static void valid ( const ::tree::PrefixRankedBarPattern &, const std::ranked_symbol < > & ) { + static void valid ( const ::tree::PrefixRankedBarPattern < SymbolType, RankType > &, const std::ranked_symbol < SymbolType, RankType > & ) { } }; -template < > -class ElementConstraint< ::tree::PrefixRankedBarPattern, std::ranked_symbol < >, ::tree::SubtreeWildcard > { +template < class SymbolType, class RankType > +class ElementConstraint< ::tree::PrefixRankedBarPattern < SymbolType, RankType >, std::ranked_symbol < SymbolType, RankType >, ::tree::SubtreeWildcard > { public: - static bool available ( const ::tree::PrefixRankedBarPattern & pattern, const std::ranked_symbol < > & symbol ) { - return pattern.accessComponent < ::tree::GeneralAlphabet > ( ).get ( ).count ( symbol ); + static bool available ( const ::tree::PrefixRankedBarPattern < SymbolType, RankType > & pattern, const std::ranked_symbol < SymbolType, RankType > & symbol ) { + return pattern.template accessComponent < ::tree::GeneralAlphabet > ( ).get ( ).count ( symbol ); } - static void valid ( const ::tree::PrefixRankedBarPattern &, const std::ranked_symbol < > & symbol) { + static void valid ( const ::tree::PrefixRankedBarPattern < SymbolType, RankType > &, const std::ranked_symbol < SymbolType, RankType > & symbol) { if( symbol.getRank().getData() != 0 ) throw ::tree::TreeException ( "SubtreeWildcard symbol has nonzero arity" ); } }; -template < > -class ElementConstraint< ::tree::PrefixRankedBarPattern, std::ranked_symbol < >, ::tree::VariablesBarSymbol > { +template < class SymbolType, class RankType > +class ElementConstraint< ::tree::PrefixRankedBarPattern < SymbolType, RankType >, std::ranked_symbol < SymbolType, RankType >, ::tree::VariablesBarSymbol > { public: - static bool available ( const ::tree::PrefixRankedBarPattern & pattern, const std::ranked_symbol < > & symbol ) { - return pattern.accessComponent < ::tree::BarSymbols > ( ).get ( ).count ( symbol ); + static bool available ( const ::tree::PrefixRankedBarPattern < SymbolType, RankType > & pattern, const std::ranked_symbol < SymbolType, RankType > & symbol ) { + return pattern.template accessComponent < ::tree::BarSymbols > ( ).get ( ).count ( symbol ); } - static void valid ( const ::tree::PrefixRankedBarPattern &, const std::ranked_symbol < > & symbol) { + static void valid ( const ::tree::PrefixRankedBarPattern < SymbolType, RankType > &, const std::ranked_symbol < SymbolType, RankType > & symbol) { if( symbol.getRank().getData() != 0 ) throw ::tree::TreeException ( "VariablesBarSymbol has nonzero arity" ); } diff --git a/alib2data/test-src/tree/PatternTest.cpp b/alib2data/test-src/tree/PatternTest.cpp index cb4be01400..3d8e7fe7d1 100644 --- a/alib2data/test-src/tree/PatternTest.cpp +++ b/alib2data/test-src/tree/PatternTest.cpp @@ -173,7 +173,7 @@ void PatternTest::testPrefixRankedBarPatternParser() { std::tree < std::ranked_symbol < > > node1(a, {std::move(node2), std::move(node4)}); tree::RankedPattern < > pattern(S, alphabet, std::move(node1)); - tree::PrefixRankedBarPattern pattern2(alphabet::BarSymbol::BAR_SYMBOL, alphabet::VariablesBarSymbol::RANKED_BAR_SYMBOL, pattern); + tree::PrefixRankedBarPattern < > pattern2(alphabet::BarSymbol::BAR_SYMBOL, alphabet::VariablesBarSymbol::RANKED_BAR_SYMBOL, pattern); CPPUNIT_ASSERT( pattern2 == pattern2 ); { @@ -185,7 +185,7 @@ void PatternTest::testPrefixRankedBarPatternParser() { std::deque<sax::Token> tokens2; sax::SaxParseInterface::parseMemory(tmp, tokens2); - tree::PrefixRankedBarPattern pattern3 = alib::XmlDataFactory::fromTokens<tree::PrefixRankedBarPattern>(std::move(tokens2)); + tree::PrefixRankedBarPattern < > pattern3 = alib::XmlDataFactory::fromTokens<tree::PrefixRankedBarPattern < > >(std::move(tokens2)); CPPUNIT_ASSERT( pattern2 == pattern3 ); std::cout << std::endl; -- GitLab