This commit is contained in:
Hieu Hoang 2013-08-07 14:18:12 +01:00
parent 5eef91c0ea
commit 441acf15e6
17 changed files with 96 additions and 93 deletions

View File

@ -206,10 +206,10 @@ void OutputSurface(std::ostream &out, const Hypothesis &edge, const std::vector<
const Factor *factor = phrase.GetFactor(pos, outputFactorOrder[0]);
if (placeholderFactor != NOT_FOUND) {
const Factor *origFactor = phrase.GetFactor(pos, placeholderFactor);
if (origFactor) {
factor = origFactor;
}
const Factor *origFactor = phrase.GetFactor(pos, placeholderFactor);
if (origFactor) {
factor = origFactor;
}
}
CHECK(factor);
out << *factor;
@ -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();
}
}

View File

@ -232,6 +232,6 @@ size_t ChartParser::GetSize() const
long ChartParser::GetTranslationId() const
{
return m_source.GetTranslationId();
return m_source.GetTranslationId();
}
} // namespace Moses

View File

@ -51,8 +51,9 @@ public:
return m_cellCollection.GetBase(WordsRange(begin, end)).GetTargetLabelSet();
}
const ChartParser &GetParser() const
{ return m_parser; }
const ChartParser &GetParser() const {
return m_parser;
}
//const Sentence &GetSentence() const;
const ChartCellLabel &GetSourceAt(size_t at) const {

View File

@ -73,7 +73,7 @@ public:
TranslationOptionCollection* CreateTranslationOptionCollection() const;
const NonTerminalSet &GetLabelSet(size_t /*startPos*/, size_t /*endPos*/) const {
return m_defaultLabelSet;
return m_defaultLabelSet;
}
};

View File

@ -41,11 +41,11 @@ public:
void Process(const TranslationOption &inputPartialTranslOpt
, const DecodeStep &decodeStep
, PartialTranslOptColl &outputPartialTranslOptColl
, TranslationOptionCollection *toc
, bool adhereTableLimit
, const Phrase &src) const;
, const DecodeStep &decodeStep
, PartialTranslOptColl &outputPartialTranslOptColl
, TranslationOptionCollection *toc
, bool adhereTableLimit
, const Phrase &src) const;
private:
};

View File

@ -173,33 +173,33 @@ void DecodeStepTranslation::ProcessInitialTranslationLegacy(
}
const InputPath &DecodeStepTranslation::GetInputPathLegacy(const TargetPhrase targetPhrase,
const InputPathList &inputPathList) const
const InputPathList &inputPathList) const
{
const Phrase &phraseFromTP = targetPhrase.GetSourcePhraseAA();
const Word &wordTP = phraseFromTP.GetWord(0);
const Phrase &phraseFromTP = targetPhrase.GetSourcePhraseAA();
const Word &wordTP = phraseFromTP.GetWord(0);
InputPathList::const_iterator iter;
for (iter = inputPathList.begin(); iter != inputPathList.end(); ++iter) {
const InputPath &inputPath = **iter;
const Phrase &phraseFromIP = inputPath.GetPhrase();
const Word &wordIP = phraseFromIP.GetWord(0);
InputPathList::const_iterator iter;
for (iter = inputPathList.begin(); iter != inputPathList.end(); ++iter) {
const InputPath &inputPath = **iter;
const Phrase &phraseFromIP = inputPath.GetPhrase();
const Word &wordIP = phraseFromIP.GetWord(0);
const WordsRange &range = inputPath.GetWordsRange();
const WordsRange &range = inputPath.GetWordsRange();
if (wordTP == wordIP) {
return inputPath;
}
}
if (wordTP == wordIP) {
return inputPath;
}
}
UTIL_THROW(util::Exception, "Input path not found");
UTIL_THROW(util::Exception, "Input path not found");
}
void DecodeStepTranslation::ProcessLegacy(const TranslationOption &inputPartialTranslOpt
, const DecodeStep &decodeStep
, PartialTranslOptColl &outputPartialTranslOptColl
, TranslationOptionCollection *toc
, bool adhereTableLimit
, const Phrase &src) const
, const DecodeStep &decodeStep
, PartialTranslOptColl &outputPartialTranslOptColl
, TranslationOptionCollection *toc
, bool adhereTableLimit
, const Phrase &src) const
{
if (inputPartialTranslOpt.GetTargetPhrase().GetSize() == 0) {
// word deletion
@ -216,7 +216,7 @@ void DecodeStepTranslation::ProcessLegacy(const TranslationOption &inputPartialT
const size_t tableLimit = phraseDictionary->GetTableLimit();
const TargetPhraseCollectionWithSourcePhrase *phraseColl
= phraseDictionary->GetTargetPhraseCollectionLegacy(toc->GetSource(),sourceWordsRange);
= phraseDictionary->GetTargetPhraseCollectionLegacy(toc->GetSource(),sourceWordsRange);
if (phraseColl != NULL) {

View File

@ -61,22 +61,22 @@ public:
// legacy
void ProcessInitialTranslationLegacy(const InputType &source
, PartialTranslOptColl &outputPartialTranslOptColl
, size_t startPos, size_t endPos, bool adhereTableLimit
, const InputPathList &inputPathList) const;
, PartialTranslOptColl &outputPartialTranslOptColl
, size_t startPos, size_t endPos, bool adhereTableLimit
, const InputPathList &inputPathList) const;
void ProcessLegacy(const TranslationOption &inputPartialTranslOpt
, const DecodeStep &decodeStep
, PartialTranslOptColl &outputPartialTranslOptColl
, TranslationOptionCollection *toc
, bool adhereTableLimit
, const Phrase &src) const;
, const DecodeStep &decodeStep
, PartialTranslOptColl &outputPartialTranslOptColl
, TranslationOptionCollection *toc
, bool adhereTableLimit
, const Phrase &src) const;
private:
// I'm not sure whether this actually works or not for binary phrase table.
// The source phrase only appears to contain the 1st word, therefore, this function
// only compares the 1st word
const InputPath &GetInputPathLegacy(const TargetPhrase targetPhrase,
const InputPathList &inputPathList) const;
const InputPathList &inputPathList) const;
};

View File

@ -345,7 +345,7 @@ void Hypothesis::PrintHypothesis() const
TRACE_ERR( ")"<<endl);
TRACE_ERR( "\tbase score "<< (m_prevHypo->m_totalScore - m_prevHypo->m_futureScore) <<endl);
TRACE_ERR( "\tcovering "<<m_currSourceWordsRange.GetStartPos()<<"-"<<m_currSourceWordsRange.GetEndPos()
<<": " << m_transOpt.GetSourcePhrase() << endl);
<<": " << m_transOpt.GetSourcePhrase() << endl);
TRACE_ERR( "\ttranslated as: "<<(Phrase&) GetCurrTargetPhrase()<<endl); // <<" => translation cost "<<m_score[ScoreType::PhraseTrans];
@ -398,7 +398,8 @@ void Hypothesis::CleanupArcList()
}
}
const TargetPhrase &Hypothesis::GetCurrTargetPhrase() const {
const TargetPhrase &Hypothesis::GetCurrTargetPhrase() const
{
return m_transOpt.GetTargetPhrase();
}

View File

@ -3,18 +3,19 @@
using namespace std;
namespace Moses {
std::ostream& operator<<(std::ostream &out, const NonTerminalSet &obj)
{
NonTerminalSet::const_iterator iter;
for (iter = obj.begin(); iter != obj.end(); ++iter) {
const Word &word = *iter;
out << word << " ";
}
return out;
namespace Moses
{
std::ostream& operator<<(std::ostream &out, const NonTerminalSet &obj)
{
NonTerminalSet::const_iterator iter;
for (iter = obj.begin(); iter != obj.end(); ++iter) {
const Word &word = *iter;
out << word << " ";
}
return out;
}
}

View File

@ -309,11 +309,13 @@ public:
}
TargetPhraseCollectionWithSourcePhrase* PruneTargetCandidates
(const std::vector<TargetPhrase> & tCands,
std::vector<std::pair<float,size_t> >& costs,
const std::vector<Phrase> &sourcePhrases) const {
(const std::vector<TargetPhrase> & tCands,
std::vector<std::pair<float,size_t> >& costs,
const std::vector<Phrase> &sourcePhrases) const {
// convert into TargetPhraseCollection
TargetPhraseCollectionWithSourcePhrase *rv=new TargetPhraseCollectionWithSourcePhrase;
CHECK(tCands.size() == sourcePhrases.size());
TargetPhraseCollectionWithSourcePhrase *rv=new TargetPhraseCollectionWithSourcePhrase;
// set limit to tableLimit or actual size, whatever is smaller

View File

@ -8,9 +8,9 @@ namespace Moses
{
Search::Search(Manager& manager)
: m_manager(manager)
,m_sourcePhrase(0)
,m_initialTransOpt()
: m_manager(manager)
,m_sourcePhrase(0)
,m_initialTransOpt()
{
m_initialTransOpt.SetSourcePhrase(m_sourcePhrase);
}

View File

@ -83,7 +83,7 @@ public:
void CleanUpAfterSentenceProcessing(const InputType &source);
virtual ChartRuleLookupManager *CreateRuleLookupManager(
const ChartParser &,
const ChartParser &,
const ChartCellCollectionBase &) {
assert(false);
return 0;

View File

@ -110,8 +110,8 @@ PhraseDictionaryTreeAdaptor::GetTargetPhraseCollectionLegacy(InputType const& sr
const TargetPhraseCollectionWithSourcePhrase *tpColl = GetImplementation().GetTargetPhraseCollection(src.GetSubString(range));
return tpColl;
} else {
const TargetPhraseCollectionWithSourcePhrase *tpColl = GetImplementation().m_rangeCache[range.GetStartPos()][range.GetEndPos()];
return tpColl;
const TargetPhraseCollectionWithSourcePhrase *tpColl = GetImplementation().m_rangeCache[range.GetStartPos()][range.GetEndPos()];
return tpColl;
}
}

View File

@ -33,9 +33,9 @@ namespace Moses
{
TranslationOption::TranslationOption()
:m_targetPhrase()
,m_sourcePhrase(NULL)
,m_sourceWordsRange(NOT_FOUND, NOT_FOUND)
:m_targetPhrase()
,m_sourcePhrase(NULL)
,m_sourceWordsRange(NOT_FOUND, NOT_FOUND)
{
}

View File

@ -96,8 +96,7 @@ public:
/** returns source phrase */
const Phrase &GetSourcePhrase() const;
void SetSourcePhrase(const Phrase &sourcePhrase)
{
void SetSourcePhrase(const Phrase &sourcePhrase) {
m_sourcePhrase = &sourcePhrase;
}

View File

@ -262,9 +262,9 @@ void TranslationOptionCollection::ProcessOneUnknownWord(const Word &sourceWord,s
}
// source phrase
Phrase *unksrc = new Phrase(1);
unksrc->AddWord() = sourceWord;
m_unksrcs.push_back(unksrc);
Phrase *unksrc = new Phrase(1);
unksrc->AddWord() = sourceWord;
m_unksrcs.push_back(unksrc);
targetPhrase.Evaluate(*unksrc);
@ -482,12 +482,12 @@ void TranslationOptionCollection::CreateTranslationOptionsForRange(
} else {
const DecodeStepGeneration *genStep = dynamic_cast<const DecodeStepGeneration*>(decodeStep);
assert(genStep);
genStep->Process(inputPartialTranslOpt
, *decodeStep
, *newPtoc
, this
, adhereTableLimit
, *sourcePhrase);
genStep->Process(inputPartialTranslOpt
, *decodeStep
, *newPtoc
, this
, adhereTableLimit
, *sourcePhrase);
}
}
@ -530,8 +530,8 @@ void TranslationOptionCollection::SetInputPath(const InputPath &inputPath, Parti
transOpt.SetSourcePhrase(sourcePhrase);
if (inputScore) {
ScoreComponentCollection &scores = transOpt.GetScoreBreakdown();
scores.PlusEquals(*inputScore);
ScoreComponentCollection &scores = transOpt.GetScoreBreakdown();
scores.PlusEquals(*inputScore);
}
}
}
@ -663,7 +663,7 @@ void TranslationOptionCollection::CacheLexReordering()
//Phrase sourcePhrase = m_source.GetSubString(WordsRange(startPos,endPos));
const Phrase &sourcePhrase = transOpt.GetSourcePhrase();
Scores score = lexreordering.GetProb(sourcePhrase
, transOpt.GetTargetPhrase());
, transOpt.GetTargetPhrase());
if (!score.empty())
transOpt.CacheLexReorderingScores(lexreordering, score);
} // for(iterTransOpt

View File

@ -192,7 +192,7 @@ void TranslationOptionCollectionConfusionNet::CreateTranslationOptionsForRangeLe
if ((StaticData::Instance().GetXmlInputType() != XmlExclusive) || !HasXmlOptionsOverlappingRange(startPos,endPos)) {
Phrase *sourcePhrase = NULL; // can't initialise with substring, in case it's confusion network
InputPathList &inputPathList = GetInputPathList(startPos, endPos);
InputPathList &inputPathList = GetInputPathList(startPos, endPos);
// partial trans opt stored in here
PartialTranslOptColl* oldPtoc = new PartialTranslOptColl;
@ -225,21 +225,20 @@ void TranslationOptionCollectionConfusionNet::CreateTranslationOptionsForRangeLe
if (transStep) {
transStep->ProcessLegacy(inputPartialTranslOpt
, *decodeStep
, *newPtoc
, this
, adhereTableLimit
, *sourcePhrase);
} else {
CHECK(genStep);
genStep->Process(inputPartialTranslOpt
, *decodeStep
, *newPtoc
, this
, adhereTableLimit
, *sourcePhrase);
}
else {
CHECK(genStep);
genStep->Process(inputPartialTranslOpt
, *decodeStep
, *newPtoc
, this
, adhereTableLimit
, *sourcePhrase);
}
}
// last but 1 partial trans not required anymore