diff --git a/core/src/main/lspl/patterns/parsers/Functions.cpp b/core/src/main/lspl/patterns/parsers/Functions.cpp index f035e869..dc221464 100644 --- a/core/src/main/lspl/patterns/parsers/Functions.cpp +++ b/core/src/main/lspl/patterns/parsers/Functions.cpp @@ -46,16 +46,6 @@ using lspl::morphology::Morphology; namespace lspl { namespace patterns { namespace parsers { -static bool isRegexp( const std::string & str ) { - static std::string regexSymbols( ".[{()\\*+?|^$'" ); - - for ( uint i = 0; i < regexSymbols.length(); ++ i ) - if ( str.find( regexSymbols.at(i) ) != std::string::npos ) - return true; - - return false; -} - void AddWordMatcherImpl::operator()( boost::ptr_vector & matchers, const std::string & base, SpeechPart speechPart, uint index, boost::ptr_vector< Restriction > & restrictions ) const { WordMatcher * matcher; @@ -73,13 +63,6 @@ void AddWordMatcherImpl::operator()( boost::ptr_vector & matchers, cons matchers.push_back( matcher ); } -void AddTokenMatcherImpl::operator()( boost::ptr_vector & matchers, const std::string & token ) const { - if ( isRegexp( token ) ) - matchers.push_back( new RegexpMatcher( token ) ); - else - matchers.push_back( new TokenMatcher( token ) ); -} - void AddTokenMatcherNoRegexpImpl::operator()( boost::ptr_vector & matchers, const std::string & token ) const { matchers.push_back( new TokenMatcher( token ) ); } @@ -88,20 +71,6 @@ void AddStringMatcherImpl::operator()( boost::ptr_vector & matchers, co matchers.push_back( new StringMatcher( token ) ); } -void AddLoopMatcherImpl::operator()( boost::ptr_vector & matchers, uint min, uint max, std::vector & alternativesCount ) const { - LoopMatcher * matcher = new LoopMatcher( min, max ); - - for ( int i = alternativesCount.size() - 1; i >= 0 ; -- i ) { // Важно!! Здесь перебираем в обратном порядке! - MatcherContainer * matcherGroup = new MatcherContainer(); // Создаем контейнер для альтернативы - - matcherGroup->addMatchers( matchers.end() - alternativesCount[ i ], matchers.end(), matchers ); - - matcher->addAlternative( matcherGroup ); - } - - matchers.push_back( matcher ); -} - PatternRef DefinePattern::getPattern( const std::string & name ) const { PatternRef pattern = space.getPatternByName( name ); @@ -124,22 +93,6 @@ void AddPatternMatcherImpl::operator()( boost::ptr_vector & matchers, c matchers.push_back( matcher ); } -void AddAlternativeDefinitionImpl::operator()( boost::ptr_vector & alts, boost::ptr_vector & matchers, boost::ptr_map & bindings, const std::string & source, const std::string & transformSource, const std::string & transformType ) const { - Alternative * alternative = new Alternative( source, transformSource ); // Добавляем новую альтернативу к шаблону - - alternative->addMatchers( matchers ); // Добавляем сопоставители - alternative->addBindings( bindings ); // Добавляем связывания - alternative->updateDependencies(); // Обновляем зависимости альтернативы - - const auto transformBuilder = transformBuilders.find(transformType); - if (transformBuilder == transformBuilders.end()) - throw PatternBuildingException("Invalid transform type: =" + transformType + ">", "", 0); - - alternative->setTransform( std::unique_ptr( transformBuilder->second->build( *alternative, alternative->getTransformSource() ) ) ); - - alts.push_back( alternative ); -} - void AddRestrictionImpl::operator()( boost::ptr_vector & matchers, Restriction * restriction ) const { findLastMatcher( matchers, restriction ).addRestriction( restriction ); } @@ -163,29 +116,6 @@ void AddNormalizationRestrictionImpl::operator()( boost::ptr_vector restrictions.push_back( restriction ); } -void AddBindingImpl::operator()( boost::ptr_map & bindings, AttributeKey att, Expression * exp ) const { - if ( att == AttributeKey::UNDEFINED && dynamic_cast( exp ) ) { - bindings.insert( static_cast( exp )->attribute, exp ); // Если у аттрибута не указано связывание, связываем его с соответствующим аттрибутом - } else if ( att == AttributeKey::UNDEFINED && dynamic_cast( exp ) ) { - bindings.insert( att = AttributeKey::TEXT, exp ); // Если у текстового выражения не указано связывание, связываем его с аттрибутом TEXT - } else { - bindings.insert( att, exp ); - } -} - -Restriction * CreateDictionaryRestrictionImpl::operator()( const std::string & dictionaryName, boost::ptr_vector & args ) const { - dictionaries::DictionaryRef dict = ns.getDictionaryByName( dictionaryName ); - - if ( !dict ) // Не нашли словаря - выкидываем исключение - throw PatternBuildingException( "No dictionary found", "", 0 ); - - DictionaryRestriction * dr = new DictionaryRestriction( dict ); - - dr->addArguments( args ); - - return dr; -} - Restriction * CreateAgreementRestrictionImpl::operator()( boost::ptr_vector & args ) const { AgreementRestriction * dr = new AgreementRestriction(); diff --git a/core/src/main/lspl/patterns/parsers/Functions.h b/core/src/main/lspl/patterns/parsers/Functions.h index 09804460..4ff96a41 100644 --- a/core/src/main/lspl/patterns/parsers/Functions.h +++ b/core/src/main/lspl/patterns/parsers/Functions.h @@ -47,14 +47,6 @@ struct AddWordMatcherImpl { void operator()( boost::ptr_vector & matchers, const std::string & base, SpeechPart speechPart, uint index, boost::ptr_vector< Restriction > & restrictions ) const; }; -struct AddTokenMatcherImpl { - - template - struct result { typedef void type; }; - - void operator()( boost::ptr_vector & matchers, const std::string & token ) const; -}; - struct AddTokenMatcherNoRegexpImpl { template @@ -71,14 +63,6 @@ struct AddStringMatcherImpl { void operator()( boost::ptr_vector & matchers, const std::string & token ) const; }; -struct AddLoopMatcherImpl { - - template - struct result { typedef void type; }; - - void operator()( boost::ptr_vector & matchers, uint min, uint max, std::vector & alternativesCount ) const ; -}; - struct DefinePattern { public: DefinePattern( Namespace & space, boost::spirit::classic::symbols & typeSymbol ) : @@ -101,20 +85,6 @@ struct AddPatternMatcherImpl : public DefinePattern { void operator()( boost::ptr_vector & matchers, const std::string & name, uint index, boost::ptr_vector< Restriction > & restrictions ) const; }; -struct AddAlternativeDefinitionImpl { - - template - struct result { typedef void type; }; - - AddAlternativeDefinitionImpl( const std::map& transformBuilders ) : - transformBuilders( transformBuilders ) {} - - void operator()( boost::ptr_vector & alts, boost::ptr_vector & matchers, boost::ptr_map & bindings, const std::string & source, const std::string & transformSource, const std::string & transformType ) const; - -private: - const std::map& transformBuilders; -}; - struct AddImpl { template struct result { typedef void type; }; @@ -141,26 +111,6 @@ struct AddNormalizationRestrictionImpl { void operator()( boost::ptr_vector & restrictions ) const; }; -struct AddBindingImpl { - template - struct result { typedef void type; }; - - void operator()( boost::ptr_map & bindings, AttributeKey att, Expression * exp ) const; -}; - -struct CreateDictionaryRestrictionImpl { - template - struct result { typedef Restriction * type; }; - - CreateDictionaryRestrictionImpl( Namespace & ns ) : - ns( ns ) { - } - - Restriction * operator()( const std::string & dictionaryName, boost::ptr_vector & args ) const; - - Namespace & ns; -}; - struct CreateAgreementRestrictionImpl { template struct result { typedef Restriction * type; };