mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-11-12 16:27:56 +03:00
start nbest list
This commit is contained in:
parent
8cc18061e4
commit
2f024d403f
67
contrib/other-builds/moses2/ArcLists.cpp
Normal file
67
contrib/other-builds/moses2/ArcLists.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* ArcList.cpp
|
||||
*
|
||||
* Created on: 26 Oct 2015
|
||||
* Author: hieu
|
||||
*/
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
#include "ArcLists.h"
|
||||
#include "util/exception.hh"
|
||||
|
||||
ArcLists::ArcLists() {
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
ArcLists::~ArcLists() {
|
||||
BOOST_FOREACH(const Coll::value_type &collPair, m_coll) {
|
||||
const ArcList *arcList = collPair.second;
|
||||
delete arcList;
|
||||
}
|
||||
}
|
||||
|
||||
void ArcLists::AddArc(bool added, const Hypothesis *currHypo,const Hypothesis *otherHypo)
|
||||
{
|
||||
if (added) {
|
||||
// we're winners!
|
||||
ArcList *arcList;
|
||||
if (otherHypo) {
|
||||
// there was a existing losing hypo
|
||||
arcList = GetAndDetachArcList(otherHypo);
|
||||
arcList->push_back(otherHypo);
|
||||
}
|
||||
else {
|
||||
// there was no existing hypo
|
||||
arcList = new ArcList;
|
||||
}
|
||||
m_coll[currHypo] = arcList;
|
||||
}
|
||||
else {
|
||||
// we're losers!
|
||||
// there should be a winner, we're not doing beam pruning
|
||||
UTIL_THROW_IF2(otherHypo == NULL, "There must have been a winning hypo");
|
||||
ArcList *arcList = GetArcList(otherHypo);
|
||||
arcList->push_back(currHypo);
|
||||
}
|
||||
}
|
||||
|
||||
ArcList *ArcLists::GetArcList(const Hypothesis *hypo)
|
||||
{
|
||||
Coll::iterator iter = m_coll.find(hypo);
|
||||
UTIL_THROW_IF2(iter == m_coll.end(), "Can't find arc list");
|
||||
ArcList *arcList = iter->second;
|
||||
return arcList;
|
||||
}
|
||||
|
||||
ArcList *ArcLists::GetAndDetachArcList(const Hypothesis *hypo)
|
||||
{
|
||||
Coll::iterator iter = m_coll.find(hypo);
|
||||
UTIL_THROW_IF2(iter == m_coll.end(), "Can't find arc list");
|
||||
ArcList *arcList = iter->second;
|
||||
|
||||
m_coll.erase(iter);
|
||||
|
||||
return arcList;
|
||||
}
|
||||
|
33
contrib/other-builds/moses2/ArcLists.h
Normal file
33
contrib/other-builds/moses2/ArcLists.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* ArcList.h
|
||||
*
|
||||
* Created on: 26 Oct 2015
|
||||
* Author: hieu
|
||||
*/
|
||||
|
||||
#ifndef ARCLISTS_H_
|
||||
#define ARCLISTS_H_
|
||||
#include <vector>
|
||||
#include <boost/unordered_map.hpp>
|
||||
|
||||
class Hypothesis;
|
||||
|
||||
typedef std::vector<const Hypothesis*> ArcList;
|
||||
|
||||
class ArcLists {
|
||||
public:
|
||||
ArcLists();
|
||||
virtual ~ArcLists();
|
||||
|
||||
void AddArc(bool added, const Hypothesis *currHypo,const Hypothesis *otherHypo);
|
||||
|
||||
protected:
|
||||
typedef boost::unordered_map<const Hypothesis*, ArcList*> Coll;
|
||||
Coll m_coll;
|
||||
|
||||
ArcList *GetArcList(const Hypothesis *hypo);
|
||||
ArcList *GetAndDetachArcList(const Hypothesis *hypo);
|
||||
|
||||
};
|
||||
|
||||
#endif /* ARCLISTS_H_ */
|
@ -5,6 +5,7 @@ import option ;
|
||||
import path ;
|
||||
|
||||
exe moses2 :
|
||||
ArcLists.cpp
|
||||
FeatureFunction.cpp
|
||||
Hypothesis.cpp
|
||||
InputPath.cpp
|
||||
|
@ -91,6 +91,8 @@ void SearchNormal::Extend(const Hypothesis &hypo,
|
||||
|
||||
size_t numWordsCovered = newBitmap.GetNumWordsCovered();
|
||||
StackAdd stackAdded = m_stacks[numWordsCovered].Add(newHypo);
|
||||
|
||||
m_arcLists.AddArc(stackAdded.added, newHypo, stackAdded.other);
|
||||
}
|
||||
|
||||
void SearchNormal::DebugStacks() const
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <vector>
|
||||
#include "moses/Range.h"
|
||||
#include "moses/Bitmap.h"
|
||||
#include "ArcLists.h"
|
||||
|
||||
class Manager;
|
||||
class Stack;
|
||||
@ -30,6 +31,7 @@ public:
|
||||
protected:
|
||||
Manager &m_mgr;
|
||||
std::vector<Stack> &m_stacks;
|
||||
ArcLists m_arcLists;
|
||||
|
||||
void Extend(const Hypothesis &hypo);
|
||||
void Extend(const Hypothesis &hypo, const InputPath &path);
|
||||
|
Loading…
Reference in New Issue
Block a user