mosesdecoder/contrib/other-builds/moses2/Stack.cpp

48 lines
1.0 KiB
C++
Raw Normal View History

2015-10-24 21:54:16 +03:00
/*
* Stack.cpp
*
* Created on: 24 Oct 2015
* Author: hieu
*/
#include "Stack.h"
2015-10-27 02:24:58 +03:00
#include "Hypothesis.h"
#include "Scores.h"
2015-10-24 21:54:16 +03:00
Stack::Stack() {
// TODO Auto-generated constructor stub
}
Stack::~Stack() {
// TODO Auto-generated destructor stub
}
2015-10-27 02:24:58 +03:00
StackAdd Stack::Add(const Hypothesis *hypo)
2015-10-24 21:54:16 +03:00
{
2015-10-27 02:24:58 +03:00
std::pair<iterator, bool> addRet = m_hypos.insert(hypo);
if (addRet.second) {
// equiv hypo doesn't exists
return StackAdd(true, NULL);
}
else {
const Hypothesis *hypoExisting = *addRet.first;
if (hypo->GetScores().GetTotalScore() > hypoExisting->GetScores().GetTotalScore()) {
// incoming hypo is better than the one we have
m_hypos.erase(addRet.first);
return StackAdd(true, hypoExisting);
}
else {
// already storing the best hypo. discard incoming hypo
return StackAdd(false, hypo);
}
}
2015-10-24 21:54:16 +03:00
}
2015-10-27 15:51:57 +03:00
std::vector<const Hypothesis*> Stack::GetSortedHypos() const
{
std::vector<const Hypothesis*> ret(m_hypos.begin(), m_hypos.end());
std::sort(ret.begin(), ret.end(), HypothesisScoreOrderer());
return ret;
}