push InpuutPath down into phrase dictionary for legacy methods

This commit is contained in:
Hieu Hoang 2013-08-06 17:09:53 +01:00
parent 646cf93c1f
commit 7a808a2edb
5 changed files with 56 additions and 1 deletions

View File

@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "TranslationOptionCollection.h"
#include "PartialTranslOptColl.h"
#include "FactorCollection.h"
#include "util/exception.hh"
using namespace std;
@ -214,7 +215,11 @@ void DecodeStepTranslation::ProcessInitialTranslationLegacy(
for (iterTargetPhrase = phraseColl->begin() ; iterTargetPhrase != iterEnd ; ++iterTargetPhrase) {
const TargetPhrase &targetPhrase = **iterTargetPhrase;
const InputPath &inputPath = GetInputPathLegacy(targetPhrase, inputPathList);
TranslationOption *transOpt = new TranslationOption(wordsRange, targetPhrase);
transOpt->SetSourcePhrase(inputPath.GetPhrase());
outputPartialTranslOptColl.Add (transOpt);
@ -224,6 +229,27 @@ void DecodeStepTranslation::ProcessInitialTranslationLegacy(
}
}
const InputPath &DecodeStepTranslation::GetInputPathLegacy(const TargetPhrase targetPhrase,
const InputPathList &inputPathList) const
{
const Phrase &phraseFromTP = targetPhrase.GetSourcePhrase();
const Word &wordTP = phraseFromTP.GetWord(0);
InputPathList::const_iterator iter;
for (iter = inputPathList.begin(); iter != inputPathList.end(); ++iter) {
const InputPath &inputPath = **iter;
const Phrase &phraseFromIP = inputPath.GetPhrase();
const Word &wordIP = phraseFromIP.GetWord(0);
const WordsRange &range = inputPath.GetWordsRange();
if (wordTP == wordIP) {
return inputPath;
}
}
UTIL_THROW(util::Exception, "Input path not found");
}
}

View File

@ -71,6 +71,11 @@ public:
, const InputPathList &inputPathList) const;
private:
// I'm not sure whether this actually works or not for binary phrase table.
// The source phrase only appears to contain the 1st word, therefore, this function
// only compares the 1st word
const InputPath &GetInputPathLegacy(const TargetPhrase targetPhrase,
const InputPathList &inputPathList) const;
};

View File

@ -46,13 +46,24 @@ class PartialTranslOptColl
friend std::ostream& operator<<(std::ostream& out, const PartialTranslOptColl& possibleTranslation);
protected:
std::vector<TranslationOption*> m_list;
typedef std::vector<TranslationOption*> Coll;
Coll m_list;
float m_bestScore; /**< score of the best translation option */
float m_worstScore; /**< score of the worse translation option */
size_t m_maxSize; /**< maximum number of translation options allowed */
size_t m_totalPruned; /**< number of options pruned */
public:
typedef Coll::iterator iterator;
typedef Coll::const_iterator const_iterator;
const_iterator begin() const {
return m_list.begin();
}
const_iterator end() const {
return m_list.end();
}
PartialTranslOptColl();
/** destructor, cleans out list */

View File

@ -101,6 +101,11 @@ public:
return m_targetPhrase.GetSourcePhrase();
}
void SetSourcePhrase(const Phrase &sourcePhrase)
{
// TODO
}
/** whether source span overlaps with those of a hypothesis */
bool Overlap(const Hypothesis &hypothesis) const;

View File

@ -205,6 +205,14 @@ void TranslationOptionCollectionConfusionNet::CreateTranslationOptionsForRangeLe
(m_source, *oldPtoc
, startPos, endPos, adhereTableLimit, inputPathList );
PartialTranslOptColl::const_iterator iter;
for (iter = oldPtoc->begin(); iter != oldPtoc->end(); ++iter) {
TranslationOption &transOpt = **iter;
const TargetPhrase &tp = transOpt.GetTargetPhrase();
const Phrase &sp = tp.GetSourcePhrase();
cerr << "sp=" << sp << endl;
}
// do rest of decode steps
int indexStep = 0;