2008-06-11 14:52:57 +04:00
|
|
|
// $Id$
|
|
|
|
|
2012-11-27 19:08:31 +04:00
|
|
|
#include "moses/TranslationModel/PhraseDictionaryTreeAdaptor.h"
|
2008-06-11 14:52:57 +04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <algorithm>
|
2012-11-27 19:08:31 +04:00
|
|
|
#include "moses/TranslationModel/PhraseDictionaryTree.h"
|
|
|
|
#include "moses/Phrase.h"
|
|
|
|
#include "moses/FactorCollection.h"
|
|
|
|
#include "moses/InputFileStream.h"
|
|
|
|
#include "moses/InputType.h"
|
|
|
|
#include "moses/ConfusionNet.h"
|
|
|
|
#include "moses/Sentence.h"
|
|
|
|
#include "moses/StaticData.h"
|
|
|
|
#include "moses/UniqueObject.h"
|
|
|
|
#include "moses/PDTAimp.h"
|
|
|
|
#include "moses/UserMessage.h"
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
2008-06-11 14:52:57 +04:00
|
|
|
/*************************************************************
|
|
|
|
function definitions of the interface class
|
|
|
|
virtually everything is forwarded to the implementation class
|
|
|
|
*************************************************************/
|
|
|
|
|
|
|
|
PhraseDictionaryTreeAdaptor::
|
2013-02-22 23:17:57 +04:00
|
|
|
PhraseDictionaryTreeAdaptor(const std::string &line)
|
|
|
|
: PhraseDictionary("PhraseDictionaryTreeAdaptor", line)
|
2011-02-24 16:14:42 +03:00
|
|
|
{
|
2013-02-22 23:17:57 +04:00
|
|
|
imp = new PDTAimp(this,m_numInputScores);
|
2009-08-07 20:47:54 +04:00
|
|
|
}
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
PhraseDictionaryTreeAdaptor::~PhraseDictionaryTreeAdaptor()
|
2008-06-11 14:52:57 +04:00
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
imp->CleanUp();
|
|
|
|
delete imp;
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PhraseDictionaryTreeAdaptor::Load(const std::vector<FactorType> &input
|
2011-02-24 16:14:42 +03:00
|
|
|
, const std::vector<FactorType> &output
|
|
|
|
, const std::string &filePath
|
|
|
|
, const std::vector<float> &weight
|
|
|
|
, size_t tableLimit
|
|
|
|
, const LMList &languageModels
|
|
|
|
, float weightWP)
|
2008-06-11 14:52:57 +04:00
|
|
|
{
|
2013-02-22 23:17:57 +04:00
|
|
|
if(m_numScoreComponents!=weight.size()) {
|
2011-02-24 16:14:42 +03:00
|
|
|
std::stringstream strme;
|
|
|
|
strme << "ERROR: mismatch of number of scaling factors: "<<weight.size()
|
2013-02-22 23:17:57 +04:00
|
|
|
<<" "<<m_numScoreComponents<<"\n";
|
2011-02-24 16:14:42 +03:00
|
|
|
UserMessage::Add(strme.str());
|
|
|
|
return false;
|
|
|
|
}
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
// set PhraseDictionary members
|
|
|
|
m_tableLimit=tableLimit;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2012-06-01 04:49:42 +04:00
|
|
|
imp->Create(input,output,filePath,weight,languageModels);
|
2011-02-24 16:14:42 +03:00
|
|
|
return true;
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
void PhraseDictionaryTreeAdaptor::InitializeForInput(InputType const& source)
|
|
|
|
{
|
|
|
|
imp->CleanUp();
|
|
|
|
// caching only required for confusion net
|
|
|
|
if(ConfusionNet const* cn=dynamic_cast<ConfusionNet const*>(&source))
|
|
|
|
imp->CacheSource(*cn);
|
2009-08-07 20:47:54 +04:00
|
|
|
}
|
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
TargetPhraseCollection const*
|
2008-06-11 14:52:57 +04:00
|
|
|
PhraseDictionaryTreeAdaptor::GetTargetPhraseCollection(Phrase const &src) const
|
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
return imp->GetTargetPhraseCollection(src);
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
2008-09-12 22:09:06 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
TargetPhraseCollection const*
|
2008-06-11 14:52:57 +04:00
|
|
|
PhraseDictionaryTreeAdaptor::GetTargetPhraseCollection(InputType const& src,WordsRange const &range) const
|
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
if(imp->m_rangeCache.empty()) {
|
|
|
|
return imp->GetTargetPhraseCollection(src.GetSubString(range));
|
|
|
|
} else {
|
|
|
|
return imp->m_rangeCache[range.GetStartPos()][range.GetEndPos()];
|
|
|
|
}
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void PhraseDictionaryTreeAdaptor::EnableCache()
|
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
imp->useCache=1;
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
|
|
|
void PhraseDictionaryTreeAdaptor::DisableCache()
|
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
imp->useCache=0;
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
|
|
|
|
2011-08-30 16:25:50 +04:00
|
|
|
}
|