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"
|
|
|
|
#include "moses/StaticData.h"
|
|
|
|
#include "moses/UserMessage.h"
|
|
|
|
#include "Loader.h"
|
|
|
|
#include "LoaderFactory.h"
|
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-05-29 21:16:15 +04:00
|
|
|
: PhraseDictionaryMemory("PhraseDictionaryALSuffixArray", 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
|
|
|
}
|
2011-11-06 13:08:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void PhraseDictionaryALSuffixArray::InitializeForInput(InputType const& source)
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
2011-11-18 16:07:41 +04:00
|
|
|
CHECK(ret);
|
2011-11-06 13:08:37 +04:00
|
|
|
}
|
|
|
|
|
2013-05-28 18:38:36 +04:00
|
|
|
void PhraseDictionaryALSuffixArray::CleanUpAfterSentenceProcessing(const InputType &source)
|
|
|
|
{
|
|
|
|
m_collection.Clear();
|
|
|
|
}
|
|
|
|
|
2011-11-06 13:08:37 +04:00
|
|
|
}
|