Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHieu Hoang <hieu@hoang.co.uk>2013-08-09 00:29:22 +0400
committerHieu Hoang <hieu@hoang.co.uk>2013-08-09 00:29:22 +0400
commit59e7a179cafd61aaaefd1ec91e248617d40e14bc (patch)
treedb6b101bfbbbd8b265e73e9dd61d58657e8647a9
parent15132a04aab28bc01200652a1ca06be528523fda (diff)
add InputPath objects of chart decoding. Start on lattice input for chart decoding
-rw-r--r--moses/ChartManager.cpp3
-rw-r--r--moses/ChartTranslationOptionList.cpp52
-rw-r--r--moses/ChartTranslationOptionList.h11
3 files changed, 62 insertions, 4 deletions
diff --git a/moses/ChartManager.cpp b/moses/ChartManager.cpp
index 2ff1be8f1..faecb181e 100644
--- a/moses/ChartManager.cpp
+++ b/moses/ChartManager.cpp
@@ -50,7 +50,7 @@ ChartManager::ChartManager(InputType const& source)
,m_start(clock())
,m_hypothesisId(0)
,m_parser(source, m_hypoStackColl)
- ,m_translationOptionList(StaticData::Instance().GetRuleLimit())
+ ,m_translationOptionList(StaticData::Instance().GetRuleLimit(), source)
{
}
@@ -342,5 +342,4 @@ void ChartManager::CreateDeviantPaths(
}
}
-
} // namespace Moses
diff --git a/moses/ChartTranslationOptionList.cpp b/moses/ChartTranslationOptionList.cpp
index 5b72ea7a3..73711f3fe 100644
--- a/moses/ChartTranslationOptionList.cpp
+++ b/moses/ChartTranslationOptionList.cpp
@@ -19,25 +19,68 @@
#include <algorithm>
#include <iostream>
+#include <vector>
#include "StaticData.h"
#include "ChartTranslationOptionList.h"
#include "ChartTranslationOptions.h"
#include "ChartCellCollection.h"
#include "WordsRange.h"
+#include "InputType.h"
+#include "InputPath.h"
+
+using namespace std;
namespace Moses
{
-ChartTranslationOptionList::ChartTranslationOptionList(size_t ruleLimit)
+ChartTranslationOptionList::ChartTranslationOptionList(size_t ruleLimit, const InputType &input)
: m_size(0)
, m_ruleLimit(ruleLimit)
{
m_scoreThreshold = std::numeric_limits<float>::infinity();
+
+ // create input paths
+ size_t size = input.GetSize();
+ m_inputPathMatrix.resize(size);
+ for (size_t phaseSize = 1; phaseSize <= size; ++phaseSize) {
+ for (size_t startPos = 0; startPos < size - phaseSize + 1; ++startPos) {
+ size_t endPos = startPos + phaseSize -1;
+ vector<InputPath*> &vec = m_inputPathMatrix[startPos];
+
+ WordsRange range(startPos, endPos);
+ Phrase subphrase(input.GetSubString(WordsRange(startPos, endPos)));
+ const NonTerminalSet &labels = input.GetLabelSet(startPos, endPos);
+
+ InputPath *node;
+ if (range.GetNumWordsCovered() == 1) {
+ node = new InputPath(subphrase, labels, range, NULL, NULL);
+ vec.push_back(node);
+ } else {
+ const InputPath &prevNode = GetInputPath(startPos, endPos - 1);
+ node = new InputPath(subphrase, labels, range, &prevNode, NULL);
+ vec.push_back(node);
+ }
+
+ //m_phraseDictionaryQueue.push_back(node);
+ }
+ }
+
}
ChartTranslationOptionList::~ChartTranslationOptionList()
{
RemoveAllInColl(m_collection);
+
+ InputPathMatrix::const_iterator iterOuter;
+ for (iterOuter = m_inputPathMatrix.begin(); iterOuter != m_inputPathMatrix.end(); ++iterOuter) {
+ const std::vector<InputPath*> &outer = *iterOuter;
+
+ std::vector<InputPath*>::const_iterator iterInner;
+ for (iterInner = outer.begin(); iterInner != outer.end(); ++iterInner) {
+ InputPath *path = *iterInner;
+ delete path;
+ }
+ }
}
void ChartTranslationOptionList::Clear()
@@ -142,4 +185,11 @@ void ChartTranslationOptionList::ApplyThreshold()
m_size = std::distance(m_collection.begin(), bound);
}
+InputPath &ChartTranslationOptionList::GetInputPath(size_t startPos, size_t endPos)
+{
+ size_t offset = endPos - startPos;
+ CHECK(offset < m_inputPathMatrix[startPos].size());
+ return *m_inputPathMatrix[startPos][offset];
+}
+
}
diff --git a/moses/ChartTranslationOptionList.h b/moses/ChartTranslationOptionList.h
index a2979fcbc..daa9d05ba 100644
--- a/moses/ChartTranslationOptionList.h
+++ b/moses/ChartTranslationOptionList.h
@@ -30,12 +30,14 @@ namespace Moses
class TargetPhraseCollection;
class WordsRange;
+class InputType;
+class InputPath;
//! a vector of translations options for a specific range, in a specific sentence
class ChartTranslationOptionList : public ChartParserCallback
{
public:
- ChartTranslationOptionList(size_t);
+ ChartTranslationOptionList(size_t ruleLimit, const InputType &input);
~ChartTranslationOptionList();
const ChartTranslationOptions &Get(size_t i) const {
@@ -74,6 +76,13 @@ private:
size_t m_size;
float m_scoreThreshold;
const size_t m_ruleLimit;
+
+ // input paths
+ typedef std::vector< std::vector<InputPath*> > InputPathMatrix;
+ InputPathMatrix m_inputPathMatrix; /*< contains translation options */
+
+ InputPath &GetInputPath(size_t startPos, size_t endPos);
+
};
}