mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 13:23:25 +03:00
daily automatic beautifier
This commit is contained in:
parent
aec2d51ce5
commit
adbb1c897a
@ -428,7 +428,7 @@ inline float CalcTranslationScore(const std::vector<float> &probVector,
|
||||
out << *this; \
|
||||
return out.str(); \
|
||||
} \
|
||||
|
||||
|
||||
//! delete and remove every element of a collection object such as set, list etc
|
||||
template<class COLL>
|
||||
void RemoveAllInColl(COLL &coll)
|
||||
|
@ -19,110 +19,108 @@ namespace Moses2
|
||||
|
||||
ArcLists::ArcLists()
|
||||
{
|
||||
// TODO Auto-generated constructor stub
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
ArcLists::~ArcLists()
|
||||
{
|
||||
BOOST_FOREACH(const Coll::value_type &collPair, m_coll){
|
||||
const ArcList *arcList = collPair.second;
|
||||
delete arcList;
|
||||
}
|
||||
BOOST_FOREACH(const Coll::value_type &collPair, m_coll) {
|
||||
const ArcList *arcList = collPair.second;
|
||||
delete arcList;
|
||||
}
|
||||
}
|
||||
|
||||
void ArcLists::AddArc(bool added, const HypothesisBase *currHypo,
|
||||
const HypothesisBase *otherHypo)
|
||||
const HypothesisBase *otherHypo)
|
||||
{
|
||||
//cerr << added << " " << currHypo << " " << otherHypo << endl;
|
||||
ArcList *arcList;
|
||||
if (added) {
|
||||
// we're winners!
|
||||
if (otherHypo) {
|
||||
// there was a existing losing hypo
|
||||
arcList = &GetAndDetachArcList(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 = &GetArcList(otherHypo);
|
||||
}
|
||||
//cerr << added << " " << currHypo << " " << otherHypo << endl;
|
||||
ArcList *arcList;
|
||||
if (added) {
|
||||
// we're winners!
|
||||
if (otherHypo) {
|
||||
// there was a existing losing hypo
|
||||
arcList = &GetAndDetachArcList(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 = &GetArcList(otherHypo);
|
||||
}
|
||||
|
||||
// in any case, add the curr hypo
|
||||
arcList->push_back(currHypo);
|
||||
// in any case, add the curr hypo
|
||||
arcList->push_back(currHypo);
|
||||
}
|
||||
|
||||
ArcList &ArcLists::GetArcList(const HypothesisBase *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;
|
||||
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;
|
||||
}
|
||||
|
||||
const ArcList &ArcLists::GetArcList(const HypothesisBase *hypo) const
|
||||
{
|
||||
Coll::const_iterator iter = m_coll.find(hypo);
|
||||
Coll::const_iterator iter = m_coll.find(hypo);
|
||||
|
||||
if (iter == m_coll.end()) {
|
||||
cerr << "looking for:" << hypo << " have " << m_coll.size() << " :";
|
||||
BOOST_FOREACH(const Coll::value_type &collPair, m_coll){
|
||||
const HypothesisBase *hypo = collPair.first;
|
||||
cerr << hypo << " ";
|
||||
}
|
||||
}
|
||||
if (iter == m_coll.end()) {
|
||||
cerr << "looking for:" << hypo << " have " << m_coll.size() << " :";
|
||||
BOOST_FOREACH(const Coll::value_type &collPair, m_coll) {
|
||||
const HypothesisBase *hypo = collPair.first;
|
||||
cerr << hypo << " ";
|
||||
}
|
||||
}
|
||||
|
||||
UTIL_THROW_IF2(iter == m_coll.end(), "Can't find arc list for " << hypo);
|
||||
ArcList &arcList = *iter->second;
|
||||
return arcList;
|
||||
UTIL_THROW_IF2(iter == m_coll.end(), "Can't find arc list for " << hypo);
|
||||
ArcList &arcList = *iter->second;
|
||||
return arcList;
|
||||
}
|
||||
|
||||
ArcList &ArcLists::GetAndDetachArcList(const HypothesisBase *hypo)
|
||||
{
|
||||
Coll::iterator iter = m_coll.find(hypo);
|
||||
UTIL_THROW_IF2(iter == m_coll.end(), "Can't find arc list");
|
||||
ArcList &arcList = *iter->second;
|
||||
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);
|
||||
m_coll.erase(iter);
|
||||
|
||||
return arcList;
|
||||
return arcList;
|
||||
}
|
||||
|
||||
void ArcLists::Sort()
|
||||
{
|
||||
BOOST_FOREACH(Coll::value_type &collPair, m_coll){
|
||||
ArcList &list = *collPair.second;
|
||||
std::sort(list.begin(), list.end(), HypothesisFutureScoreOrderer() );
|
||||
}
|
||||
BOOST_FOREACH(Coll::value_type &collPair, m_coll) {
|
||||
ArcList &list = *collPair.second;
|
||||
std::sort(list.begin(), list.end(), HypothesisFutureScoreOrderer() );
|
||||
}
|
||||
}
|
||||
|
||||
void ArcLists::Delete(const HypothesisBase *hypo)
|
||||
{
|
||||
//cerr << "hypo=" << hypo->Debug() << endl;
|
||||
//cerr << "m_coll=" << m_coll.size() << endl;
|
||||
Coll::iterator iter = m_coll.find(hypo);
|
||||
UTIL_THROW_IF2(iter == m_coll.end(), "Can't find arc list");
|
||||
ArcList *arcList = iter->second;
|
||||
//cerr << "hypo=" << hypo->Debug() << endl;
|
||||
//cerr << "m_coll=" << m_coll.size() << endl;
|
||||
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);
|
||||
delete arcList;
|
||||
m_coll.erase(iter);
|
||||
delete arcList;
|
||||
}
|
||||
|
||||
std::string ArcLists::Debug(const System &system) const
|
||||
{
|
||||
stringstream strm;
|
||||
BOOST_FOREACH(const Coll::value_type &collPair, m_coll){
|
||||
const ArcList *arcList = collPair.second;
|
||||
strm << arcList << "(" << arcList->size() << ") ";
|
||||
}
|
||||
return strm.str();
|
||||
stringstream strm;
|
||||
BOOST_FOREACH(const Coll::value_type &collPair, m_coll) {
|
||||
const ArcList *arcList = collPair.second;
|
||||
strm << arcList << "(" << arcList->size() << ") ";
|
||||
}
|
||||
return strm.str();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public:
|
||||
virtual ~ArcLists();
|
||||
|
||||
void AddArc(bool added, const HypothesisBase *currHypo,
|
||||
const HypothesisBase *otherHypo);
|
||||
const HypothesisBase *otherHypo);
|
||||
void Sort();
|
||||
void Delete(const HypothesisBase *hypo);
|
||||
|
||||
|
@ -13,26 +13,21 @@ public:
|
||||
typedef T* iterator;
|
||||
typedef const T* const_iterator;
|
||||
//! iterators
|
||||
const_iterator begin() const
|
||||
{
|
||||
const_iterator begin() const {
|
||||
return m_arr;
|
||||
}
|
||||
const_iterator end() const
|
||||
{
|
||||
const_iterator end() const {
|
||||
return m_arr + m_size;
|
||||
}
|
||||
|
||||
iterator begin()
|
||||
{
|
||||
iterator begin() {
|
||||
return m_arr;
|
||||
}
|
||||
iterator end()
|
||||
{
|
||||
iterator end() {
|
||||
return m_arr + m_size;
|
||||
}
|
||||
|
||||
Array(MemPool &pool, size_t size = 0, const T &val = T())
|
||||
{
|
||||
Array(MemPool &pool, size_t size = 0, const T &val = T()) {
|
||||
m_size = size;
|
||||
m_maxSize = size;
|
||||
m_arr = pool.Allocate<T>(size);
|
||||
@ -41,26 +36,23 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
size_t size() const
|
||||
{
|
||||
size_t size() const {
|
||||
return m_size;
|
||||
}
|
||||
|
||||
const T& operator[](size_t ind) const
|
||||
{
|
||||
const T& operator[](size_t ind) const {
|
||||
return m_arr[ind];
|
||||
}
|
||||
|
||||
T& operator[](size_t ind)
|
||||
{
|
||||
T& operator[](size_t ind) {
|
||||
return m_arr[ind];
|
||||
}
|
||||
|
||||
T *GetArray()
|
||||
{ return m_arr; }
|
||||
T *GetArray() {
|
||||
return m_arr;
|
||||
}
|
||||
|
||||
size_t hash() const
|
||||
{
|
||||
size_t hash() const {
|
||||
size_t seed = 0;
|
||||
for (size_t i = 0; i < m_size; ++i) {
|
||||
boost::hash_combine(seed, m_arr[i]);
|
||||
@ -68,21 +60,18 @@ public:
|
||||
return seed;
|
||||
}
|
||||
|
||||
int Compare(const Array &compare) const
|
||||
{
|
||||
int Compare(const Array &compare) const {
|
||||
|
||||
int cmp = memcmp(m_arr, compare.m_arr, sizeof(T) * m_size);
|
||||
return cmp;
|
||||
}
|
||||
|
||||
bool operator==(const Array &compare) const
|
||||
{
|
||||
bool operator==(const Array &compare) const {
|
||||
int cmp = Compare(compare);
|
||||
return cmp == 0;
|
||||
}
|
||||
|
||||
void resize(size_t newSize)
|
||||
{
|
||||
void resize(size_t newSize) {
|
||||
assert(m_size < m_maxSize);
|
||||
m_size = newSize;
|
||||
}
|
||||
|
@ -99,8 +99,8 @@ float EstimatedScores::CalcEstimatedScore(Bitmap const &bitmap, size_t startPos,
|
||||
}
|
||||
// end of a gap?
|
||||
else if (startGap != notInGap
|
||||
&& (bitmap.GetValue(currPos) == true
|
||||
|| (startPos <= currPos && currPos <= endPos))) {
|
||||
&& (bitmap.GetValue(currPos) == true
|
||||
|| (startPos <= currPos && currPos <= endPos))) {
|
||||
estimatedScore += GetValue(startGap, currPos - 1);
|
||||
startGap = notInGap;
|
||||
}
|
||||
|
@ -36,8 +36,7 @@ class EstimatedScores: public Matrix<float>
|
||||
{
|
||||
public:
|
||||
EstimatedScores(MemPool &pool, size_t size) :
|
||||
Matrix<float>(pool, size, size)
|
||||
{
|
||||
Matrix<float>(pool, size, size) {
|
||||
}
|
||||
|
||||
~EstimatedScores(); // not implemented
|
||||
@ -45,8 +44,7 @@ public:
|
||||
float CalcEstimatedScore(Bitmap const&) const;
|
||||
float CalcEstimatedScore(Bitmap const&, size_t startPos, size_t endPos) const;
|
||||
|
||||
std::ostream &Debug(std::ostream &out, const System &system) const
|
||||
{
|
||||
std::ostream &Debug(std::ostream &out, const System &system) const {
|
||||
for (size_t endPos = 0; endPos < GetSize(); endPos++) {
|
||||
for (size_t startPos = 0; startPos < GetSize(); startPos++)
|
||||
out << GetValue(startPos, endPos) << " ";
|
||||
|
@ -16,36 +16,30 @@ using namespace std;
|
||||
namespace Moses2
|
||||
{
|
||||
|
||||
struct DistortionState_traditional: public FFState
|
||||
{
|
||||
struct DistortionState_traditional: public FFState {
|
||||
Range range;
|
||||
int first_gap;
|
||||
|
||||
DistortionState_traditional() :
|
||||
range()
|
||||
{
|
||||
range() {
|
||||
// uninitialised
|
||||
}
|
||||
|
||||
void Set(const Range& wr, int fg)
|
||||
{
|
||||
void Set(const Range& wr, int fg) {
|
||||
range = wr;
|
||||
first_gap = fg;
|
||||
}
|
||||
|
||||
size_t hash() const
|
||||
{
|
||||
size_t hash() const {
|
||||
return range.GetEndPos();
|
||||
}
|
||||
virtual bool operator==(const FFState& other) const
|
||||
{
|
||||
virtual bool operator==(const FFState& other) const {
|
||||
const DistortionState_traditional& o =
|
||||
static_cast<const DistortionState_traditional&>(other);
|
||||
static_cast<const DistortionState_traditional&>(other);
|
||||
return range.GetEndPos() == o.range.GetEndPos();
|
||||
}
|
||||
|
||||
virtual std::string ToString() const
|
||||
{
|
||||
virtual std::string ToString() const {
|
||||
stringstream sb;
|
||||
sb << first_gap << " " << range;
|
||||
return sb.str();
|
||||
@ -55,7 +49,7 @@ struct DistortionState_traditional: public FFState
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
Distortion::Distortion(size_t startInd, const std::string &line) :
|
||||
StatefulFeatureFunction(startInd, line)
|
||||
StatefulFeatureFunction(startInd, line)
|
||||
{
|
||||
ReadParameters();
|
||||
}
|
||||
@ -71,10 +65,10 @@ FFState* Distortion::BlankState(MemPool &pool, const System &sys) const
|
||||
}
|
||||
|
||||
void Distortion::EmptyHypothesisState(FFState &state, const ManagerBase &mgr,
|
||||
const InputType &input, const Hypothesis &hypo) const
|
||||
const InputType &input, const Hypothesis &hypo) const
|
||||
{
|
||||
DistortionState_traditional &stateCast =
|
||||
static_cast<DistortionState_traditional&>(state);
|
||||
static_cast<DistortionState_traditional&>(state);
|
||||
|
||||
// fake previous translated phrase start and end
|
||||
size_t start = NOT_FOUND;
|
||||
@ -92,31 +86,31 @@ void Distortion::EmptyHypothesisState(FFState &state, const ManagerBase &mgr,
|
||||
}
|
||||
|
||||
void Distortion::EvaluateInIsolation(MemPool &pool, const System &system,
|
||||
const Phrase<Moses2::Word> &source, const TargetPhraseImpl &targetPhrase, Scores &scores,
|
||||
SCORE &estimatedScore) const
|
||||
const Phrase<Moses2::Word> &source, const TargetPhraseImpl &targetPhrase, Scores &scores,
|
||||
SCORE &estimatedScore) const
|
||||
{
|
||||
}
|
||||
|
||||
void Distortion::EvaluateInIsolation(MemPool &pool, const System &system, const Phrase<SCFG::Word> &source,
|
||||
const TargetPhrase<SCFG::Word> &targetPhrase, Scores &scores,
|
||||
SCORE &estimatedScore) const
|
||||
const TargetPhrase<SCFG::Word> &targetPhrase, Scores &scores,
|
||||
SCORE &estimatedScore) const
|
||||
{
|
||||
}
|
||||
|
||||
void Distortion::EvaluateWhenApplied(const ManagerBase &mgr,
|
||||
const Hypothesis &hypo, const FFState &prevState, Scores &scores,
|
||||
FFState &state) const
|
||||
const Hypothesis &hypo, const FFState &prevState, Scores &scores,
|
||||
FFState &state) const
|
||||
{
|
||||
const DistortionState_traditional &prev =
|
||||
static_cast<const DistortionState_traditional&>(prevState);
|
||||
static_cast<const DistortionState_traditional&>(prevState);
|
||||
SCORE distortionScore = CalculateDistortionScore(prev.range,
|
||||
hypo.GetInputPath().range, prev.first_gap);
|
||||
hypo.GetInputPath().range, prev.first_gap);
|
||||
//cerr << "distortionScore=" << distortionScore << endl;
|
||||
|
||||
scores.PlusEquals(mgr.system, *this, distortionScore);
|
||||
|
||||
DistortionState_traditional &stateCast =
|
||||
static_cast<DistortionState_traditional&>(state);
|
||||
static_cast<DistortionState_traditional&>(state);
|
||||
stateCast.Set(hypo.GetInputPath().range, hypo.GetBitmap().GetFirstGapPos());
|
||||
|
||||
//cerr << "hypo=" << hypo.Debug(mgr.system) << endl;
|
||||
@ -128,8 +122,7 @@ SCORE Distortion::CalculateDistortionScore(const Range &prev, const Range &curr,
|
||||
bool useEarlyDistortionCost = false;
|
||||
if (!useEarlyDistortionCost) {
|
||||
return -(SCORE) ComputeDistortionDistance(prev, curr);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* Pay distortion score as soon as possible, from Moore and Quirk MT Summit 2007
|
||||
Definitions:
|
||||
S : current source range
|
||||
@ -162,7 +155,7 @@ SCORE Distortion::CalculateDistortionScore(const Range &prev, const Range &curr,
|
||||
// case4: otherwise => return 2(nbWordBetween(S,S')+length(S))
|
||||
//IFVERBOSE(4) std::cerr<< "MQ07disto:case4" << std::endl;
|
||||
return (float) -2
|
||||
* ((int) curr.GetNumWordsBetween(prev) + (int) curr.GetNumWordsCovered());
|
||||
* ((int) curr.GetNumWordsBetween(prev) + (int) curr.GetNumWordsCovered());
|
||||
|
||||
}
|
||||
}
|
||||
@ -173,16 +166,15 @@ int Distortion::ComputeDistortionDistance(const Range& prev,
|
||||
int dist = 0;
|
||||
if (prev.GetNumWordsCovered() == 0) {
|
||||
dist = current.GetStartPos();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
dist = (int) prev.GetEndPos() - (int) current.GetStartPos() + 1;
|
||||
}
|
||||
return abs(dist);
|
||||
}
|
||||
|
||||
void Distortion::EvaluateWhenApplied(const SCFG::Manager &mgr,
|
||||
const SCFG::Hypothesis &hypo, int featureID, Scores &scores,
|
||||
FFState &state) const
|
||||
const SCFG::Hypothesis &hypo, int featureID, Scores &scores,
|
||||
FFState &state) const
|
||||
{
|
||||
UTIL_THROW2("Not implemented");
|
||||
}
|
||||
|
@ -23,33 +23,32 @@ public:
|
||||
|
||||
virtual FFState* BlankState(MemPool &pool, const System &sys) const;
|
||||
virtual void EmptyHypothesisState(FFState &state, const ManagerBase &mgr,
|
||||
const InputType &input, const Hypothesis &hypo) const;
|
||||
const InputType &input, const Hypothesis &hypo) const;
|
||||
|
||||
virtual void
|
||||
EvaluateInIsolation(MemPool &pool, const System &system, const Phrase<Moses2::Word> &source,
|
||||
const TargetPhraseImpl &targetPhrase, Scores &scores,
|
||||
SCORE &estimatedScore) const;
|
||||
const TargetPhraseImpl &targetPhrase, Scores &scores,
|
||||
SCORE &estimatedScore) const;
|
||||
|
||||
virtual void
|
||||
EvaluateInIsolation(MemPool &pool, const System &system, const Phrase<SCFG::Word> &source,
|
||||
const TargetPhrase<SCFG::Word> &targetPhrase, Scores &scores,
|
||||
SCORE &estimatedScore) const;
|
||||
const TargetPhrase<SCFG::Word> &targetPhrase, Scores &scores,
|
||||
SCORE &estimatedScore) const;
|
||||
|
||||
virtual void EvaluateWhenApplied(const std::deque<Hypothesis*> &hypos) const
|
||||
{
|
||||
virtual void EvaluateWhenApplied(const std::deque<Hypothesis*> &hypos) const {
|
||||
}
|
||||
|
||||
virtual void EvaluateWhenApplied(const ManagerBase &mgr,
|
||||
const Hypothesis &hypo, const FFState &prevState, Scores &scores,
|
||||
FFState &state) const;
|
||||
const Hypothesis &hypo, const FFState &prevState, Scores &scores,
|
||||
FFState &state) const;
|
||||
|
||||
virtual void EvaluateWhenApplied(const SCFG::Manager &mgr,
|
||||
const SCFG::Hypothesis &hypo, int featureID, Scores &scores,
|
||||
FFState &state) const;
|
||||
const SCFG::Hypothesis &hypo, int featureID, Scores &scores,
|
||||
FFState &state) const;
|
||||
|
||||
protected:
|
||||
SCORE CalculateDistortionScore(const Range &prev, const Range &curr,
|
||||
const int FirstGap) const;
|
||||
const int FirstGap) const;
|
||||
|
||||
int ComputeDistortionDistance(const Range& prev, const Range& current) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user