diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2015-02-19 15:27:23 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2015-02-19 15:27:23 +0300 |
commit | 32de07502217879f0d354ec810c8e669f4d45d3c (patch) | |
tree | fafdf8f63d9902e4fd2b45f05902faa5d65df996 /moses/TranslationOptionList.cpp | |
parent | 6d4bad0f78ede5bcf7eaaea1de584f42bce8e91f (diff) |
beautify
Diffstat (limited to 'moses/TranslationOptionList.cpp')
-rw-r--r-- | moses/TranslationOptionList.cpp | 135 |
1 files changed, 66 insertions, 69 deletions
diff --git a/moses/TranslationOptionList.cpp b/moses/TranslationOptionList.cpp index 4e6449b5b..6e2065d0f 100644 --- a/moses/TranslationOptionList.cpp +++ b/moses/TranslationOptionList.cpp @@ -8,83 +8,80 @@ using namespace std; namespace Moses { - TranslationOptionList:: - TranslationOptionList(const TranslationOptionList ©) - { - const_iterator iter; - for (iter = copy.begin(); iter != copy.end(); ++iter) { - const TranslationOption &origTransOpt = **iter; - TranslationOption *newTransOpt = new TranslationOption(origTransOpt); - Add(newTransOpt); - } +TranslationOptionList:: +TranslationOptionList(const TranslationOptionList ©) +{ + const_iterator iter; + for (iter = copy.begin(); iter != copy.end(); ++iter) { + const TranslationOption &origTransOpt = **iter; + TranslationOption *newTransOpt = new TranslationOption(origTransOpt); + Add(newTransOpt); } +} - TranslationOptionList:: - ~TranslationOptionList() - { - RemoveAllInColl(m_coll); - } +TranslationOptionList:: +~TranslationOptionList() +{ + RemoveAllInColl(m_coll); +} - TO_STRING_BODY(TranslationOptionList); +TO_STRING_BODY(TranslationOptionList); - std::ostream& operator<<(std::ostream& out, const TranslationOptionList& coll) - { - TranslationOptionList::const_iterator iter; - for (iter = coll.begin(); iter != coll.end(); ++iter) { - const TranslationOption &transOpt = **iter; - out << transOpt << endl; - } - - return out; +std::ostream& operator<<(std::ostream& out, const TranslationOptionList& coll) +{ + TranslationOptionList::const_iterator iter; + for (iter = coll.begin(); iter != coll.end(); ++iter) { + const TranslationOption &transOpt = **iter; + out << transOpt << endl; } - - size_t - TranslationOptionList:: - SelectNBest(size_t const N) - { - if (N == 0 || N >= m_coll.size()) return 0; - static TranslationOption::Better cmp; - NTH_ELEMENT4(m_coll.begin(), m_coll.begin() + N, m_coll.end(), cmp); - // delete the rest - for (size_t i = N ; i < m_coll.size() ; ++i) delete m_coll[i]; - size_t ret = m_coll.size() - N; - m_coll.resize(N); - return ret; + + return out; +} + +size_t +TranslationOptionList:: +SelectNBest(size_t const N) +{ + if (N == 0 || N >= m_coll.size()) return 0; + static TranslationOption::Better cmp; + NTH_ELEMENT4(m_coll.begin(), m_coll.begin() + N, m_coll.end(), cmp); + // delete the rest + for (size_t i = N ; i < m_coll.size() ; ++i) delete m_coll[i]; + size_t ret = m_coll.size() - N; + m_coll.resize(N); + return ret; +} + +size_t +TranslationOptionList:: +PruneByThreshold(float const th) +{ + if (m_coll.size() <= 1) return 0; + if (th == -std::numeric_limits<float>::infinity()) return 0; + + // first, find the best score + float bestScore = -std::numeric_limits<float>::infinity(); + BOOST_FOREACH(TranslationOption const* t, m_coll) { + if (t->GetFutureScore() > bestScore) + bestScore = t->GetFutureScore(); } - size_t - TranslationOptionList:: - PruneByThreshold(float const th) - { - if (m_coll.size() <= 1) return 0; - if (th == -std::numeric_limits<float>::infinity()) return 0; - - // first, find the best score - float bestScore = -std::numeric_limits<float>::infinity(); - BOOST_FOREACH(TranslationOption const* t, m_coll) - { - if (t->GetFutureScore() > bestScore) - bestScore = t->GetFutureScore(); - } - - size_t old_size = m_coll.size(); - - // then, remove items that are worse than best score + threshold - // why '+' th ??? Does this ever hold? - for (size_t i=0; i < m_coll.size() ; ++i) - { - if (m_coll[i]->GetFutureScore() < bestScore + th) - { - delete m_coll[i]; - if(i + 1 < m_coll.size()) - std::swap(m_coll[i],m_coll.back()); - m_coll.pop_back(); - } - } - - m_coll.resize(m_coll.size()); - return old_size - m_coll.size(); + size_t old_size = m_coll.size(); + + // then, remove items that are worse than best score + threshold + // why '+' th ??? Does this ever hold? + for (size_t i=0; i < m_coll.size() ; ++i) { + if (m_coll[i]->GetFutureScore() < bestScore + th) { + delete m_coll[i]; + if(i + 1 < m_coll.size()) + std::swap(m_coll[i],m_coll.back()); + m_coll.pop_back(); + } } + m_coll.resize(m_coll.size()); + return old_size - m_coll.size(); +} + } // namespace |