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"
|
|
|
|
|
2008-09-24 20:48:23 +04:00
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
#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
|
|
|
|
{
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
class LMList;
|
|
|
|
class PhraseDictionary;
|
|
|
|
class GenerationDictionary;
|
|
|
|
class ScoreProducer;
|
2010-08-10 17:12:00 +04:00
|
|
|
class TranslationSystem;
|
|
|
|
class WordPenaltyProducer;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
class CountInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CountInfo()
|
|
|
|
{}
|
|
|
|
CountInfo(float countSource, float countTarget)
|
|
|
|
:m_countSource(countSource)
|
|
|
|
,m_countTarget(countTarget)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
float m_countSource;
|
|
|
|
float m_countTarget;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
friend std::ostream& operator<<(std::ostream&, const TargetPhrase&);
|
|
|
|
protected:
|
|
|
|
float m_transScore, m_ngramScore, m_fullScore;
|
|
|
|
//float m_ngramScore, m_fullScore;
|
|
|
|
ScoreComponentCollection m_scoreBreakdown;
|
2010-04-08 21:16:10 +04:00
|
|
|
AlignmentInfo m_alignmentInfo;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
// in case of confusion net, ptr to source phrase
|
|
|
|
Phrase const* m_sourcePhrase;
|
2010-04-08 21:16:10 +04:00
|
|
|
Word m_lhsTarget;
|
|
|
|
CountInfo m_countInfo;
|
2008-09-12 22:09:06 +04:00
|
|
|
|
|
|
|
static bool wordalignflag;
|
|
|
|
static bool printalign;
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
public:
|
2010-05-06 23:46:23 +04:00
|
|
|
TargetPhrase(FactorDirection direction=Output);
|
|
|
|
TargetPhrase(FactorDirection direction, std::string out_string);
|
|
|
|
~TargetPhrase();
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
//! used by the unknown word handler- these targets
|
|
|
|
//! don't have a translation score, so wp is the only thing used
|
2010-08-10 17:12:00 +04:00
|
|
|
void SetScore(const TranslationSystem* system);
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
//!Set score for Sentence XML target options
|
|
|
|
void SetScore(float score);
|
|
|
|
|
2009-02-05 20:37:09 +03:00
|
|
|
//! Set score for unknown words with input weights
|
2010-08-10 17:12:00 +04:00
|
|
|
void SetScore(const TranslationSystem* system, const Scores &scoreVector);
|
2009-02-05 20:37:09 +03:00
|
|
|
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
/*** Called immediately after creation to initialize scores.
|
|
|
|
*
|
|
|
|
* @param translationScoreProducer The PhraseDictionaryMemory that this TargetPhrase is contained by.
|
|
|
|
* Used to identify where the scores for this phrase belong in the list of all scores.
|
|
|
|
* @param scoreVector the vector of scores (log probs) associated with this translation
|
|
|
|
* @param weighT the weights for the individual scores (t-weights in the .ini file)
|
|
|
|
* @param languageModels all the LanguageModels that should be used to compute the LM scores
|
|
|
|
* @param weightWP the weight of the word penalty
|
|
|
|
*
|
|
|
|
* @TODO should this be part of the constructor? If not, add explanation why not.
|
2008-09-12 22:09:06 +04:00
|
|
|
*/
|
2008-06-11 14:52:57 +04:00
|
|
|
void SetScore(const ScoreProducer* translationScoreProducer,
|
2008-09-12 22:09:06 +04:00
|
|
|
const Scores &scoreVector,
|
2008-06-11 14:52:57 +04:00
|
|
|
const std::vector<float> &weightT,
|
|
|
|
float weightWP,
|
|
|
|
const LMList &languageModels);
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
void SetScoreChart(const ScoreProducer* translationScoreProducer
|
|
|
|
,const Scores &scoreVector
|
|
|
|
,const std::vector<float> &weightT
|
2010-08-10 17:12:00 +04:00
|
|
|
,const LMList &languageModels
|
|
|
|
,const WordPenaltyProducer* wpProducer);
|
2010-04-08 21:16:10 +04:00
|
|
|
|
|
|
|
// used by for unknown word proc in chart decoding
|
|
|
|
void SetScore(const ScoreProducer* producer, const Scores &scoreVector);
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2008-09-12 22:09:06 +04:00
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
// used when creating translations of unknown words:
|
|
|
|
void ResetScore();
|
|
|
|
void SetWeights(const ScoreProducer*, const std::vector<float> &weightT);
|
|
|
|
|
|
|
|
TargetPhrase *MergeNext(const TargetPhrase &targetPhrase) const;
|
|
|
|
// used for translation step
|
|
|
|
|
2008-09-24 20:48:23 +04:00
|
|
|
#ifdef HAVE_PROTOBUF
|
|
|
|
void WriteToRulePB(hgmert::Rule* pb) const;
|
|
|
|
#endif
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
/* inline float GetTranslationScore() const
|
|
|
|
{
|
|
|
|
return m_transScore;
|
|
|
|
}*/
|
|
|
|
/***
|
|
|
|
* 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)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
inline float GetFutureScore() const
|
|
|
|
{
|
|
|
|
return m_fullScore;
|
|
|
|
}
|
|
|
|
inline const ScoreComponentCollection &GetScoreBreakdown() const
|
|
|
|
{
|
|
|
|
return m_scoreBreakdown;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! TODO - why is this needed and is it set correctly by every phrase dictionary class ? should be set in constructor
|
|
|
|
void SetSourcePhrase(Phrase const* p)
|
|
|
|
{
|
|
|
|
m_sourcePhrase=p;
|
|
|
|
}
|
|
|
|
Phrase const* GetSourcePhrase() const
|
|
|
|
{
|
|
|
|
return m_sourcePhrase;
|
|
|
|
}
|
2008-09-12 22:09:06 +04:00
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
void SetTargetLHS(const Word &lhs)
|
|
|
|
{ m_lhsTarget = lhs; }
|
|
|
|
const Word &GetTargetLHS() const
|
|
|
|
{ return m_lhsTarget; }
|
2009-08-07 20:47:54 +04:00
|
|
|
|
2010-07-18 02:29:06 +04:00
|
|
|
void SetAlignmentInfo(const std::string &alignString);
|
2010-04-08 21:16:10 +04:00
|
|
|
void SetAlignmentInfo(const std::list<std::pair<size_t,size_t> > &alignmentInfo);
|
2009-08-07 20:47:54 +04:00
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
AlignmentInfo &GetAlignmentInfo()
|
|
|
|
{ return m_alignmentInfo; }
|
|
|
|
const AlignmentInfo &GetAlignmentInfo() const
|
|
|
|
{ return m_alignmentInfo; }
|
2008-09-12 22:09:06 +04:00
|
|
|
|
|
|
|
void UseWordAlignment(bool a){
|
|
|
|
wordalignflag=a;
|
|
|
|
};
|
|
|
|
bool UseWordAlignment() const {
|
|
|
|
return wordalignflag;
|
|
|
|
};
|
|
|
|
void PrintAlignmentInfo(bool a) {
|
|
|
|
printalign=a;
|
|
|
|
}
|
|
|
|
bool PrintAlignmentInfo() const {
|
|
|
|
return printalign;
|
|
|
|
}
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2010-04-08 21:16:10 +04:00
|
|
|
void CreateCountInfo(const std::string &countStr);
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
TO_STRING();
|
|
|
|
};
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream&, const TargetPhrase&);
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
}
|
|
|
|
|
2010-02-24 14:15:44 +03:00
|
|
|
#endif
|