mosesdecoder/moses/TranslationModel/RuleTable/PhraseDictionaryALSuffixArray.cpp

63 lines
1.6 KiB
C++
Raw Normal View History

//
// PhraseDictionaryALSuffixArray.cpp
// moses
//
// Created by Hieu Hoang on 06/11/2011.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#include <iostream>
#include "PhraseDictionaryALSuffixArray.h"
2012-11-12 23:56:18 +04:00
#include "moses/InputType.h"
#include "moses/InputFileStream.h"
#include "moses/TypeDef.h"
#include "moses/TranslationTask.h"
2012-11-12 23:56:18 +04:00
#include "moses/StaticData.h"
#include "Loader.h"
#include "LoaderFactory.h"
#include "util/exception.hh"
using namespace std;
2013-05-29 21:16:15 +04:00
namespace Moses
{
2013-05-28 16:11:37 +04:00
PhraseDictionaryALSuffixArray::PhraseDictionaryALSuffixArray(const std::string &line)
: PhraseDictionaryMemory(1, line)
{
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");
}
ReadParameters();
}
void PhraseDictionaryALSuffixArray::Load()
{
SetFeaturesToApply();
}
void PhraseDictionaryALSuffixArray::InitializeForInput(ttasksptr const& ttask)
{
InputType const& source = *ttask->GetSource();
// populate with rules for this sentence
long translationId = source.GetTranslationId();
2013-05-29 21:16:15 +04:00
string grammarFile = GetFilePath() + "/grammar." + SPrint(translationId) + ".gz";
2013-05-29 21:16:15 +04:00
std::auto_ptr<RuleTableLoader> loader =
2013-05-29 21:16:15 +04:00
RuleTableLoaderFactory::Create(grammarFile);
bool ret = loader->Load(m_input, m_output, grammarFile, m_tableLimit,
*this);
2013-05-29 21:16:15 +04:00
UTIL_THROW_IF2(!ret,
2015-01-14 14:07:42 +03:00
"Rules not successfully loaded for sentence id " << translationId);
}
void PhraseDictionaryALSuffixArray::CleanUpAfterSentenceProcessing(const InputType &source)
{
2013-07-18 23:23:44 +04:00
m_collection.Remove();
}
}