mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 05:14:36 +03:00
Make ChartParser accept ChartParserCallback
This commit is contained in:
parent
ba1915bcf7
commit
7a5976b721
2
lazy
2
lazy
@ -1 +1 @@
|
||||
Subproject commit 6a73b80f054c61785497c09abc8091098b83bfb9
|
||||
Subproject commit 02625f416da85bad8641437d553f350f96ed4559
|
@ -153,11 +153,9 @@ ChartParser::~ChartParser() {
|
||||
RemoveAllInColl(m_ruleLookupManagers);
|
||||
}
|
||||
|
||||
void ChartParser::Create(const WordsRange &wordsRange, ChartTranslationOptionList &to) {
|
||||
void ChartParser::Create(const WordsRange &wordsRange, ChartParserCallback &to) {
|
||||
assert(m_decodeGraphList.size() == m_ruleLookupManagers.size());
|
||||
|
||||
to.Clear();
|
||||
|
||||
|
||||
std::vector <DecodeGraph*>::const_iterator iterDecodeGraph;
|
||||
std::vector <ChartRuleLookupManager*>::const_iterator iterRuleLookupManagers = m_ruleLookupManagers.begin();
|
||||
for (iterDecodeGraph = m_decodeGraphList.begin(); iterDecodeGraph != m_decodeGraphList.end(); ++iterDecodeGraph, ++iterRuleLookupManagers) {
|
||||
@ -172,14 +170,12 @@ void ChartParser::Create(const WordsRange &wordsRange, ChartTranslationOptionLis
|
||||
|
||||
if (wordsRange.GetNumWordsCovered() == 1 && wordsRange.GetStartPos() != 0 && wordsRange.GetStartPos() != m_source.GetSize()-1) {
|
||||
bool alwaysCreateDirectTranslationOption = StaticData::Instance().IsAlwaysCreateDirectTranslationOption();
|
||||
if (to.GetSize() == 0 || alwaysCreateDirectTranslationOption) {
|
||||
if (to.Empty() || alwaysCreateDirectTranslationOption) {
|
||||
// create unknown words for 1 word coverage where we don't have any trans options
|
||||
const Word &sourceWord = m_source.GetWord(wordsRange.GetStartPos());
|
||||
m_unknown.Process(sourceWord, wordsRange, to);
|
||||
}
|
||||
}
|
||||
|
||||
to.ApplyThreshold();
|
||||
}
|
||||
}
|
||||
|
||||
/* constructor. Initialize everything prior to decoding a particular sentence.
|
||||
@ -229,7 +225,9 @@ void ChartManager::ProcessSentence()
|
||||
WordsRange range(startPos, endPos);
|
||||
|
||||
// create trans opt
|
||||
m_translationOptionList.Clear();
|
||||
m_parser.Create(range, m_translationOptionList);
|
||||
m_translationOptionList.ApplyThreshold();
|
||||
|
||||
// decode
|
||||
ChartCell &cell = m_hypoStackColl.Get(range);
|
||||
|
@ -61,7 +61,7 @@ class ChartParser {
|
||||
ChartParser(InputType const &source, const TranslationSystem &system, ChartCellCollection &cells);
|
||||
~ChartParser();
|
||||
|
||||
void Create(const WordsRange &range, ChartTranslationOptionList &to);
|
||||
void Create(const WordsRange &range, ChartParserCallback &to);
|
||||
|
||||
private:
|
||||
ChartParserUnknown m_unknown;
|
||||
|
@ -12,6 +12,8 @@ class ChartParserCallback {
|
||||
virtual ~ChartParserCallback() {}
|
||||
|
||||
virtual void Add(const TargetPhraseCollection &, const StackVec &, const WordsRange &) = 0;
|
||||
|
||||
virtual bool Empty() const = 0;
|
||||
};
|
||||
|
||||
} // namespace Moses
|
||||
|
@ -45,6 +45,8 @@ class ChartTranslationOptionList : public ChartParserCallback {
|
||||
void Add(const TargetPhraseCollection &, const StackVec &,
|
||||
const WordsRange &);
|
||||
|
||||
bool Empty() const { return m_size == 0; }
|
||||
|
||||
void Clear();
|
||||
void ApplyThreshold();
|
||||
|
||||
|
@ -33,6 +33,8 @@ template <class Model> class Fill : public ChartParserCallback {
|
||||
|
||||
void Add(const TargetPhraseCollection &targets, const StackVec &nts, const WordsRange &ignored);
|
||||
|
||||
bool Empty() const { return edges_.Empty(); }
|
||||
|
||||
void Search(ChartCellLabelSet &out);
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user