2008-06-11 14:52:57 +04:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
#include "PhraseDictionaryTreeAdaptor.h"
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <algorithm>
|
|
|
|
#include "PhraseDictionaryTree.h"
|
|
|
|
#include "Phrase.h"
|
|
|
|
#include "FactorCollection.h"
|
|
|
|
#include "InputFileStream.h"
|
|
|
|
#include "InputType.h"
|
|
|
|
#include "ConfusionNet.h"
|
|
|
|
#include "Sentence.h"
|
|
|
|
#include "StaticData.h"
|
|
|
|
#include "UniqueObject.h"
|
|
|
|
#include "PDTAimp.h"
|
|
|
|
#include "UserMessage.h"
|
|
|
|
|
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::
|
2009-08-07 20:47:54 +04:00
|
|
|
PhraseDictionaryTreeAdaptor(size_t numScoreComponent, unsigned numInputScores, const PhraseDictionaryFeature* feature)
|
|
|
|
: PhraseDictionary(numScoreComponent,feature), imp(new PDTAimp(this,numInputScores)) {
|
|
|
|
}
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
PhraseDictionaryTreeAdaptor::~PhraseDictionaryTreeAdaptor()
|
|
|
|
{
|
|
|
|
imp->CleanUp();
|
|
|
|
delete imp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool PhraseDictionaryTreeAdaptor::Load(const std::vector<FactorType> &input
|
|
|
|
, const std::vector<FactorType> &output
|
|
|
|
, const std::string &filePath
|
|
|
|
, const std::vector<float> &weight
|
|
|
|
, size_t tableLimit
|
|
|
|
, const LMList &languageModels
|
2009-08-07 20:47:54 +04:00
|
|
|
, float weightWP)
|
2008-06-11 14:52:57 +04:00
|
|
|
{
|
|
|
|
if(m_numScoreComponent!=weight.size()) {
|
2010-08-10 17:51:20 +04:00
|
|
|
std::stringstream strme;
|
2008-06-11 14:52:57 +04:00
|
|
|
strme << "ERROR: mismatch of number of scaling factors: "<<weight.size()
|
|
|
|
<<" "<<m_numScoreComponent<<"\n";
|
|
|
|
UserMessage::Add(strme.str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// set PhraseDictionary members
|
|
|
|
m_tableLimit=tableLimit;
|
|
|
|
|
|
|
|
imp->Create(input,output,filePath,
|
|
|
|
weight,languageModels,weightWP);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-08-07 20:47:54 +04: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);
|
|
|
|
}
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
TargetPhraseCollection const*
|
|
|
|
PhraseDictionaryTreeAdaptor::GetTargetPhraseCollection(Phrase const &src) const
|
|
|
|
{
|
|
|
|
return imp->GetTargetPhraseCollection(src);
|
|
|
|
}
|
2008-09-12 22:09:06 +04:00
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
TargetPhraseCollection const*
|
|
|
|
PhraseDictionaryTreeAdaptor::GetTargetPhraseCollection(InputType const& src,WordsRange const &range) const
|
|
|
|
{
|
|
|
|
if(imp->m_rangeCache.empty())
|
|
|
|
{
|
|
|
|
return imp->GetTargetPhraseCollection(src.GetSubString(range));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return imp->m_rangeCache[range.GetStartPos()][range.GetEndPos()];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhraseDictionaryTreeAdaptor::
|
|
|
|
AddEquivPhrase(const Phrase &source, const TargetPhrase &targetPhrase)
|
|
|
|
{
|
|
|
|
imp->AddEquivPhrase(source,targetPhrase);
|
|
|
|
}
|
|
|
|
void PhraseDictionaryTreeAdaptor::EnableCache()
|
|
|
|
{
|
|
|
|
imp->useCache=1;
|
|
|
|
}
|
|
|
|
void PhraseDictionaryTreeAdaptor::DisableCache()
|
|
|
|
{
|
|
|
|
imp->useCache=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t PhraseDictionaryTreeAdaptor::GetNumInputScores() const {
|
|
|
|
return imp->GetNumInputScores();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string PhraseDictionaryTreeAdaptor::GetScoreProducerDescription() const
|
|
|
|
{
|
2008-09-24 21:03:07 +04:00
|
|
|
return "PhraseModel";
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|