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_TargetPhrase_h
|
|
|
|
#define moses_TargetPhrase_h
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
#include <vector>
|
2008-09-12 22:09:06 +04:00
|
|
|
#include "TypeDef.h"
|
2008-06-11 14:52:57 +04:00
|
|
|
#include "Phrase.h"
|
|
|
|
#include "ScoreComponentCollection.h"
|
2010-04-08 21:16:10 +04:00
|
|
|
#include "AlignmentInfo.h"
|
|
|
|
|
2011-10-14 20:40:30 +04:00
|
|
|
#include "util/string_piece.hh"
|
|
|
|
|
2008-09-24 20:48:23 +04:00
|
|
|
#ifdef HAVE_PROTOBUF
|
|
|
|
#include "rule.pb.h"
|
|
|
|
#endif
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
2013-02-22 00:03:35 +04:00
|
|
|
class FeatureFunction;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2008-09-12 22:09:06 +04:00
|
|
|
/** represents an entry on the target side of a phrase table (scores, translation, alignment)
|
2008-06-11 14:52:57 +04:00
|
|
|
*/
|
|
|
|
class TargetPhrase: public Phrase
|
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
friend std::ostream& operator<<(std::ostream&, const TargetPhrase&);
|
2008-06-11 14:52:57 +04:00
|
|
|
protected:
|
2011-06-24 22:29:50 +04:00
|
|
|
float m_fullScore;
|
2011-02-24 16:14:42 +03:00
|
|
|
ScoreComponentCollection m_scoreBreakdown;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
// in case of confusion net, ptr to source phrase
|
2011-03-23 23:42:34 +03:00
|
|
|
Phrase m_sourcePhrase;
|
2012-10-19 18:10:10 +04:00
|
|
|
const AlignmentInfo* m_alignTerm, *m_alignNonTerm;
|
2013-05-22 14:22:17 +04:00
|
|
|
const Word *m_lhsTarget;
|
2008-09-12 22:09:06 +04:00
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
public:
|
2011-11-21 14:49:26 +04:00
|
|
|
TargetPhrase();
|
2013-05-22 13:40:12 +04:00
|
|
|
TargetPhrase(const TargetPhrase ©);
|
2012-10-22 20:40:23 +04:00
|
|
|
explicit TargetPhrase(std::string out_string);
|
|
|
|
explicit TargetPhrase(const Phrase &targetPhrase);
|
2013-05-22 13:57:19 +04:00
|
|
|
~TargetPhrase();
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2013-05-28 03:41:25 +04:00
|
|
|
void Evaluate(const Phrase &source);
|
|
|
|
void Evaluate(const InputType &input);
|
2013-05-02 15:15:26 +04:00
|
|
|
|
2013-04-30 20:27:35 +04:00
|
|
|
void SetSparseScore(const FeatureFunction* translationScoreProducer, const StringPiece &sparseString);
|
|
|
|
|
2013-05-02 20:25:29 +04:00
|
|
|
// used to set translation or gen score
|
2013-05-02 20:44:19 +04:00
|
|
|
void SetXMLScore(float score);
|
2013-05-02 21:21:52 +04:00
|
|
|
void SetInputScore(const Scores &scoreVector);
|
2011-02-24 16:14:42 +03:00
|
|
|
|
|
|
|
TargetPhrase *MergeNext(const TargetPhrase &targetPhrase) const;
|
|
|
|
// used for translation step
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2008-09-24 20:48:23 +04:00
|
|
|
#ifdef HAVE_PROTOBUF
|
2011-02-24 16:14:42 +03:00
|
|
|
void WriteToRulePB(hgmert::Rule* pb) const;
|
2008-09-24 20:48:23 +04:00
|
|
|
#endif
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
/***
|
|
|
|
* return the estimated score resulting from our being added to a sentence
|
|
|
|
* (it's an estimate because we don't have full n-gram info for the language model
|
|
|
|
* without using the (unknown) full sentence)
|
2011-02-24 16:14:42 +03:00
|
|
|
*
|
2008-06-11 14:52:57 +04:00
|
|
|
*/
|
2011-02-24 16:14:42 +03:00
|
|
|
inline float GetFutureScore() const {
|
2008-06-11 14:52:57 +04:00
|
|
|
return m_fullScore;
|
|
|
|
}
|
2013-05-01 21:43:59 +04:00
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
inline const ScoreComponentCollection &GetScoreBreakdown() const
|
2013-05-13 16:19:25 +04:00
|
|
|
{ return m_scoreBreakdown; }
|
|
|
|
inline ScoreComponentCollection &GetScoreBreakdown()
|
|
|
|
{ return m_scoreBreakdown; }
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2012-09-26 17:40:06 +04:00
|
|
|
//TODO: Probably shouldn't copy this, but otherwise ownership is unclear
|
2011-03-23 23:42:34 +03:00
|
|
|
void SetSourcePhrase(const Phrase& p)
|
2008-06-11 14:52:57 +04:00
|
|
|
{
|
|
|
|
m_sourcePhrase=p;
|
|
|
|
}
|
2013-05-28 14:19:47 +04:00
|
|
|
const Phrase& GetSourcePhrase() const
|
2008-06-11 14:52:57 +04:00
|
|
|
{
|
|
|
|
return m_sourcePhrase;
|
|
|
|
}
|
2008-09-12 22:09:06 +04:00
|
|
|
|
2013-05-22 14:22:17 +04:00
|
|
|
void SetTargetLHS(const Word *lhs)
|
|
|
|
{ m_lhsTarget = lhs; }
|
2010-04-08 21:16:10 +04:00
|
|
|
const Word &GetTargetLHS() const
|
2013-05-22 13:57:19 +04:00
|
|
|
{ return *m_lhsTarget; }
|
2009-08-07 20:47:54 +04:00
|
|
|
|
2011-10-14 20:40:30 +04:00
|
|
|
void SetAlignmentInfo(const StringPiece &alignString);
|
2012-10-19 18:10:10 +04:00
|
|
|
void SetAlignTerm(const AlignmentInfo *alignTerm) {
|
|
|
|
m_alignTerm = alignTerm;
|
2011-09-27 04:34:46 +04:00
|
|
|
}
|
2012-10-19 18:10:10 +04:00
|
|
|
void SetAlignNonTerm(const AlignmentInfo *alignNonTerm) {
|
|
|
|
m_alignNonTerm = alignNonTerm;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetAlignTerm(const AlignmentInfo::CollType &coll);
|
|
|
|
void SetAlignNonTerm(const AlignmentInfo::CollType &coll);
|
|
|
|
|
|
|
|
const AlignmentInfo &GetAlignTerm() const
|
|
|
|
{ return *m_alignTerm; }
|
|
|
|
const AlignmentInfo &GetAlignNonTerm() const
|
|
|
|
{ return *m_alignNonTerm; }
|
2008-09-12 22:09:06 +04:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream&, const TargetPhrase&);
|
|
|
|
|
2012-09-21 18:57:48 +04:00
|
|
|
/**
|
|
|
|
* Hasher that looks at source and target phrase.
|
|
|
|
**/
|
2012-10-12 01:18:56 +04:00
|
|
|
struct TargetPhraseHasher
|
2012-09-21 18:57:48 +04:00
|
|
|
{
|
|
|
|
inline size_t operator()(const TargetPhrase& targetPhrase) const
|
|
|
|
{
|
|
|
|
size_t seed = 0;
|
|
|
|
boost::hash_combine(seed, targetPhrase);
|
|
|
|
boost::hash_combine(seed, targetPhrase.GetSourcePhrase());
|
2012-10-19 18:10:10 +04:00
|
|
|
boost::hash_combine(seed, targetPhrase.GetAlignTerm());
|
|
|
|
boost::hash_combine(seed, targetPhrase.GetAlignNonTerm());
|
|
|
|
|
2012-09-21 18:57:48 +04:00
|
|
|
return seed;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-12 01:18:56 +04:00
|
|
|
struct TargetPhraseComparator
|
2012-09-21 18:57:48 +04:00
|
|
|
{
|
|
|
|
inline bool operator()(const TargetPhrase& lhs, const TargetPhrase& rhs) const
|
|
|
|
{
|
|
|
|
return lhs.Compare(rhs) == 0 &&
|
2012-10-12 01:18:56 +04:00
|
|
|
lhs.GetSourcePhrase().Compare(rhs.GetSourcePhrase()) == 0 &&
|
2012-10-19 18:10:10 +04:00
|
|
|
lhs.GetAlignTerm() == rhs.GetAlignTerm() &&
|
|
|
|
lhs.GetAlignNonTerm() == rhs.GetAlignNonTerm();
|
2012-09-21 18:57:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
}
|
|
|
|
|
2010-02-24 14:15:44 +03:00
|
|
|
#endif
|