2011-11-06 12:31:11 +04:00
|
|
|
//
|
|
|
|
// PhraseDictionaryALSuffixArray.cpp
|
|
|
|
// moses
|
|
|
|
//
|
|
|
|
// Created by Hieu Hoang on 06/11/2011.
|
|
|
|
// Copyright 2011 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <iostream>
|
2011-11-06 13:08:37 +04:00
|
|
|
#include "PhraseDictionaryALSuffixArray.h"
|
2012-11-12 23:56:18 +04:00
|
|
|
#include "moses/InputType.h"
|
|
|
|
#include "moses/InputFileStream.h"
|
|
|
|
#include "moses/TypeDef.h"
|
2015-05-19 04:35:39 +03:00
|
|
|
#include "moses/TranslationTask.h"
|
2012-11-12 23:56:18 +04:00
|
|
|
#include "moses/StaticData.h"
|
|
|
|
#include "Loader.h"
|
|
|
|
#include "LoaderFactory.h"
|
2013-11-20 18:02:38 +04:00
|
|
|
#include "util/exception.hh"
|
2011-11-06 13:08:37 +04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
namespace Moses
|
2011-11-06 13:08:37 +04:00
|
|
|
{
|
2013-05-28 16:11:37 +04:00
|
|
|
PhraseDictionaryALSuffixArray::PhraseDictionaryALSuffixArray(const std::string &line)
|
2013-10-29 22:20:55 +04:00
|
|
|
: PhraseDictionaryMemory(1, line)
|
2011-11-06 13:08:37 +04:00
|
|
|
{
|
2012-05-30 12:49:43 +04:00
|
|
|
const StaticData &staticData = StaticData::Instance();
|
2013-05-28 16:11:37 +04:00
|
|
|
if (staticData.ThreadCount() > 1) {
|
2013-05-29 21:16:15 +04:00
|
|
|
throw runtime_error("Suffix array implementation is not threadsafe");
|
2012-05-30 12:49:43 +04:00
|
|
|
}
|
2013-06-24 19:10:22 +04:00
|
|
|
|
|
|
|
ReadParameters();
|
2011-11-06 13:08:37 +04:00
|
|
|
}
|
|
|
|
|
2013-06-14 21:34:47 +04:00
|
|
|
void PhraseDictionaryALSuffixArray::Load()
|
|
|
|
{
|
|
|
|
SetFeaturesToApply();
|
|
|
|
}
|
|
|
|
|
2015-05-19 04:35:39 +03:00
|
|
|
void PhraseDictionaryALSuffixArray::InitializeForInput(ttasksptr const& ttask)
|
2011-11-06 13:08:37 +04:00
|
|
|
{
|
2015-05-19 04:35:39 +03:00
|
|
|
InputType const& source = *ttask->GetSource();
|
2011-11-06 13:08:37 +04:00
|
|
|
// populate with rules for this sentence
|
|
|
|
long translationId = source.GetTranslationId();
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2013-05-28 18:38:36 +04:00
|
|
|
string grammarFile = GetFilePath() + "/grammar." + SPrint(translationId) + ".gz";
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2011-11-06 13:08:37 +04:00
|
|
|
std::auto_ptr<RuleTableLoader> loader =
|
2013-05-29 21:16:15 +04:00
|
|
|
RuleTableLoaderFactory::Create(grammarFile);
|
2013-05-28 18:38:36 +04:00
|
|
|
bool ret = loader->Load(m_input, m_output, grammarFile, m_tableLimit,
|
2013-05-21 16:39:31 +04:00
|
|
|
*this);
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2014-10-10 17:22:53 +04:00
|
|
|
UTIL_THROW_IF2(!ret,
|
2015-01-14 14:07:42 +03:00
|
|
|
"Rules not successfully loaded for sentence id " << translationId);
|
2011-11-06 13:08:37 +04:00
|
|
|
}
|
|
|
|
|
2013-05-28 18:38:36 +04:00
|
|
|
void PhraseDictionaryALSuffixArray::CleanUpAfterSentenceProcessing(const InputType &source)
|
|
|
|
{
|
2013-07-18 23:23:44 +04:00
|
|
|
m_collection.Remove();
|
2013-05-28 18:38:36 +04:00
|
|
|
}
|
|
|
|
|
2011-11-06 13:08:37 +04:00
|
|
|
}
|