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

55 lines
1.0 KiB
C++
Raw Normal View History

2016-04-17 21:33:21 +03:00
#include <boost/foreach.hpp>
2016-02-29 18:51:17 +03:00
#include "Stacks.h"
2016-04-17 11:47:04 +03:00
#include "Hypothesis.h"
#include "TargetPhraseImpl.h"
#include "Manager.h"
2016-02-29 18:51:17 +03:00
namespace Moses2
{
namespace SCFG
{
2016-04-17 11:47:04 +03:00
Stack::Stack(const Manager &mgr)
:m_mgr(mgr)
{
}
2016-04-18 07:55:13 +03:00
StackAdd Stack::Add(SCFG::Hypothesis *hypo, Recycler<HypothesisBase*> &hypoRecycle,
2016-04-17 11:47:04 +03:00
ArcLists &arcLists)
{
const SCFG::TargetPhraseImpl &tp = hypo->GetTargetPhrase();
const SCFG::Word &lhs = tp.lhs;
HypothesisColl &coll = GetMiniStack(lhs);
StackAdd added = coll.Add(hypo);
2016-04-18 07:55:13 +03:00
return added;
2016-04-17 11:47:04 +03:00
}
Moses2::HypothesisColl &Stack::GetMiniStack(const SCFG::Word &key)
{
Moses2::HypothesisColl *ret;
Coll::iterator iter;
iter = m_coll.find(key);
if (iter == m_coll.end()) {
ret = new Moses2::HypothesisColl(m_mgr);
m_coll[key] = ret;
}
else {
ret = iter->second;
}
return *ret;
}
2016-04-17 21:33:21 +03:00
size_t Stack::GetSize() const
{
size_t ret = 0;
BOOST_FOREACH (const Coll::value_type &valPair, m_coll) {
Moses2::HypothesisColl &hypos = *valPair.second;
ret += hypos.GetSize();
}
return ret;
}
2016-02-29 18:51:17 +03:00
}
}