From 4abdf4fef3d462fc0b91078fda3b83752877cb2c Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Thu, 14 Apr 2016 18:55:13 +0400 Subject: [PATCH] syntax --- .../other-builds/moses2/SCFG/InputPaths.cpp | 22 ++++++++++++++----- contrib/other-builds/moses2/SCFG/Manager.cpp | 18 ++++++++------- .../TranslationModel/PhraseTableMemory.cpp | 5 ----- .../TranslationModel/UnknownWordPenalty.cpp | 4 ++++ .../TranslationModel/UnknownWordPenalty.h | 2 ++ 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/contrib/other-builds/moses2/SCFG/InputPaths.cpp b/contrib/other-builds/moses2/SCFG/InputPaths.cpp index 6f8601f15..cbcfcdf9e 100644 --- a/contrib/other-builds/moses2/SCFG/InputPaths.cpp +++ b/contrib/other-builds/moses2/SCFG/InputPaths.cpp @@ -25,14 +25,24 @@ void InputPaths::Init(const Sentence &input, const ManagerBase &mgr) size_t size = input.GetSize(); size_t maxLength = min(size, mgr.system.options.search.max_phrase_length); - m_matrix = new (pool.Allocate >()) Matrix(pool, + m_matrix = new (pool.Allocate< Matrix >()) Matrix(pool, size, maxLength); m_matrix->Init(NULL); - // create normal paths of subphrases through the sentence for (size_t startPos = 0; startPos < size; ++startPos) { - const InputPath *prefixPath = NULL; + // create path for 0 length string + Range range(startPos, startPos - 1); + SubPhrase subPhrase = input.GetSubPhrase(startPos, 0); + SCFG::InputPath *path = new (pool.Allocate()) SCFG::InputPath(pool, + subPhrase, range, numPt, NULL); + cerr << startPos << " " + << " path=" << *path << endl; + m_inputPaths.push_back(path); + m_matrix->SetValue(startPos, 0, path); + + // create normal paths of subphrases through the sentence + const SCFG::InputPath *prefixPath = path; for (size_t phaseSize = 1; phaseSize <= maxLength; ++phaseSize) { size_t endPos = startPos + phaseSize - 1; @@ -43,13 +53,15 @@ void InputPaths::Init(const Sentence &input, const ManagerBase &mgr) SubPhrase subPhrase = input.GetSubPhrase(startPos, phaseSize); Range range(startPos, endPos); - InputPath *path = new (pool.Allocate()) InputPath(pool, + SCFG::InputPath *path = new (pool.Allocate()) SCFG::InputPath(pool, subPhrase, range, numPt, prefixPath); + cerr << startPos << " " << (phaseSize - 1) + << " path=" << *path << endl; m_inputPaths.push_back(path); prefixPath = path; - m_matrix->SetValue(startPos, phaseSize - 1, path); + m_matrix->SetValue(startPos, phaseSize, path); } } diff --git a/contrib/other-builds/moses2/SCFG/Manager.cpp b/contrib/other-builds/moses2/SCFG/Manager.cpp index 969bd0b67..ca84e90a7 100644 --- a/contrib/other-builds/moses2/SCFG/Manager.cpp +++ b/contrib/other-builds/moses2/SCFG/Manager.cpp @@ -49,7 +49,7 @@ void Manager::Decode() m_stacks.Init(*this, size); cerr << "CREATED m_stacks" << endl; - for (int startPos = size; startPos >= 0; --startPos) { + for (int startPos = size - 1; startPos >= 0; --startPos) { InitActiveChart(startPos); for (int endPos = startPos + 1; endPos < size + 1; ++endPos) { @@ -62,17 +62,19 @@ void Manager::Decode() void Manager::InitActiveChart(size_t pos) { - /* - InputPath &path = static_cast(m_inputPaths.GetInputPath(pos, pos)); + + InputPath &path = static_cast(*m_inputPaths.GetMatrix().GetValue(pos, 0)); + cerr << "pos=" << pos << " path=" << path << endl; size_t numPt = system.mappings.size(); + cerr << "numPt=" << numPt << endl; for (size_t i = 0; i < numPt; ++i) { - const PhraseTable &pt = *system.mappings[i]; - cerr << "START InitActiveChart" << endl; - pt.InitActiveChart(path); - cerr << "FINISHED InitActiveChart" << endl; + const PhraseTable &pt = *system.mappings[i]; + cerr << "START InitActiveChart" << endl; + pt.InitActiveChart(path); + cerr << "FINISHED InitActiveChart" << endl; } - */ + } } diff --git a/contrib/other-builds/moses2/TranslationModel/PhraseTableMemory.cpp b/contrib/other-builds/moses2/TranslationModel/PhraseTableMemory.cpp index 066483c3b..ffada8f00 100644 --- a/contrib/other-builds/moses2/TranslationModel/PhraseTableMemory.cpp +++ b/contrib/other-builds/moses2/TranslationModel/PhraseTableMemory.cpp @@ -196,15 +196,10 @@ TargetPhrases* PhraseTableMemory::Lookup(const Manager &mgr, MemPool &pool, void PhraseTableMemory::InitActiveChart(SCFG::InputPath &path) const { size_t ptInd = GetPtInd(); - cerr << "BEFORE GetActiveChart" << endl; SCFG::ActiveChart &chart = path.GetActiveChart(ptInd); - cerr << "AFTER GetActiveChart" << endl; SCFG::ActiveChartEntry *chartEntry = new SCFG::ActiveChartEntry(&m_root); - cerr << "BEFORE push_back" << endl; chart.entries.push_back(chartEntry); - cerr << "AFTER push_back" << endl; - } } diff --git a/contrib/other-builds/moses2/TranslationModel/UnknownWordPenalty.cpp b/contrib/other-builds/moses2/TranslationModel/UnknownWordPenalty.cpp index e6131e142..71b0103b1 100644 --- a/contrib/other-builds/moses2/TranslationModel/UnknownWordPenalty.cpp +++ b/contrib/other-builds/moses2/TranslationModel/UnknownWordPenalty.cpp @@ -99,5 +99,9 @@ void UnknownWordPenalty::EvaluateInIsolation(const System &system, } +void UnknownWordPenalty::InitActiveChart(SCFG::InputPath &path) const +{ +} + } diff --git a/contrib/other-builds/moses2/TranslationModel/UnknownWordPenalty.h b/contrib/other-builds/moses2/TranslationModel/UnknownWordPenalty.h index c51b34208..26208d19f 100644 --- a/contrib/other-builds/moses2/TranslationModel/UnknownWordPenalty.h +++ b/contrib/other-builds/moses2/TranslationModel/UnknownWordPenalty.h @@ -27,6 +27,8 @@ public: const TargetPhrase &targetPhrase, Scores &scores, SCORE *estimatedScore) const; + virtual void InitActiveChart(SCFG::InputPath &path) const; + }; }