diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2015-01-14 14:07:42 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2015-01-14 14:07:42 +0300 |
commit | 05ead45e71916c5763c5c4b6375e2ca6838f3995 (patch) | |
tree | c279bd4aacfb31758720ffbaf5aaf62022574a52 /moses/Word.cpp | |
parent | 91cb549ccf09fc33122f3d531f47c38ad0e99b3d (diff) |
beautify
Diffstat (limited to 'moses/Word.cpp')
-rw-r--r-- | moses/Word.cpp | 98 |
1 files changed, 47 insertions, 51 deletions
diff --git a/moses/Word.cpp b/moses/Word.cpp index b1ea77059..f55be5ee8 100644 --- a/moses/Word.cpp +++ b/moses/Word.cpp @@ -34,15 +34,15 @@ using namespace std; namespace Moses { - - // utility function for factorless decoding - size_t - max_fax() - { - if (StaticData::Instance().GetFactorDelimiter().size()) - return MAX_NUM_FACTORS; - return 1; - } + +// utility function for factorless decoding +size_t +max_fax() +{ + if (StaticData::Instance().GetFactorDelimiter().size()) + return MAX_NUM_FACTORS; + return 1; +} // static int Word::Compare(const Word &targetWord, const Word &sourceWord) @@ -85,8 +85,8 @@ std::string Word::GetString(const vector<FactorType> factorType,bool endWithBlan unsigned int stop = min(max_fax(),factorType.size()); for (unsigned int i = 0 ; i < stop ; i++) { UTIL_THROW_IF2(factorType[i] >= MAX_NUM_FACTORS, - "Trying to reference factor " << factorType[i] - << ". Max factor is " << MAX_NUM_FACTORS); + "Trying to reference factor " << factorType[i] + << ". Max factor is " << MAX_NUM_FACTORS); const Factor *factor = m_factorArray[factorType[i]]; if (factor != NULL) { @@ -109,49 +109,45 @@ StringPiece Word::GetString(FactorType factorType) const class StrayFactorException : public util::Exception {}; -void +void Word:: CreateFromString(FactorDirection direction - , const std::vector<FactorType> &factorOrder - , const StringPiece &str - , bool isNonTerminal - , bool strict) + , const std::vector<FactorType> &factorOrder + , const StringPiece &str + , bool isNonTerminal + , bool strict) { FactorCollection &factorCollection = FactorCollection::Instance(); vector<StringPiece> bits(MAX_NUM_FACTORS); string factorDelimiter = StaticData::Instance().GetFactorDelimiter(); - if (factorDelimiter.size()) - { - util::TokenIter<util::MultiCharacter> fit(str, factorDelimiter); - size_t i = 0; - for (; i < MAX_NUM_FACTORS && fit; ++i,++fit) - bits[i] = *fit; - if (i == MAX_NUM_FACTORS) - UTIL_THROW_IF(fit, StrayFactorException, - "The hard limit for factors is " << MAX_NUM_FACTORS - << ". The word " << str << " contains factor delimiter " - << StaticData::Instance().GetFactorDelimiter() - << " too many times."); - if (strict) - UTIL_THROW_IF(fit, StrayFactorException, - "You have configured " << factorOrder.size() - << " factors but the word " << str - << " contains factor delimiter " - << StaticData::Instance().GetFactorDelimiter() - << " too many times."); - UTIL_THROW_IF(!isNonTerminal && i < factorOrder.size(),util::Exception, - "Too few factors in string '" << str << "'."); - } - else - { - bits[0] = str; - } - for (size_t k = 0; k < factorOrder.size(); ++k) - { - UTIL_THROW_IF(factorOrder[k] >= MAX_NUM_FACTORS, util::Exception, - "Factor order out of bounds."); - m_factorArray[factorOrder[k]] = factorCollection.AddFactor(bits[k], isNonTerminal); - } + if (factorDelimiter.size()) { + util::TokenIter<util::MultiCharacter> fit(str, factorDelimiter); + size_t i = 0; + for (; i < MAX_NUM_FACTORS && fit; ++i,++fit) + bits[i] = *fit; + if (i == MAX_NUM_FACTORS) + UTIL_THROW_IF(fit, StrayFactorException, + "The hard limit for factors is " << MAX_NUM_FACTORS + << ". The word " << str << " contains factor delimiter " + << StaticData::Instance().GetFactorDelimiter() + << " too many times."); + if (strict) + UTIL_THROW_IF(fit, StrayFactorException, + "You have configured " << factorOrder.size() + << " factors but the word " << str + << " contains factor delimiter " + << StaticData::Instance().GetFactorDelimiter() + << " too many times."); + UTIL_THROW_IF(!isNonTerminal && i < factorOrder.size(),util::Exception, + "Too few factors in string '" << str << "'."); + } else { + bits[0] = str; + } + for (size_t k = 0; k < factorOrder.size(); ++k) { + UTIL_THROW_IF(factorOrder[k] >= MAX_NUM_FACTORS, util::Exception, + "Factor order out of bounds."); + m_factorArray[factorOrder[k]] = factorCollection.AddFactor(bits[k], isNonTerminal); + } // assume term/non-term same for all factors m_isNonTerminal = isNonTerminal; } @@ -188,10 +184,10 @@ void Word::OnlyTheseFactors(const FactorMask &factors) bool Word::IsEpsilon() const { - const Factor *factor = m_factorArray[0]; - int compare = factor->GetString().compare(EPSILON); + const Factor *factor = m_factorArray[0]; + int compare = factor->GetString().compare(EPSILON); - return compare == 0; + return compare == 0; } TO_STRING_BODY(Word); |