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>
|
|
|
|
|
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
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
PhraseDictionaryDynSuffixArray::PhraseDictionaryDynSuffixArray(size_t numScoreComponent,
|
|
|
|
PhraseDictionaryFeature* feature): PhraseDictionary(numScoreComponent, feature)
|
|
|
|
{
|
|
|
|
m_biSA = new BilingualDynSuffixArray();
|
2010-02-12 14:05:43 +03:00
|
|
|
}
|
2010-04-08 18:52:35 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
PhraseDictionaryDynSuffixArray::~PhraseDictionaryDynSuffixArray()
|
2010-04-08 18:52:35 +04:00
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
delete m_biSA;
|
2010-02-12 14:05:43 +03:00
|
|
|
}
|
2010-04-08 18:52:35 +04:00
|
|
|
|
2010-04-20 18:09:53 +04:00
|
|
|
bool PhraseDictionaryDynSuffixArray::Load(const std::vector<FactorType>& input,
|
2011-02-24 16:14:42 +03:00
|
|
|
const std::vector<FactorType>& output,
|
|
|
|
string source, string target, string alignments,
|
|
|
|
const std::vector<float> &weight,
|
|
|
|
size_t tableLimit,
|
|
|
|
const LMList &languageModels,
|
|
|
|
float weightWP)
|
2010-02-12 14:05:43 +03:00
|
|
|
{
|
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
m_tableLimit = tableLimit;
|
|
|
|
m_languageModels = &languageModels;
|
2010-05-19 20:37:57 +04:00
|
|
|
m_weight = weight;
|
2011-02-24 16:14:42 +03:00
|
|
|
m_weightWP = weightWP;
|
2010-04-20 18:09:53 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
m_biSA->Load( input, output, source, target, alignments, weight);
|
2010-02-12 14:05:43 +03:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
return true;
|
2010-02-12 14:05:43 +03:00
|
|
|
}
|
2010-04-08 18:52:35 +04:00
|
|
|
|
2010-02-12 14:05:43 +03:00
|
|
|
void PhraseDictionaryDynSuffixArray::InitializeForInput(const InputType& input)
|
|
|
|
{
|
2011-11-18 16:07:41 +04:00
|
|
|
CHECK(&input == &input);
|
2010-02-12 14:05:43 +03:00
|
|
|
}
|
2010-04-08 18:52:35 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
const TargetPhraseCollection *PhraseDictionaryDynSuffixArray::GetTargetPhraseCollection(const Phrase& src) const
|
|
|
|
{
|
|
|
|
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);
|
2010-04-08 18:52:35 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
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(),NegateScore);
|
|
|
|
std::transform(scoreVector.begin(),scoreVector.end(),scoreVector.begin(),FloorScore);
|
2011-09-20 19:32:26 +04:00
|
|
|
targetPhrase->SetScore(m_feature, scoreVector, ScoreComponentCollection(), m_weight, m_weightWP, *m_languageModels);
|
2011-06-08 19:05:19 +04:00
|
|
|
//cout << *targetPhrase << "\t" << std::setprecision(8) << scoreVector[2] << endl;
|
2011-02-24 16:14:42 +03:00
|
|
|
ret->Add(targetPhrase);
|
|
|
|
}
|
|
|
|
ret->NthElement(m_tableLimit); // sort the phrases for the dcoder
|
|
|
|
return ret;
|
2010-02-12 14:05:43 +03:00
|
|
|
}
|
2011-02-24 16:14:42 +03:00
|
|
|
|
|
|
|
void PhraseDictionaryDynSuffixArray::insertSnt(string& source, string& target, string& alignment)
|
|
|
|
{
|
2011-05-31 13:43:17 +04:00
|
|
|
m_biSA->addSntPair(source, target, alignment); // insert sentence pair into suffix arrays
|
2011-06-24 12:12:50 +04:00
|
|
|
//StaticData::Instance().ClearTransOptionCache(); // clear translation option cache
|
2010-05-07 13:50:19 +04:00
|
|
|
}
|
2011-02-24 19:17:38 +03:00
|
|
|
void 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
|
|
|
|
2012-10-11 17:27:30 +04:00
|
|
|
ChartRuleLookupManager *PhraseDictionaryDynSuffixArray::CreateRuleLookupManager(const InputType&, const ChartCellCollectionBase&)
|
2011-02-24 16:14:42 +03:00
|
|
|
{
|
2011-11-18 16:07:41 +04:00
|
|
|
CHECK(false);
|
2011-01-24 22:14:19 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-12 14:05:43 +03:00
|
|
|
}// end namepsace
|