mosesdecoder/moses/TranslationModel/PhraseDictionaryDynSuffixArray.cpp

111 lines
3.0 KiB
C++
Raw Normal View History

#include "moses/TranslationModel/PhraseDictionaryDynSuffixArray.h"
#include "moses/FactorCollection.h"
#include "moses/StaticData.h"
#include "moses/TargetPhrase.h"
#include <iomanip>
#include <boost/foreach.hpp>
using namespace std;
namespace Moses
{
PhraseDictionaryDynSuffixArray::
PhraseDictionaryDynSuffixArray(const std::string &line)
: PhraseDictionary(line)
2013-06-26 20:19:09 +04:00
,m_biSA(new BilingualDynSuffixArray())
{
2013-06-26 20:19:09 +04:00
ReadParameters();
}
2013-09-27 12:35:24 +04:00
void
2013-09-25 03:03:46 +04:00
PhraseDictionaryDynSuffixArray::
Load()
{
2013-06-26 20:12:22 +04:00
SetFeaturesToApply();
2013-06-26 20:12:22 +04:00
vector<float> weight = StaticData::Instance().GetWeights(this);
m_biSA->Load(m_input, m_output, m_source, m_target, m_alignments, weight);
}
PhraseDictionaryDynSuffixArray::
~PhraseDictionaryDynSuffixArray()
{
delete m_biSA;
}
2013-05-02 21:36:34 +04:00
2013-09-27 12:35:24 +04:00
void
2013-09-25 03:03:46 +04:00
PhraseDictionaryDynSuffixArray::
SetParameter(const std::string& key, const std::string& value)
2013-06-26 20:12:22 +04:00
{
if (key == "source") {
m_source = value;
} else if (key == "target") {
m_target = value;
} else if (key == "alignment") {
m_alignments = value;
} else {
PhraseDictionary::SetParameter(key, value);
}
}
const TargetPhraseCollection*
PhraseDictionaryDynSuffixArray::
GetTargetPhraseCollectionLEGACY(const Phrase& src) const
{
2013-06-26 20:19:09 +04:00
typedef map<SAPhrase, vector<float> >::value_type pstat_entry;
map<SAPhrase, vector<float> > pstats; // phrase (pair) statistics
m_biSA->GatherCands(src,pstats);
2013-05-02 21:36:34 +04:00
TargetPhraseCollection *ret = new TargetPhraseCollection();
2013-06-26 20:19:09 +04:00
BOOST_FOREACH(pstat_entry & e, pstats) {
TargetPhrase* tp = m_biSA->GetMosesFactorIDs(e.first, src);
tp->GetScoreBreakdown().Assign(this,e.second);
tp->Evaluate(src);
2013-06-26 20:19:09 +04:00
ret->Add(tp);
}
// return ret;
// TargetPhraseCollection *ret = new TargetPhraseCollection();
// std::vector< std::pair< Scores, TargetPhrase*> > trg;
//
// // extract target phrases and their scores from suffix array
// m_biSA->GetTargetPhrasesByLexicalWeight(src, trg);
//
// std::vector< std::pair< Scores, TargetPhrase*> >::iterator itr;
// for(itr = trg.begin(); itr != trg.end(); ++itr) {
// Scores scoreVector = itr->first;
// TargetPhrase *targetPhrase = itr->second;
// std::transform(scoreVector.begin(),scoreVector.end(),
// scoreVector.begin(),FloorScore);
// targetPhrase->GetScoreBreakdown().Assign(this, scoreVector);
// targetPhrase->Evaluate();
// ret->Add(targetPhrase);
// }
ret->NthElement(m_tableLimit); // sort the phrases for the decoder
return ret;
}
2013-06-26 20:19:09 +04:00
void
PhraseDictionaryDynSuffixArray::
insertSnt(string& source, string& target, string& alignment)
{
m_biSA->addSntPair(source, target, alignment); // insert sentence pair into suffix arrays
2013-06-26 20:19:09 +04:00
//StaticData::Instance().ClearTransOptionCache(); // clear translation option cache
}
2013-06-26 20:19:09 +04:00
void
PhraseDictionaryDynSuffixArray::
deleteSnt(unsigned /* idx */, unsigned /* num2Del */)
{
// need to implement --
}
ChartRuleLookupManager*
PhraseDictionaryDynSuffixArray::
CreateRuleLookupManager(const ChartParser &, const ChartCellCollectionBase&, std::size_t)
{
UTIL_THROW(util::Exception, "SCFG decoding not supported with dynamic suffix array");
return 0;
}
}// end namepsace