2008-06-11 14:52:57 +04:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2006 University of Edinburgh
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
***********************************************************************/
|
|
|
|
|
2010-02-24 14:15:44 +03:00
|
|
|
#ifndef moses_TrellisPath_h
|
|
|
|
#define moses_TrellisPath_h
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
#include <limits>
|
|
|
|
#include "Hypothesis.h"
|
|
|
|
#include "TypeDef.h"
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
class TrellisPathCollection;
|
2010-03-07 10:57:48 +03:00
|
|
|
class TrellisPathList;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
/** Encapsulate the set of hypotheses/arcs that goes from decoding 1 phrase to all the source phrases
|
2011-02-24 16:14:42 +03:00
|
|
|
* to reach a final translation. For the best translation, this consist of all hypotheses, for the other
|
2012-06-29 02:29:46 +04:00
|
|
|
* n-best paths, the node on the path can consist of hypotheses or arcs.
|
|
|
|
* Used by phrase-based decoding
|
2008-06-11 14:52:57 +04:00
|
|
|
*/
|
|
|
|
class TrellisPath
|
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
friend std::ostream& operator<<(std::ostream&, const TrellisPath&);
|
2011-10-04 19:46:24 +04:00
|
|
|
friend class Manager;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
protected:
|
2011-02-24 16:14:42 +03:00
|
|
|
std::vector<const Hypothesis *> m_path; //< list of hypotheses/arcs
|
|
|
|
size_t m_prevEdgeChanged; /**< the last node that was wiggled to create this path
|
2008-06-11 14:52:57 +04:00
|
|
|
, or NOT_FOUND if this path is the best trans so consist of only hypos
|
|
|
|
*/
|
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
ScoreComponentCollection m_scoreBreakdown;
|
|
|
|
float m_totalScore;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2011-10-04 19:46:24 +04:00
|
|
|
//Used by Manager::LatticeSample()
|
|
|
|
TrellisPath(const std::vector<const Hypothesis*> edges);
|
|
|
|
|
|
|
|
void InitScore();
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
public:
|
2013-05-29 21:16:15 +04:00
|
|
|
TrellisPath(); // not implemented
|
|
|
|
|
|
|
|
//! create path OF pure hypo
|
|
|
|
TrellisPath(const Hypothesis *hypo);
|
|
|
|
|
|
|
|
/** create path from another path, deviate at edgeIndex by using arc instead,
|
|
|
|
* which may change other hypo back from there
|
|
|
|
*/
|
|
|
|
TrellisPath(const TrellisPath ©, size_t edgeIndex, const Hypothesis *arc);
|
|
|
|
|
|
|
|
//! get score for this path throught trellis
|
|
|
|
inline float GetTotalScore() const {
|
|
|
|
return m_totalScore;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** list of each hypo/arcs in path. For anything other than the best hypo, it is not possible just to follow the
|
|
|
|
* m_prevHypo variable in the hypothesis object
|
|
|
|
*/
|
|
|
|
inline const std::vector<const Hypothesis *> &GetEdges() const {
|
|
|
|
return m_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline size_t GetSize() const {
|
|
|
|
return m_path.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
//! create a set of next best paths by wiggling 1 of the node at a time.
|
|
|
|
void CreateDeviantPaths(TrellisPathCollection &pathColl) const;
|
|
|
|
|
|
|
|
//! create a list of next best paths by wiggling 1 of the node at a time.
|
2010-03-07 10:57:48 +03:00
|
|
|
void CreateDeviantPaths(TrellisPathList &pathColl) const;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
inline const ScoreComponentCollection &GetScoreBreakdown() const {
|
|
|
|
return m_scoreBreakdown;
|
|
|
|
}
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
//! get target words range of the hypo within n-best trellis. not necessarily the same as hypo.GetCurrTargetWordsRange()
|
|
|
|
WordsRange GetTargetWordsRange(const Hypothesis &hypo) const;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
Phrase GetTargetPhrase() const;
|
|
|
|
Phrase GetSurfacePhrase() const;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
TO_STRING();
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// friend
|
|
|
|
inline std::ostream& operator<<(std::ostream& out, const TrellisPath& path)
|
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
const size_t sizePath = path.m_path.size();
|
|
|
|
for (int pos = (int) sizePath - 1 ; pos >= 0 ; pos--) {
|
|
|
|
const Hypothesis *edge = path.m_path[pos];
|
|
|
|
const WordsRange &sourceRange = edge->GetCurrSourceWordsRange();
|
|
|
|
out << edge->GetId() << " " << sourceRange.GetStartPos() << "-" << sourceRange.GetEndPos() << ", ";
|
|
|
|
}
|
|
|
|
// scores
|
|
|
|
out << " total=" << path.GetTotalScore()
|
|
|
|
<< " " << path.GetScoreBreakdown()
|
|
|
|
<< std::endl;
|
|
|
|
|
|
|
|
return out;
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
2008-10-09 03:51:26 +04:00
|
|
|
|
|
|
|
}
|
2010-02-24 14:15:44 +03:00
|
|
|
#endif
|