Skip to content

Commit

Permalink
Removed some unused parser functions
Browse files Browse the repository at this point in the history
  • Loading branch information
apathism committed Oct 7, 2019
1 parent f538be9 commit 9562b0e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 120 deletions.
70 changes: 0 additions & 70 deletions core/src/main/lspl/patterns/parsers/Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Matcher> & matchers, const std::string & base, SpeechPart speechPart, uint index, boost::ptr_vector< Restriction > & restrictions ) const {
WordMatcher * matcher;

Expand All @@ -73,13 +63,6 @@ void AddWordMatcherImpl::operator()( boost::ptr_vector<Matcher> & matchers, cons
matchers.push_back( matcher );
}

void AddTokenMatcherImpl::operator()( boost::ptr_vector<Matcher> & 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<Matcher> & matchers, const std::string & token ) const {
matchers.push_back( new TokenMatcher( token ) );
}
Expand All @@ -88,20 +71,6 @@ void AddStringMatcherImpl::operator()( boost::ptr_vector<Matcher> & matchers, co
matchers.push_back( new StringMatcher( token ) );
}

void AddLoopMatcherImpl::operator()( boost::ptr_vector<Matcher> & matchers, uint min, uint max, std::vector<uint> & 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 );

Expand All @@ -124,22 +93,6 @@ void AddPatternMatcherImpl::operator()( boost::ptr_vector<Matcher> & matchers, c
matchers.push_back( matcher );
}

void AddAlternativeDefinitionImpl::operator()( boost::ptr_vector<Alternative> & alts, boost::ptr_vector<Matcher> & matchers, boost::ptr_map<AttributeKey,Expression> & 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<transforms::Transform>( transformBuilder->second->build( *alternative, alternative->getTransformSource() ) ) );

alts.push_back( alternative );
}

void AddRestrictionImpl::operator()( boost::ptr_vector<Matcher> & matchers, Restriction * restriction ) const {
findLastMatcher( matchers, restriction ).addRestriction( restriction );
}
Expand All @@ -163,29 +116,6 @@ void AddNormalizationRestrictionImpl::operator()( boost::ptr_vector<Restriction>
restrictions.push_back( restriction );
}

void AddBindingImpl::operator()( boost::ptr_map<AttributeKey,Expression> & bindings, AttributeKey att, Expression * exp ) const {
if ( att == AttributeKey::UNDEFINED && dynamic_cast<AttributeExpression*>( exp ) ) {
bindings.insert( static_cast<AttributeExpression*>( exp )->attribute, exp ); // Если у аттрибута не указано связывание, связываем его с соответствующим аттрибутом
} else if ( att == AttributeKey::UNDEFINED && dynamic_cast<ConcatenationExpression*>( exp ) ) {
bindings.insert( att = AttributeKey::TEXT, exp ); // Если у текстового выражения не указано связывание, связываем его с аттрибутом TEXT
} else {
bindings.insert( att, exp );
}
}

Restriction * CreateDictionaryRestrictionImpl::operator()( const std::string & dictionaryName, boost::ptr_vector<Expression> & 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<Expression> & args ) const {
AgreementRestriction * dr = new AgreementRestriction();

Expand Down
50 changes: 0 additions & 50 deletions core/src/main/lspl/patterns/parsers/Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ struct AddWordMatcherImpl {
void operator()( boost::ptr_vector<Matcher> & matchers, const std::string & base, SpeechPart speechPart, uint index, boost::ptr_vector< Restriction > & restrictions ) const;
};

struct AddTokenMatcherImpl {

template <typename Arg1, typename Arg2>
struct result { typedef void type; };

void operator()( boost::ptr_vector<Matcher> & matchers, const std::string & token ) const;
};

struct AddTokenMatcherNoRegexpImpl {

template <typename Arg1, typename Arg2>
Expand All @@ -71,14 +63,6 @@ struct AddStringMatcherImpl {
void operator()( boost::ptr_vector<Matcher> & matchers, const std::string & token ) const;
};

struct AddLoopMatcherImpl {

template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
struct result { typedef void type; };

void operator()( boost::ptr_vector<Matcher> & matchers, uint min, uint max, std::vector<uint> & alternativesCount ) const ;
};

struct DefinePattern {
public:
DefinePattern( Namespace & space, boost::spirit::classic::symbols<uint> & typeSymbol ) :
Expand All @@ -101,20 +85,6 @@ struct AddPatternMatcherImpl : public DefinePattern {
void operator()( boost::ptr_vector<Matcher> & matchers, const std::string & name, uint index, boost::ptr_vector< Restriction > & restrictions ) const;
};

struct AddAlternativeDefinitionImpl {

template <typename Arg1, typename Arg2, typename Arg3, typename Arg4, typename Arg5, typename Arg6>
struct result { typedef void type; };

AddAlternativeDefinitionImpl( const std::map<std::string, transforms::TransformBuilderRef>& transformBuilders ) :
transformBuilders( transformBuilders ) {}

void operator()( boost::ptr_vector<Alternative> & alts, boost::ptr_vector<Matcher> & matchers, boost::ptr_map<AttributeKey,Expression> & bindings, const std::string & source, const std::string & transformSource, const std::string & transformType ) const;

private:
const std::map<std::string, transforms::TransformBuilderRef>& transformBuilders;
};

struct AddImpl {
template <typename Arg1, typename Arg2>
struct result { typedef void type; };
Expand All @@ -141,26 +111,6 @@ struct AddNormalizationRestrictionImpl {
void operator()( boost::ptr_vector<Restriction> & restrictions ) const;
};

struct AddBindingImpl {
template <typename Arg1, typename Arg2, typename Arg3>
struct result { typedef void type; };

void operator()( boost::ptr_map<AttributeKey,Expression> & bindings, AttributeKey att, Expression * exp ) const;
};

struct CreateDictionaryRestrictionImpl {
template <typename Arg1, typename Arg2>
struct result { typedef Restriction * type; };

CreateDictionaryRestrictionImpl( Namespace & ns ) :
ns( ns ) {
}

Restriction * operator()( const std::string & dictionaryName, boost::ptr_vector<Expression> & args ) const;

Namespace & ns;
};

struct CreateAgreementRestrictionImpl {
template <typename Arg1>
struct result { typedef Restriction * type; };
Expand Down

0 comments on commit 9562b0e

Please sign in to comment.