mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 05:14:36 +03:00
consistently set source phrase in translation options as soon as the trans opt is created
This commit is contained in:
parent
88f888f534
commit
a60bbbf892
@ -49,7 +49,7 @@ void DecodeStepTranslation::Process(const TranslationOption &inputPartialTranslO
|
||||
, PartialTranslOptColl &outputPartialTranslOptColl
|
||||
, TranslationOptionCollection *toc
|
||||
, bool adhereTableLimit
|
||||
, const Phrase &src
|
||||
, const Phrase &sourcePhrase
|
||||
, const TargetPhraseCollection *phraseColl) const
|
||||
{
|
||||
if (inputPartialTranslOpt.GetTargetPhrase().GetSize() == 0) {
|
||||
@ -84,12 +84,13 @@ void DecodeStepTranslation::Process(const TranslationOption &inputPartialTranslO
|
||||
}
|
||||
|
||||
outPhrase.Merge(targetPhrase, m_newOutputFactors);
|
||||
outPhrase.Evaluate(src, m_featuresToApply); // need to do this as all non-transcores would be screwed up
|
||||
|
||||
outPhrase.Evaluate(sourcePhrase, m_featuresToApply); // need to do this as all non-transcores would be screwed up
|
||||
|
||||
TranslationOption *newTransOpt = new TranslationOption(sourceWordsRange, outPhrase);
|
||||
assert(newTransOpt != NULL);
|
||||
|
||||
newTransOpt->SetSourcePhrase(sourcePhrase);
|
||||
|
||||
outputPartialTranslOptColl.Add(newTransOpt );
|
||||
|
||||
}
|
||||
@ -103,6 +104,7 @@ void DecodeStepTranslation::ProcessInitialTranslation(
|
||||
const InputType &source
|
||||
,PartialTranslOptColl &outputPartialTranslOptColl
|
||||
, size_t startPos, size_t endPos, bool adhereTableLimit
|
||||
, const Phrase &sourcePhrase
|
||||
, const TargetPhraseCollection *phraseColl) const
|
||||
{
|
||||
const PhraseDictionary* phraseDictionary = GetPhraseDictionaryFeature();
|
||||
@ -125,6 +127,8 @@ void DecodeStepTranslation::ProcessInitialTranslation(
|
||||
const TargetPhrase &targetPhrase = **iterTargetPhrase;
|
||||
TranslationOption *transOpt = new TranslationOption(wordsRange, targetPhrase);
|
||||
|
||||
transOpt->SetSourcePhrase(sourcePhrase);
|
||||
|
||||
outputPartialTranslOptColl.Add (transOpt);
|
||||
|
||||
VERBOSE(3,"\t" << targetPhrase << "\n");
|
||||
@ -208,7 +212,7 @@ void DecodeStepTranslation::ProcessLegacy(const TranslationOption &inputPartialT
|
||||
, PartialTranslOptColl &outputPartialTranslOptColl
|
||||
, TranslationOptionCollection *toc
|
||||
, bool adhereTableLimit
|
||||
, const Phrase &src) const
|
||||
, const Phrase &sourcePhrase) const
|
||||
{
|
||||
if (inputPartialTranslOpt.GetTargetPhrase().GetSize() == 0) {
|
||||
// word deletion
|
||||
@ -246,12 +250,14 @@ void DecodeStepTranslation::ProcessLegacy(const TranslationOption &inputPartialT
|
||||
}
|
||||
|
||||
outPhrase.Merge(targetPhrase, m_newOutputFactors);
|
||||
outPhrase.Evaluate(src, m_featuresToApply); // need to do this as all non-transcores would be screwed up
|
||||
outPhrase.Evaluate(sourcePhrase, m_featuresToApply); // need to do this as all non-transcores would be screwed up
|
||||
|
||||
|
||||
TranslationOption *newTransOpt = new TranslationOption(sourceWordsRange, outPhrase);
|
||||
assert(newTransOpt != NULL);
|
||||
|
||||
newTransOpt->SetSourcePhrase(sourcePhrase);
|
||||
|
||||
outputPartialTranslOptColl.Add(newTransOpt );
|
||||
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
, PartialTranslOptColl &outputPartialTranslOptColl
|
||||
, TranslationOptionCollection *toc
|
||||
, bool adhereTableLimit
|
||||
, const Phrase &src
|
||||
, const Phrase &sourcePhrase
|
||||
, const TargetPhraseCollection *phraseColl) const;
|
||||
|
||||
|
||||
@ -57,6 +57,7 @@ public:
|
||||
void ProcessInitialTranslation(const InputType &source
|
||||
, PartialTranslOptColl &outputPartialTranslOptColl
|
||||
, size_t startPos, size_t endPos, bool adhereTableLimit
|
||||
, const Phrase &sourcePhrase
|
||||
, const TargetPhraseCollection *phraseColl) const;
|
||||
|
||||
// legacy
|
||||
@ -69,7 +70,7 @@ public:
|
||||
, PartialTranslOptColl &outputPartialTranslOptColl
|
||||
, TranslationOptionCollection *toc
|
||||
, bool adhereTableLimit
|
||||
, const Phrase &src) const;
|
||||
, const Phrase &sourcePhrase) const;
|
||||
|
||||
private:
|
||||
// I'm not sure whether this actually works or not for binary phrase table.
|
||||
|
@ -83,6 +83,12 @@ const Phrase &TranslationOption::GetSourcePhrase() const
|
||||
return *m_sourcePhrase;
|
||||
}
|
||||
|
||||
void TranslationOption::SetSourcePhrase(const Phrase &sourcePhrase)
|
||||
{
|
||||
CHECK(m_sourcePhrase == NULL);
|
||||
m_sourcePhrase = &sourcePhrase;
|
||||
}
|
||||
|
||||
|
||||
TO_STRING_BODY(TranslationOption);
|
||||
|
||||
|
@ -96,9 +96,7 @@ public:
|
||||
/** returns source phrase */
|
||||
const Phrase &GetSourcePhrase() const;
|
||||
|
||||
void SetSourcePhrase(const Phrase &sourcePhrase) {
|
||||
m_sourcePhrase = &sourcePhrase;
|
||||
}
|
||||
void SetSourcePhrase(const Phrase &sourcePhrase);
|
||||
|
||||
/** whether source span overlaps with those of a hypothesis */
|
||||
bool Overlap(const Hypothesis &hypothesis) const;
|
||||
|
@ -435,7 +435,7 @@ void TranslationOptionCollection::CreateTranslationOptionsForRange(
|
||||
, InputPath &inputPath)
|
||||
{
|
||||
if ((StaticData::Instance().GetXmlInputType() != XmlExclusive) || !HasXmlOptionsOverlappingRange(startPos,endPos)) {
|
||||
Phrase *sourcePhrase = NULL; // can't initialise with substring, in case it's confusion network
|
||||
const Phrase &sourcePhrase = inputPath.GetPhrase(); // can't initialise with substring, in case it's confusion network
|
||||
|
||||
// partial trans opt stored in here
|
||||
PartialTranslOptColl* oldPtoc = new PartialTranslOptColl;
|
||||
@ -451,7 +451,7 @@ void TranslationOptionCollection::CreateTranslationOptionsForRange(
|
||||
static_cast<const DecodeStepTranslation&>(decodeStep).ProcessInitialTranslation
|
||||
(m_source, *oldPtoc
|
||||
, startPos, endPos, adhereTableLimit
|
||||
, targetPhrases);
|
||||
, sourcePhrase, targetPhrases);
|
||||
|
||||
SetInputPath(inputPath, *oldPtoc);
|
||||
|
||||
@ -477,7 +477,7 @@ void TranslationOptionCollection::CreateTranslationOptionsForRange(
|
||||
, *newPtoc
|
||||
, this
|
||||
, adhereTableLimit
|
||||
, *sourcePhrase
|
||||
, sourcePhrase
|
||||
, targetPhrases);
|
||||
} else {
|
||||
const DecodeStepGeneration *genStep = dynamic_cast<const DecodeStepGeneration*>(decodeStep);
|
||||
@ -487,7 +487,7 @@ void TranslationOptionCollection::CreateTranslationOptionsForRange(
|
||||
, *newPtoc
|
||||
, this
|
||||
, adhereTableLimit
|
||||
, *sourcePhrase);
|
||||
, sourcePhrase);
|
||||
}
|
||||
}
|
||||
|
||||
@ -522,17 +522,17 @@ void TranslationOptionCollection::CreateTranslationOptionsForRange(
|
||||
void TranslationOptionCollection::SetInputPath(const InputPath &inputPath, PartialTranslOptColl &oldPtoc)
|
||||
{
|
||||
const ScoreComponentCollection *inputScore = inputPath.GetInputScore();
|
||||
const Phrase &sourcePhrase = inputPath.GetPhrase();
|
||||
if (inputScore == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::vector<TranslationOption*> &transOpts = oldPtoc.GetList();
|
||||
for (size_t i = 0; i < transOpts.size(); ++i) {
|
||||
TranslationOption &transOpt = *transOpts[i];
|
||||
transOpt.SetSourcePhrase(sourcePhrase);
|
||||
|
||||
if (inputScore) {
|
||||
ScoreComponentCollection &scores = transOpt.GetScoreBreakdown();
|
||||
scores.PlusEquals(*inputScore);
|
||||
}
|
||||
ScoreComponentCollection &scores = transOpt.GetScoreBreakdown();
|
||||
scores.PlusEquals(*inputScore);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user