#include "moses/TranslationModel/PhraseDictionaryDynSuffixArray.h" #include "moses/FactorCollection.h" #include "moses/StaticData.h" #include "moses/TargetPhrase.h" #include using namespace std; namespace Moses { PhraseDictionaryDynSuffixArray::PhraseDictionaryDynSuffixArray(size_t numScoreComponent, PhraseDictionaryFeature* feature): PhraseDictionary(numScoreComponent, feature) { m_biSA = new BilingualDynSuffixArray(); } PhraseDictionaryDynSuffixArray::~PhraseDictionaryDynSuffixArray() { delete m_biSA; } bool PhraseDictionaryDynSuffixArray::Load(const std::vector& input, const std::vector& output, string source, string target, string alignments, const std::vector &weight, size_t tableLimit, const LMList &languageModels, float weightWP) { m_tableLimit = tableLimit; m_languageModels = &languageModels; m_weight = weight; m_weightWP = weightWP; m_biSA->Load( input, output, source, target, alignments, weight); return true; } void PhraseDictionaryDynSuffixArray::InitializeForInput(const InputType& input) { CHECK(&input == &input); } 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); 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); targetPhrase->SetScore(m_feature, scoreVector, ScoreComponentCollection(), m_weight, m_weightWP, *m_languageModels); //cout << *targetPhrase << "\t" << std::setprecision(8) << scoreVector[2] << endl; ret->Add(targetPhrase); } ret->NthElement(m_tableLimit); // sort the phrases for the dcoder return ret; } void PhraseDictionaryDynSuffixArray::insertSnt(string& source, string& target, string& alignment) { m_biSA->addSntPair(source, target, alignment); // insert sentence pair into suffix arrays //StaticData::Instance().ClearTransOptionCache(); // clear translation option cache } void PhraseDictionaryDynSuffixArray::deleteSnt(unsigned /* idx */, unsigned /* num2Del */) { // need to implement -- } ChartRuleLookupManager *PhraseDictionaryDynSuffixArray::CreateRuleLookupManager(const InputType&, const ChartCellCollectionBase&) { CHECK(false); return 0; } }// end namepsace