find all target phrases before search

This commit is contained in:
Hieu Hoang 2013-06-28 17:40:22 +01:00
parent 2b357f91e3
commit d2e37b701b
4 changed files with 49 additions and 6 deletions

View File

@ -39,9 +39,9 @@ using namespace std;
namespace Moses
{
const TargetPhraseCollection *InputLatticeNode::GetTargetPhrases(const PhraseDictionary *phraseDictionary) const {
const TargetPhraseCollection *InputLatticeNode::GetTargetPhrases(const PhraseDictionary &phraseDictionary) const {
std::map<const PhraseDictionary*, const TargetPhraseCollection *>::const_iterator iter;
iter = m_targetPhrases.find(phraseDictionary);
iter = m_targetPhrases.find(&phraseDictionary);
CHECK(iter != m_targetPhrases.end());
return iter->second;
}
@ -584,5 +584,39 @@ const TranslationOptionList &TranslationOptionCollection::GetTranslationOptionLi
return m_collection[startPos][maxSize];
}
void TranslationOptionCollection::SetTargetPhraseFromPtMatrix()
{
const vector <DecodeGraph*> &decodeGraphList = StaticData::Instance().GetDecodeGraphs();
for (size_t graphInd = 0 ; graphInd < decodeGraphList.size() ; graphInd++) {
const DecodeGraph &decodeGraph = *decodeGraphList[graphInd];
list <const DecodeStep* >::const_iterator iterStep;
for (iterStep = decodeGraph.begin(); iterStep != decodeGraph.end() ; ++iterStep) {
const DecodeStep &decodeStep = **iterStep;
const DecodeStepTranslation *transStep = dynamic_cast<const DecodeStepTranslation *>(&decodeStep);
if (transStep) {
const PhraseDictionary &phraseDictionary = *transStep->GetPhraseDictionaryFeature();
SetTargetPhraseFromPtMatrix(phraseDictionary);
}
}
}
}
void TranslationOptionCollection::SetTargetPhraseFromPtMatrix(const PhraseDictionary &phraseDictionary)
{
for (size_t i = 0; i < m_phraseDictionaryQueue.size(); ++i) {
InputLatticeNode &node = *m_phraseDictionaryQueue[i];
bool doIt = true;
doIt = true; // TODO HACK
if (doIt) {
const Phrase &phrase = node.GetPhrase();
const TargetPhraseCollection *targetPhrases = phraseDictionary.GetTargetPhraseCollection(phrase);
node.SetTargetPhrases(phraseDictionary, targetPhrases);
}
}
}
}

View File

@ -73,10 +73,10 @@ public:
return m_range;
}
void SetTargetPhrases(const PhraseDictionary *phraseDictionary, const TargetPhraseCollection *targetPhrases) {
m_targetPhrases[phraseDictionary] = targetPhrases;
void SetTargetPhrases(const PhraseDictionary &phraseDictionary, const TargetPhraseCollection *targetPhrases) {
m_targetPhrases[&phraseDictionary] = targetPhrases;
}
const TargetPhraseCollection *GetTargetPhrases(const PhraseDictionary *phraseDictionary) const;
const TargetPhraseCollection *GetTargetPhrases(const PhraseDictionary &phraseDictionary) const;
};
@ -135,6 +135,8 @@ protected:
void CacheLexReordering();
void SetTargetPhraseFromPtMatrix();
void SetTargetPhraseFromPtMatrix(const PhraseDictionary &phraseDictionary);
public:
virtual ~TranslationOptionCollection();

View File

@ -56,7 +56,6 @@ TranslationOptionCollectionText::TranslationOptionCollectionText(Sentence const
m_phraseDictionaryQueue.push_back(&node);
}
}
}
/* forcibly create translation option for a particular source word.
@ -102,6 +101,12 @@ InputLatticeNode &TranslationOptionCollectionText::GetInputLatticeNode(size_t st
return m_targetPhrasesfromPt[startPos][offset];
}
void TranslationOptionCollectionText::CreateTranslationOptions()
{
SetTargetPhraseFromPtMatrix();
TranslationOptionCollection::CreateTranslationOptions();
}
/** create translation options that exactly cover a specific input span.
* Called by CreateTranslationOptions() and ProcessUnknownWord()
* \param decodeGraph list of decoding steps

View File

@ -53,6 +53,8 @@ public:
void CreateXmlOptionsForRange(size_t startPosition, size_t endPosition);
void CreateTranslationOptions();
void CreateTranslationOptionsForRange(const DecodeGraph &decodeStepList
, size_t startPosition
, size_t endPosition