mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2025-01-03 17:33:52 +03:00
moses_chart: simplify ChartTranslationOptionCollection a bit.
This commit is contained in:
parent
0fcb87629b
commit
7cdc0b26c0
@ -66,12 +66,12 @@ void ChartTranslationOptionCollection::CreateTranslationOptionsForRange(
|
||||
ChartTranslationOptionList &chartRuleColl = GetTranslationOptionList(startPos, endPos);
|
||||
const WordsRange &wordsRange = chartRuleColl.GetSourceRange();
|
||||
|
||||
CHECK(m_decodeGraphList.size() == m_ruleLookupManagers.size());
|
||||
assert(m_decodeGraphList.size() == m_ruleLookupManagers.size());
|
||||
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) {
|
||||
const DecodeGraph &decodeGraph = **iterDecodeGraph;
|
||||
CHECK(decodeGraph.GetSize() == 1);
|
||||
assert(decodeGraph.GetSize() == 1);
|
||||
ChartRuleLookupManager &ruleLookupManager = **iterRuleLookupManagers;
|
||||
size_t maxSpan = decodeGraph.GetMaxChartSpan();
|
||||
if (maxSpan == 0 || (endPos-startPos+1) <= maxSpan) {
|
||||
@ -79,50 +79,18 @@ void ChartTranslationOptionCollection::CreateTranslationOptionsForRange(
|
||||
}
|
||||
}
|
||||
|
||||
ProcessUnknownWord(startPos, endPos);
|
||||
|
||||
Prune(startPos, endPos);
|
||||
|
||||
Sort(startPos, endPos);
|
||||
|
||||
}
|
||||
|
||||
//! Force a creation of a translation option where there are none for a particular source position.
|
||||
void ChartTranslationOptionCollection::ProcessUnknownWord(size_t startPos, size_t endPos)
|
||||
{
|
||||
if (startPos != endPos) {
|
||||
// only for 1 word phrases
|
||||
return;
|
||||
}
|
||||
|
||||
if (startPos == 0 || startPos == m_source.GetSize() - 1)
|
||||
{ // don't create unknown words for <S> or </S> tags. Otherwise they can be moved. Should only be translated by glue rules
|
||||
return;
|
||||
}
|
||||
|
||||
ChartTranslationOptionList &fullList = GetTranslationOptionList(startPos, startPos);
|
||||
const WordsRange &wordsRange = fullList.GetSourceRange();
|
||||
|
||||
// try to translation for coverage with no trans by expanding table limit
|
||||
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) {
|
||||
//const DecodeGraph &decodeGraph = **iterDecodeGraph;
|
||||
ChartRuleLookupManager &ruleLookupManager = **iterRuleLookupManagers;
|
||||
size_t numTransOpt = fullList.GetSize();
|
||||
if (numTransOpt == 0) {
|
||||
ruleLookupManager.GetChartRuleCollection(wordsRange, fullList);
|
||||
if (startPos == endPos && startPos != 0 && startPos != m_source.GetSize()-1) {
|
||||
bool alwaysCreateDirectTranslationOption = StaticData::Instance().IsAlwaysCreateDirectTranslationOption();
|
||||
if (chartRuleColl.GetSize() == 0 || alwaysCreateDirectTranslationOption) {
|
||||
// create unknown words for 1 word coverage where we don't have any trans options
|
||||
const Word &sourceWord = m_source.GetWord(startPos);
|
||||
ProcessOneUnknownWord(sourceWord, startPos);
|
||||
}
|
||||
}
|
||||
CHECK(iterRuleLookupManagers == m_ruleLookupManagers.end());
|
||||
|
||||
bool alwaysCreateDirectTranslationOption = StaticData::Instance().IsAlwaysCreateDirectTranslationOption();
|
||||
// create unknown words for 1 word coverage where we don't have any trans options
|
||||
if (fullList.GetSize() == 0 || alwaysCreateDirectTranslationOption)
|
||||
ProcessUnknownWord(startPos);
|
||||
Sort(startPos, endPos);
|
||||
}
|
||||
|
||||
|
||||
ChartTranslationOptionList &ChartTranslationOptionCollection::GetTranslationOptionList(size_t startPos, size_t endPos)
|
||||
{
|
||||
size_t sizeVec = m_collection[startPos].size();
|
||||
@ -153,13 +121,6 @@ std::ostream& operator<<(std::ostream &out, const ChartTranslationOptionCollecti
|
||||
return out;
|
||||
}
|
||||
|
||||
// taken from ChartTranslationOptionCollectionText.
|
||||
void ChartTranslationOptionCollection::ProcessUnknownWord(size_t sourcePos)
|
||||
{
|
||||
const Word &sourceWord = m_source.GetWord(sourcePos);
|
||||
ProcessOneUnknownWord(sourceWord,sourcePos);
|
||||
}
|
||||
|
||||
//! special handling of ONE unknown words.
|
||||
void ChartTranslationOptionCollection::ProcessOneUnknownWord(const Word &sourceWord, size_t sourcePos, size_t /* length */)
|
||||
{
|
||||
@ -262,18 +223,6 @@ void ChartTranslationOptionCollection::ProcessOneUnknownWord(const Word &sourceW
|
||||
}
|
||||
}
|
||||
|
||||
void ChartTranslationOptionCollection::Add(ChartTranslationOption *transOpt, size_t pos)
|
||||
{
|
||||
ChartTranslationOptionList &transOptList = GetTranslationOptionList(pos, pos);
|
||||
transOptList.Add(transOpt);
|
||||
}
|
||||
|
||||
//! pruning: only keep the top n (m_maxNoTransOptPerCoverage) elements */
|
||||
void ChartTranslationOptionCollection::Prune(size_t /* startPos */, size_t /* endPos */)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//! sort all trans opt in each list for cube pruning */
|
||||
void ChartTranslationOptionCollection::Sort(size_t startPos, size_t endPos)
|
||||
{
|
||||
|
@ -51,24 +51,14 @@ protected:
|
||||
std::list<TargetPhraseCollection*> m_cacheTargetPhraseCollection;
|
||||
StackVec m_emptyStackVec;
|
||||
|
||||
// for adding 1 trans opt in unknown word proc
|
||||
void Add(ChartTranslationOption *transOpt, size_t pos);
|
||||
|
||||
ChartTranslationOptionList &GetTranslationOptionList(size_t startPos, size_t endPos);
|
||||
const ChartTranslationOptionList &GetTranslationOptionList(size_t startPos, size_t endPos) const;
|
||||
|
||||
void ProcessUnknownWord(size_t startPos, size_t endPos);
|
||||
|
||||
// taken from ChartTranslationOptionCollectionText.
|
||||
void ProcessUnknownWord(size_t sourcePos);
|
||||
|
||||
//! special handling of ONE unknown words.
|
||||
virtual void ProcessOneUnknownWord(const Word &sourceWord
|
||||
, size_t sourcePos, size_t length = 1);
|
||||
|
||||
//! pruning: only keep the top n (m_maxNoTransOptPerCoverage) elements */
|
||||
void Prune(size_t startPos, size_t endPos);
|
||||
|
||||
//! sort all trans opt in each list for cube pruning */
|
||||
void Sort(size_t startPos, size_t endPos);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user