mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 13:23:25 +03:00
create queue of InputPath objects. Starting SCFG parsing with lattices and conf net
This commit is contained in:
parent
2e6266c85a
commit
1d40a604df
@ -143,6 +143,8 @@ ChartParser::ChartParser(InputType const &source, ChartCellCollectionBase &cells
|
||||
PhraseDictionary *nonConstDict = const_cast<PhraseDictionary*>(dict);
|
||||
m_ruleLookupManagers.push_back(nonConstDict->CreateRuleLookupManager(source, cells));
|
||||
}
|
||||
|
||||
CreateInputPaths(m_source);
|
||||
}
|
||||
|
||||
ChartParser::~ChartParser()
|
||||
@ -177,4 +179,38 @@ void ChartParser::Create(const WordsRange &wordsRange, ChartParserCallback &to)
|
||||
}
|
||||
}
|
||||
|
||||
void ChartParser::CreateInputPaths(const InputType &input)
|
||||
{
|
||||
size_t size = input.GetSize();
|
||||
m_targetPhrasesfromPt.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_targetPhrasesfromPt[startPos];
|
||||
|
||||
Phrase subphrase(input.GetSubString(WordsRange(startPos, endPos)));
|
||||
WordsRange range(startPos, endPos);
|
||||
|
||||
InputPath *node;
|
||||
if (range.GetNumWordsCovered() == 1) {
|
||||
node = new InputPath(subphrase, range, NULL, NULL);
|
||||
vec.push_back(node);
|
||||
} else {
|
||||
const InputPath &prevNode = GetInputPath(startPos, endPos - 1);
|
||||
node = new InputPath(subphrase, range, &prevNode, NULL);
|
||||
vec.push_back(node);
|
||||
}
|
||||
|
||||
m_phraseDictionaryQueue.push_back(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
InputPath &ChartParser::GetInputPath(size_t startPos, size_t endPos)
|
||||
{
|
||||
size_t offset = endPos - startPos;
|
||||
CHECK(offset < m_targetPhrasesfromPt[startPos].size());
|
||||
return *m_targetPhrasesfromPt[startPos][offset];
|
||||
}
|
||||
|
||||
} // namespace Moses
|
||||
|
@ -21,11 +21,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "WordsRange.h"
|
||||
#include "StackVec.h"
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include "WordsRange.h"
|
||||
#include "StackVec.h"
|
||||
#include "InputPath.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
@ -50,7 +50,6 @@ public:
|
||||
private:
|
||||
std::vector<Phrase*> m_unksrcs;
|
||||
std::list<TargetPhraseCollection*> m_cacheTargetPhraseCollection;
|
||||
StackVec m_emptyStackVec;
|
||||
};
|
||||
|
||||
class ChartParser
|
||||
@ -66,6 +65,15 @@ private:
|
||||
std::vector <DecodeGraph*> m_decodeGraphList;
|
||||
std::vector<ChartRuleLookupManager*> m_ruleLookupManagers;
|
||||
InputType const& m_source; /**< source sentence to be translated */
|
||||
|
||||
InputPathList m_phraseDictionaryQueue;
|
||||
|
||||
typedef std::vector< std::vector<InputPath*> > TargetPhraseMatrix;
|
||||
TargetPhraseMatrix m_targetPhrasesfromPt; /*< contains translation options */
|
||||
|
||||
void CreateInputPaths(const InputType &input);
|
||||
InputPath &GetInputPath(size_t startPos, size_t endPos);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user