mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-10-26 19:37:58 +03:00
source phrase is a pointer in translation options.
This commit is contained in:
parent
7a808a2edb
commit
66d4c2b0be
@ -348,7 +348,7 @@ void OutputBestHypo(const std::vector<Word>& mbrBestHypo, long /*translationId*
|
||||
void OutputInput(std::vector<const Phrase*>& map, const Hypothesis* hypo)
|
||||
{
|
||||
if (hypo->GetPrevHypo()) {
|
||||
OutputInput(map, hypo->GetPrevHypo());
|
||||
OutputInput(map, hypo->GetPrevHypo());
|
||||
map[hypo->GetCurrSourceWordsRange().GetStartPos()] = &hypo->GetTranslationOption().GetSourcePhrase();
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,15 @@
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
Search::Search(Manager& manager)
|
||||
: m_manager(manager)
|
||||
,m_sourcePhrase(0)
|
||||
,m_initialTransOpt()
|
||||
{
|
||||
m_initialTransOpt.SetSourcePhrase(m_sourcePhrase);
|
||||
}
|
||||
|
||||
|
||||
Search *Search::CreateSearch(Manager& manager, const InputType &source,
|
||||
SearchAlgorithm searchAlgorithm, const TranslationOptionCollection &transOptColl)
|
||||
{
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#include <vector>
|
||||
#include "TypeDef.h"
|
||||
#include "TranslationOption.h"
|
||||
#include "Phrase.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
@ -29,7 +31,7 @@ public:
|
||||
//! Decode the sentence according to the specified search algorithm.
|
||||
virtual void ProcessSentence() = 0;
|
||||
|
||||
explicit Search(Manager& manager) : m_manager(manager) {}
|
||||
explicit Search(Manager& manager);
|
||||
virtual ~Search() {}
|
||||
|
||||
// Factory method
|
||||
@ -39,6 +41,8 @@ public:
|
||||
protected:
|
||||
const Phrase *m_constraint;
|
||||
Manager& m_manager;
|
||||
Phrase m_sourcePhrase; // for initial hypo
|
||||
TranslationOption m_initialTransOpt; /**< used to seed 1st hypo */
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -41,7 +41,6 @@ SearchCubePruning::SearchCubePruning(Manager& manager, const InputType &source,
|
||||
:Search(manager)
|
||||
,m_source(source)
|
||||
,m_hypoStackColl(source.GetSize() + 1)
|
||||
,m_initialTransOpt()
|
||||
,m_start(clock())
|
||||
,m_transOptColl(transOptColl)
|
||||
{
|
||||
|
@ -20,7 +20,6 @@ protected:
|
||||
const InputType &m_source;
|
||||
std::vector < HypothesisStack* > m_hypoStackColl; /**< stacks to store hypotheses (partial translations) */
|
||||
// no of elements = no of words in source + 1
|
||||
TranslationOption m_initialTransOpt; /**< used to seed 1st hypo */
|
||||
clock_t m_start; /**< used to track time spend on translation */
|
||||
const TranslationOptionCollection &m_transOptColl; /**< pre-computed list of translation options for the phrases in this sentence */
|
||||
|
||||
|
@ -16,7 +16,6 @@ SearchNormal::SearchNormal(Manager& manager, const InputType &source, const Tran
|
||||
:Search(manager)
|
||||
,m_source(source)
|
||||
,m_hypoStackColl(source.GetSize() + 1)
|
||||
,m_initialTransOpt()
|
||||
,m_start(clock())
|
||||
,interrupted_flag(0)
|
||||
,m_transOptColl(transOptColl)
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include "HypothesisStackNormal.h"
|
||||
#include "TranslationOptionCollection.h"
|
||||
#include "Timer.h"
|
||||
#include "TranslationOption.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
@ -24,7 +23,6 @@ protected:
|
||||
const InputType &m_source;
|
||||
std::vector < HypothesisStack* > m_hypoStackColl; /**< stacks to store hypotheses (partial translations) */
|
||||
// no of elements = no of words in source + 1
|
||||
TranslationOption m_initialTransOpt; /**< used to seed 1st hypo */
|
||||
clock_t m_start; /**< starting time, used for logging */
|
||||
size_t interrupted_flag; /**< flag indicating that decoder ran out of time (see switch -time-out) */
|
||||
HypothesisStackNormal* actual_hypoStack; /**actual (full expanded) stack of hypotheses*/
|
||||
|
@ -44,7 +44,8 @@ void SentenceStats::AddDeletedWords(const Hypothesis& hypo)
|
||||
//don't check either a null pointer or the empty initial hypothesis (if we were given the empty hypo, the null check will save us)
|
||||
if(hypo.GetPrevHypo() != NULL && hypo.GetPrevHypo()->GetCurrSourceWordsRange().GetNumWordsCovered() > 0) AddDeletedWords(*hypo.GetPrevHypo());
|
||||
|
||||
if(hypo.GetCurrTargetWordsRange().GetNumWordsCovered() == 0) {
|
||||
if(hypo.GetPrevHypo() && hypo.GetCurrTargetWordsRange().GetNumWordsCovered() == 0) {
|
||||
|
||||
m_deletedWords.push_back(&hypo.GetTranslationOption().GetSourcePhrase());
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ namespace Moses
|
||||
|
||||
TranslationOption::TranslationOption()
|
||||
:m_targetPhrase()
|
||||
,m_sourcePhrase(NULL)
|
||||
,m_sourceWordsRange(NOT_FOUND, NOT_FOUND)
|
||||
{
|
||||
}
|
||||
@ -42,19 +43,12 @@ TranslationOption::TranslationOption()
|
||||
TranslationOption::TranslationOption(const WordsRange &wordsRange
|
||||
, const TargetPhrase &targetPhrase)
|
||||
: m_targetPhrase(targetPhrase)
|
||||
, m_sourcePhrase(NULL)
|
||||
, m_sourceWordsRange(wordsRange)
|
||||
, m_futureScore(targetPhrase.GetFutureScore())
|
||||
{
|
||||
}
|
||||
|
||||
TranslationOption::TranslationOption(const TranslationOption ©, const WordsRange &sourceWordsRange)
|
||||
: m_targetPhrase(copy.m_targetPhrase)
|
||||
//, m_sourcePhrase(new Phrase(*copy.m_sourcePhrase)) // TODO use when confusion network trans opt for confusion net properly implemented
|
||||
, m_sourceWordsRange(sourceWordsRange)
|
||||
, m_futureScore(copy.m_futureScore)
|
||||
, m_lexReorderingScores(copy.m_lexReorderingScores)
|
||||
{}
|
||||
|
||||
bool TranslationOption::IsCompatible(const Phrase& phrase, const std::vector<FactorType>& featuresToCheck) const
|
||||
{
|
||||
if (featuresToCheck.size() == 1) {
|
||||
@ -83,6 +77,13 @@ void TranslationOption::Evaluate(const InputType &source)
|
||||
m_targetPhrase.Evaluate(source);
|
||||
}
|
||||
|
||||
const Phrase &TranslationOption::GetSourcePhrase() const
|
||||
{
|
||||
CHECK(m_sourcePhrase);
|
||||
return *m_sourcePhrase;
|
||||
}
|
||||
|
||||
|
||||
TO_STRING_BODY(TranslationOption);
|
||||
|
||||
// friend
|
||||
|
@ -66,6 +66,7 @@ class TranslationOption
|
||||
protected:
|
||||
|
||||
TargetPhrase m_targetPhrase; /*< output phrase when using this translation option */
|
||||
const Phrase *m_sourcePhrase;
|
||||
const WordsRange m_sourceWordsRange; /*< word position in the input that are covered by this translation option */
|
||||
float m_futureScore; /*< estimate of total cost when using this translation option, includes language model probabilities */
|
||||
|
||||
@ -73,16 +74,12 @@ protected:
|
||||
_ScoreCacheMap m_lexReorderingScores;
|
||||
|
||||
public:
|
||||
explicit TranslationOption(); // For initial hypo that does translate anything
|
||||
explicit TranslationOption(); // For initial hypo that does translate nothing
|
||||
|
||||
/** constructor. Used by initial translation step */
|
||||
TranslationOption(const WordsRange &wordsRange
|
||||
, const TargetPhrase &targetPhrase);
|
||||
|
||||
/** copy constructor, but change words range. used by caching */
|
||||
TranslationOption(const TranslationOption ©, const WordsRange &sourceWordsRange);
|
||||
|
||||
|
||||
/** returns true if all feature types in featuresToCheck are compatible between the two phrases */
|
||||
bool IsCompatible(const Phrase& phrase, const std::vector<FactorType>& featuresToCheck) const;
|
||||
|
||||
@ -97,13 +94,11 @@ public:
|
||||
}
|
||||
|
||||
/** returns source phrase */
|
||||
const Phrase &GetSourcePhrase() const {
|
||||
return m_targetPhrase.GetSourcePhrase();
|
||||
}
|
||||
const Phrase &GetSourcePhrase() const;
|
||||
|
||||
void SetSourcePhrase(const Phrase &sourcePhrase)
|
||||
{
|
||||
// TODO
|
||||
m_sourcePhrase = &sourcePhrase;
|
||||
}
|
||||
|
||||
/** whether source span overlaps with those of a hypothesis */
|
||||
|
@ -226,13 +226,7 @@ void TranslationOptionCollection::ProcessOneUnknownWord(const Word &sourceWord,s
|
||||
// modify the starting bitmap
|
||||
}
|
||||
|
||||
Phrase* m_unksrc = new Phrase(1);
|
||||
m_unksrc->AddWord() = sourceWord;
|
||||
m_unksrcs.push_back(m_unksrc);
|
||||
|
||||
TranslationOption *transOpt;
|
||||
TargetPhrase targetPhrase;
|
||||
targetPhrase.SetSourcePhrase(*m_unksrc);
|
||||
|
||||
if (!(staticData.GetDropUnknown() || isEpsilon) || isDigit) {
|
||||
// add to dictionary
|
||||
@ -266,9 +260,17 @@ void TranslationOptionCollection::ProcessOneUnknownWord(const Word &sourceWord,s
|
||||
targetPhrase.SetInputScore(*inputScores);
|
||||
}
|
||||
|
||||
targetPhrase.Evaluate(*m_unksrc);
|
||||
// source phrase
|
||||
Phrase *unksrc = new Phrase(1);
|
||||
unksrc->AddWord() = sourceWord;
|
||||
m_unksrcs.push_back(unksrc);
|
||||
|
||||
transOpt = new TranslationOption(WordsRange(sourcePos, sourcePos + length - 1), targetPhrase);
|
||||
targetPhrase.Evaluate(*unksrc);
|
||||
|
||||
WordsRange range(sourcePos, sourcePos + length - 1);
|
||||
|
||||
TranslationOption *transOpt = new TranslationOption(range, targetPhrase);
|
||||
transOpt->SetSourcePhrase(*unksrc);
|
||||
Add(transOpt);
|
||||
|
||||
|
||||
@ -517,16 +519,17 @@ void TranslationOptionCollection::CreateTranslationOptionsForRange(
|
||||
void TranslationOptionCollection::AddInputScore(const InputPath &inputPath, PartialTranslOptColl &oldPtoc)
|
||||
{
|
||||
const ScoreComponentCollection *inputScore = inputPath.GetInputScore();
|
||||
|
||||
if (inputScore == NULL) {
|
||||
return;
|
||||
}
|
||||
const Phrase &sourcePhrase = inputPath.GetPhrase();
|
||||
|
||||
const std::vector<TranslationOption*> &transOpts = oldPtoc.GetList();
|
||||
for (size_t i = 0; i < transOpts.size(); ++i) {
|
||||
TranslationOption &transOpt = *transOpts[i];
|
||||
ScoreComponentCollection &scores = transOpt.GetScoreBreakdown();
|
||||
scores.PlusEquals(*inputScore);
|
||||
transOpt.SetSourcePhrase(sourcePhrase);
|
||||
|
||||
if (inputScore) {
|
||||
ScoreComponentCollection &scores = transOpt.GetScoreBreakdown();
|
||||
scores.PlusEquals(*inputScore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user