2012-11-27 19:08:31 +04:00
|
|
|
#include "moses/TranslationModel/PhraseDictionaryDynSuffixArray.h"
|
|
|
|
#include "moses/FactorCollection.h"
|
|
|
|
#include "moses/StaticData.h"
|
|
|
|
#include "moses/TargetPhrase.h"
|
2010-02-12 14:05:43 +03:00
|
|
|
#include <iomanip>
|
2013-06-05 13:46:42 +04:00
|
|
|
#include <boost/foreach.hpp>
|
2010-04-07 15:02:04 +04:00
|
|
|
using namespace std;
|
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
namespace Moses
|
2010-04-08 18:52:35 +04:00
|
|
|
{
|
2013-06-05 13:46:42 +04:00
|
|
|
PhraseDictionaryDynSuffixArray::
|
|
|
|
PhraseDictionaryDynSuffixArray(const std::string &line)
|
2013-10-29 22:20:55 +04:00
|
|
|
: PhraseDictionary(line)
|
2013-06-26 20:19:09 +04:00
|
|
|
,m_biSA(new BilingualDynSuffixArray())
|
2011-02-24 16:14:42 +03:00
|
|
|
{
|
2013-06-26 20:19:09 +04:00
|
|
|
ReadParameters();
|
2010-02-12 14:05:43 +03:00
|
|
|
}
|
2010-04-08 18:52:35 +04:00
|
|
|
|
|
|
|
|
2013-09-27 12:35:24 +04:00
|
|
|
void
|
2013-09-25 03:03:46 +04:00
|
|
|
PhraseDictionaryDynSuffixArray::
|
|
|
|
Load()
|
2010-02-12 14:05:43 +03:00
|
|
|
{
|
2013-06-26 20:12:22 +04:00
|
|
|
SetFeaturesToApply();
|
2010-02-12 14:05:43 +03:00
|
|
|
|
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);
|
2010-02-12 14:05:43 +03:00
|
|
|
}
|
2010-04-08 18:52:35 +04:00
|
|
|
|
2013-06-05 13:46:42 +04:00
|
|
|
PhraseDictionaryDynSuffixArray::
|
|
|
|
~PhraseDictionaryDynSuffixArray()
|
2011-02-24 16:14:42 +03:00
|
|
|
{
|
2013-06-05 13:46:42 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-05 13:46:42 +04:00
|
|
|
const TargetPhraseCollection*
|
|
|
|
PhraseDictionaryDynSuffixArray::
|
2013-08-24 00:02:03 +04:00
|
|
|
GetTargetPhraseCollectionLEGACY(const Phrase& src) const
|
2013-06-05 13:46:42 +04:00
|
|
|
{
|
2013-06-26 20:19:09 +04:00
|
|
|
typedef map<SAPhrase, vector<float> >::value_type pstat_entry;
|
2013-06-05 13:46:42 +04:00
|
|
|
map<SAPhrase, vector<float> > pstats; // phrase (pair) statistics
|
|
|
|
m_biSA->GatherCands(src,pstats);
|
2013-05-02 21:36:34 +04:00
|
|
|
|
2013-06-05 13:46:42 +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);
|
2013-07-28 19:37:20 +04:00
|
|
|
tp->Evaluate(src);
|
2013-06-26 20:19:09 +04:00
|
|
|
ret->Add(tp);
|
|
|
|
}
|
2013-06-05 13:46:42 +04:00
|
|
|
// 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
|
2011-02-24 16:14:42 +03:00
|
|
|
return ret;
|
2010-02-12 14:05:43 +03:00
|
|
|
}
|
2011-02-24 16:14:42 +03:00
|
|
|
|
2013-06-26 20:19:09 +04:00
|
|
|
void
|
2013-06-05 13:46:42 +04:00
|
|
|
PhraseDictionaryDynSuffixArray::
|
|
|
|
insertSnt(string& source, string& target, string& alignment)
|
2011-02-24 16:14:42 +03:00
|
|
|
{
|
2011-05-31 13:43:17 +04:00
|
|
|
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
|
2010-05-07 13:50:19 +04:00
|
|
|
}
|
2013-06-05 13:46:42 +04:00
|
|
|
|
2013-06-26 20:19:09 +04:00
|
|
|
void
|
2013-06-05 13:46:42 +04:00
|
|
|
PhraseDictionaryDynSuffixArray::
|
|
|
|
deleteSnt(unsigned /* idx */, unsigned /* num2Del */)
|
2011-02-24 16:14:42 +03:00
|
|
|
{
|
|
|
|
// need to implement --
|
2010-05-07 13:50:19 +04:00
|
|
|
}
|
2010-02-12 14:05:43 +03:00
|
|
|
|
2013-06-05 13:46:42 +04:00
|
|
|
ChartRuleLookupManager*
|
|
|
|
PhraseDictionaryDynSuffixArray::
|
2013-07-31 15:25:34 +04:00
|
|
|
CreateRuleLookupManager(const ChartParser &, const ChartCellCollectionBase&)
|
2011-02-24 16:14:42 +03:00
|
|
|
{
|
2013-11-19 22:52:15 +04:00
|
|
|
UTIL_THROW(util::Exception, "SCFG decoding not supported with dynamic suffix array");
|
2011-01-24 22:14:19 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-12 14:05:43 +03:00
|
|
|
}// end namepsace
|