mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-10-27 11:59:52 +03:00
parent
2abc631251
commit
32b9efd775
@ -35,8 +35,8 @@ HypothesisBase::HypothesisBase(MemPool &pool, const System &system)
|
||||
m_ffStates = (FFState **) pool.Allocate(sizeof(FFState*) * numStatefulFFs);
|
||||
|
||||
BOOST_FOREACH(const StatefulFeatureFunction *sfff, sfffs){
|
||||
size_t statefulInd = sfff->GetStatefulInd();
|
||||
FFState *state = sfff->BlankState(pool, system);
|
||||
size_t statefulInd = sfff->GetStatefulInd();
|
||||
FFState *state = sfff->BlankState(pool, system);
|
||||
m_ffStates[statefulInd] = state;
|
||||
}
|
||||
}
|
||||
|
@ -33,10 +33,6 @@ public:
|
||||
const T &Cast() const
|
||||
{ return static_cast<const T&>(*this); }
|
||||
|
||||
template<typename T>
|
||||
T &Cast()
|
||||
{ return static_cast<T&>(*this); }
|
||||
|
||||
const Scores &GetScores() const
|
||||
{ return *m_scores; }
|
||||
Scores &GetScores()
|
||||
|
@ -79,7 +79,7 @@ void Search::Decode(size_t stackInd)
|
||||
|
||||
BOOST_FOREACH(const InputPathBase *path, paths){
|
||||
BOOST_FOREACH(const HypothesisBase *hypo, hypos) {
|
||||
Extend(hypo->Cast<Hypothesis>(), *static_cast<const InputPath*>(path));
|
||||
Extend(*static_cast<const Hypothesis*>(hypo), *static_cast<const InputPath*>(path));
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ const Hypothesis *Search::GetBestHypothesis() const
|
||||
|
||||
const Hypothesis *best = NULL;
|
||||
if (sortedHypos.size()) {
|
||||
best = &sortedHypos[0]->Cast<Hypothesis>();
|
||||
best = static_cast<const Hypothesis*>(sortedHypos[0]);
|
||||
}
|
||||
return best;
|
||||
}
|
||||
@ -165,8 +165,8 @@ void Search::AddInitialTrellisPaths(TrellisPaths<TrellisPath> &paths) const
|
||||
{
|
||||
const Stack &lastStack = m_stacks.Back();
|
||||
BOOST_FOREACH(const HypothesisBase *hypoBase, lastStack){
|
||||
const Hypothesis &hypo = hypoBase->Cast<Hypothesis>();
|
||||
TrellisPath *path = new TrellisPath(&hypo, mgr.arcLists);
|
||||
const Hypothesis *hypo = static_cast<const Hypothesis*>(hypoBase);
|
||||
TrellisPath *path = new TrellisPath(hypo, mgr.arcLists);
|
||||
paths.Add(path);
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,8 @@ void QueueItem::Init(Manager &mgr, CubeEdge &edge, size_t hypoIndex,
|
||||
|
||||
void QueueItem::CreateHypothesis(Manager &mgr)
|
||||
{
|
||||
const Hypothesis &prevHypo = edge->hypos[hypoIndex]->Cast<Hypothesis>();
|
||||
const Hypothesis *prevHypo =
|
||||
static_cast<const Hypothesis*>(edge->hypos[hypoIndex]);
|
||||
const TargetPhraseImpl &tp = edge->tps[tpIndex];
|
||||
|
||||
//cerr << "hypoIndex=" << hypoIndex << endl;
|
||||
@ -74,7 +75,7 @@ void QueueItem::CreateHypothesis(Manager &mgr)
|
||||
//cerr << *prevHypo << endl;
|
||||
|
||||
hypo = Hypothesis::Create(mgr.GetSystemPool(), mgr);
|
||||
hypo->Init(mgr, prevHypo, edge->path, tp, edge->newBitmap,
|
||||
hypo->Init(mgr, *prevHypo, edge->path, tp, edge->newBitmap,
|
||||
edge->estimatedScore);
|
||||
|
||||
if (!mgr.system.options.cube.lazy_scoring) {
|
||||
|
@ -236,8 +236,8 @@ void Search::AddInitialTrellisPaths(TrellisPaths<TrellisPath> &paths) const
|
||||
BOOST_FOREACH(const Stack::Coll::value_type &val, coll){
|
||||
const Moses2::HypothesisColl &hypos = *val.second;
|
||||
BOOST_FOREACH(const HypothesisBase *hypoBase, hypos) {
|
||||
const Hypothesis &hypo = hypoBase->Cast<Hypothesis>();
|
||||
TrellisPath *path = new TrellisPath(&hypo, mgr.arcLists);
|
||||
const Hypothesis *hypo = static_cast<const Hypothesis*>(hypoBase);
|
||||
TrellisPath *path = new TrellisPath(hypo, mgr.arcLists);
|
||||
paths.Add(path);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ std::vector<const Hypothesis*> Stack::GetBestHypos(size_t num) const
|
||||
|
||||
ret.reserve(ret.size() + hypos.size());
|
||||
BOOST_FOREACH(const HypothesisBase *hypo, hypos) {
|
||||
ret.push_back(&hypo->Cast<Hypothesis>());
|
||||
ret.push_back(static_cast<const Hypothesis*>(hypo));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ Hypothesis *Hypothesis::Create(MemPool &pool, Manager &mgr)
|
||||
Hypothesis *ret;
|
||||
|
||||
Recycler<HypothesisBase*> &recycler = mgr.GetHypoRecycle();
|
||||
ret = &recycler.Get()->Cast<Hypothesis>();
|
||||
ret = static_cast<Hypothesis*>(recycler.Get());
|
||||
if (ret) {
|
||||
// got new hypo from recycler. Do nothing
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ void Search::Decode(size_t stackInd)
|
||||
|
||||
BOOST_FOREACH(const InputPathBase *path, paths){
|
||||
BOOST_FOREACH(const HypothesisBase *hypo, hypos) {
|
||||
Extend(hypo->Cast<Hypothesis>(), *static_cast<const InputPath*>(path));
|
||||
Extend(*static_cast<const Hypothesis*>(hypo), *static_cast<const InputPath*>(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -143,7 +143,7 @@ const Hypothesis *Search::GetBestHypothesis() const
|
||||
|
||||
const Hypothesis *best = NULL;
|
||||
if (sortedHypos.size()) {
|
||||
best = &sortedHypos[0]->Cast<Hypothesis>();
|
||||
best = static_cast<const Hypothesis*>(sortedHypos[0]);
|
||||
}
|
||||
return best;
|
||||
}
|
||||
@ -152,10 +152,10 @@ void Search::AddInitialTrellisPaths(TrellisPaths<TrellisPath> &paths) const
|
||||
{
|
||||
const Stack &lastStack = m_stacks.Back();
|
||||
BOOST_FOREACH(const HypothesisBase *hypoBase, lastStack){
|
||||
const Hypothesis &hypo = hypoBase->Cast<Hypothesis>();
|
||||
TrellisPath *path = new TrellisPath(&hypo, mgr.arcLists);
|
||||
paths.Add(path);
|
||||
}
|
||||
const Hypothesis *hypo = static_cast<const Hypothesis*>(hypoBase);
|
||||
TrellisPath *path = new TrellisPath(hypo, mgr.arcLists);
|
||||
paths.Add(path);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -46,9 +46,9 @@ TrellisPath::TrellisPath(const TrellisPath &origPath, size_t edgeIndex,
|
||||
nodes.push_back(newNode);
|
||||
|
||||
// rest of path comes from following best path backwards
|
||||
const Hypothesis &arc = newNode.GetHypo()->Cast<Hypothesis>();
|
||||
const Hypothesis *arc = static_cast<const Hypothesis*>(newNode.GetHypo());
|
||||
|
||||
const Hypothesis *prevHypo = arc.GetPrevHypo();
|
||||
const Hypothesis *prevHypo = arc->GetPrevHypo();
|
||||
while (prevHypo != NULL) {
|
||||
const ArcList &arcList = arcLists.GetArcList(prevHypo);
|
||||
assert(arcList);
|
||||
@ -108,9 +108,9 @@ std::string TrellisPath::OutputTargetPhrase(const System &system) const
|
||||
std::stringstream out;
|
||||
for (int i = nodes.size() - 1; i >= 0; --i) {
|
||||
const TrellisNode &node = nodes[i];
|
||||
const Hypothesis &hypo = node.GetHypo()->Cast<Hypothesis>();
|
||||
const Hypothesis *hypo = static_cast<const Hypothesis*>(node.GetHypo());
|
||||
//cerr << "hypo=" << hypo << " " << *hypo << endl;
|
||||
hypo.GetTargetPhrase().OutputToStream(out);
|
||||
hypo->GetTargetPhrase().OutputToStream(out);
|
||||
out << " ";
|
||||
}
|
||||
return out.str();
|
||||
|
@ -18,11 +18,11 @@ namespace SCFG
|
||||
Hypothesis *Hypothesis::Create(MemPool &pool, Manager &mgr)
|
||||
{
|
||||
// ++g_numHypos;
|
||||
SCFG::Hypothesis *ret;
|
||||
Hypothesis *ret;
|
||||
//ret = new (pool.Allocate<Hypothesis>()) Hypothesis(pool, mgr.system);
|
||||
|
||||
Recycler<HypothesisBase*> &recycler = mgr.GetHypoRecycle();
|
||||
ret = &recycler.Get()->Cast<SCFG::Hypothesis>();
|
||||
ret = static_cast<Hypothesis*>(recycler.Get());
|
||||
if (ret) {
|
||||
// got new hypo from recycler. Do nothing
|
||||
}
|
||||
@ -71,10 +71,10 @@ void Hypothesis::Init(SCFG::Manager &mgr,
|
||||
size_t prevHyposInd = prevHyposIndices[currInd];
|
||||
assert(prevHyposInd < sortedHypos.size());
|
||||
|
||||
const Hypothesis &prevHypo = sortedHypos[prevHyposInd]->Cast<SCFG::Hypothesis>();
|
||||
m_prevHypos[currInd] = &prevHypo;
|
||||
const Hypothesis *prevHypo = static_cast<const SCFG::Hypothesis*>(sortedHypos[prevHyposInd]);
|
||||
m_prevHypos[currInd] = prevHypo;
|
||||
|
||||
m_scores->PlusEquals(mgr.system, prevHypo.GetScores());
|
||||
m_scores->PlusEquals(mgr.system, prevHypo->GetScores());
|
||||
|
||||
++currInd;
|
||||
}
|
||||
|
@ -94,10 +94,10 @@ const Hypothesis *Stack::GetBestHypo(
|
||||
BOOST_FOREACH (const Coll::value_type &valPair, m_coll) {
|
||||
Moses2::HypothesisColl &hypos = *valPair.second;
|
||||
const Hypotheses &sortedHypos = hypos.GetSortedAndPruneHypos(mgr, arcLists);
|
||||
const Hypothesis &bestHypoColl = sortedHypos[0]->Cast<SCFG::Hypothesis>();
|
||||
const Hypothesis *bestHypoColl = static_cast<const Hypothesis*>(sortedHypos[0]);
|
||||
|
||||
if (ret == NULL || ret->GetFutureScore() < bestHypoColl.GetFutureScore()) {
|
||||
ret = &bestHypoColl;
|
||||
if (ret == NULL || ret->GetFutureScore() < bestHypoColl->GetFutureScore()) {
|
||||
ret = bestHypoColl;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user