2008-06-11 14:52:57 +04:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <algorithm>
|
2013-06-11 04:46:04 +04:00
|
|
|
#include "moses/TranslationModel/PhraseDictionaryTreeAdaptor.h"
|
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"
|
2013-06-11 04:46:04 +04:00
|
|
|
#include "util/check.hh"
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2013-02-25 15:49:34 +04:00
|
|
|
using namespace std;
|
|
|
|
|
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)
|
2013-05-14 15:19:55 +04:00
|
|
|
: PhraseDictionary("PhraseDictionaryBinary", line)
|
2011-02-24 16:14:42 +03:00
|
|
|
{
|
2013-06-20 15:50:41 +04:00
|
|
|
size_t ind = 0;
|
|
|
|
while (ind < m_args.size()) {
|
|
|
|
vector<string> &args = m_args[ind];
|
|
|
|
bool consumed = SetParameter(args[0], args[1]);
|
|
|
|
if (consumed) {
|
|
|
|
m_args.erase(m_args.begin() + ind);
|
|
|
|
} else {
|
|
|
|
++ind;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
}
|
2013-06-14 21:34:47 +04:00
|
|
|
void PhraseDictionaryTreeAdaptor::Load()
|
|
|
|
{
|
|
|
|
SetFeaturesToApply();
|
|
|
|
}
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2013-03-04 22:15:05 +04:00
|
|
|
void PhraseDictionaryTreeAdaptor::InitializeForInput(InputType const& source)
|
2008-06-11 14:52:57 +04:00
|
|
|
{
|
2013-02-25 15:49:34 +04:00
|
|
|
const StaticData &staticData = StaticData::Instance();
|
|
|
|
|
2013-06-06 21:54:44 +04:00
|
|
|
PDTAimp *obj = new PDTAimp(this);
|
2013-03-04 22:15:05 +04:00
|
|
|
|
|
|
|
vector<float> weight = staticData.GetWeights(this);
|
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());
|
2013-03-04 22:15:05 +04:00
|
|
|
abort();
|
2011-02-24 16:14:42 +03:00
|
|
|
}
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2013-05-21 15:47:26 +04:00
|
|
|
obj->Create(m_input, m_output, m_filePath, weight);
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2013-03-04 22:15:05 +04:00
|
|
|
obj->CleanUp();
|
2011-02-24 16:14:42 +03:00
|
|
|
// caching only required for confusion net
|
|
|
|
if(ConfusionNet const* cn=dynamic_cast<ConfusionNet const*>(&source))
|
2013-03-04 22:15:05 +04:00
|
|
|
obj->CacheSource(*cn);
|
|
|
|
|
|
|
|
m_implementation.reset(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PhraseDictionaryTreeAdaptor::CleanUpAfterSentenceProcessing(InputType const& source)
|
|
|
|
{
|
2013-03-05 18:16:37 +04:00
|
|
|
PDTAimp &obj = GetImplementation();
|
|
|
|
obj.CleanUp();
|
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
|
|
|
|
{
|
2013-03-05 18:16:37 +04:00
|
|
|
return GetImplementation().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
|
|
|
|
{
|
2013-03-05 18:16:37 +04:00
|
|
|
if(GetImplementation().m_rangeCache.empty()) {
|
|
|
|
return GetImplementation().GetTargetPhraseCollection(src.GetSubString(range));
|
2011-02-24 16:14:42 +03:00
|
|
|
} else {
|
2013-03-05 18:16:37 +04:00
|
|
|
return GetImplementation().m_rangeCache[range.GetStartPos()][range.GetEndPos()];
|
2011-02-24 16:14:42 +03:00
|
|
|
}
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void PhraseDictionaryTreeAdaptor::EnableCache()
|
|
|
|
{
|
2013-03-05 18:16:37 +04:00
|
|
|
GetImplementation().useCache=1;
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
|
|
|
void PhraseDictionaryTreeAdaptor::DisableCache()
|
|
|
|
{
|
2013-03-05 18:16:37 +04:00
|
|
|
GetImplementation().useCache=0;
|
2013-03-04 22:15:05 +04:00
|
|
|
}
|
|
|
|
|
2013-03-05 18:16:37 +04:00
|
|
|
PDTAimp& PhraseDictionaryTreeAdaptor::GetImplementation()
|
2013-03-04 22:15:05 +04:00
|
|
|
{
|
|
|
|
PDTAimp* dict;
|
|
|
|
dict = m_implementation.get();
|
|
|
|
CHECK(dict);
|
2013-03-05 18:16:37 +04:00
|
|
|
return *dict;
|
2013-03-04 22:15:05 +04:00
|
|
|
}
|
|
|
|
|
2013-03-05 18:16:37 +04:00
|
|
|
const PDTAimp& PhraseDictionaryTreeAdaptor::GetImplementation() const
|
2013-03-04 22:15:05 +04:00
|
|
|
{
|
|
|
|
PDTAimp* dict;
|
|
|
|
dict = m_implementation.get();
|
|
|
|
CHECK(dict);
|
2013-03-05 18:16:37 +04:00
|
|
|
return *dict;
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
|
|
|
|
2011-08-30 16:25:50 +04:00
|
|
|
}
|