00001 // 00002 // PhraseDictionaryALSuffixArray.cpp 00003 // moses 00004 // 00005 // Created by Hieu Hoang on 06/11/2011. 00006 // Copyright 2011 __MyCompanyName__. All rights reserved. 00007 // 00008 00009 #include <iostream> 00010 #include "PhraseDictionaryALSuffixArray.h" 00011 #include "moses/InputType.h" 00012 #include "moses/InputFileStream.h" 00013 #include "moses/TypeDef.h" 00014 #include "moses/TranslationTask.h" 00015 #include "moses/StaticData.h" 00016 #include "Loader.h" 00017 #include "LoaderFactory.h" 00018 #include "util/exception.hh" 00019 00020 using namespace std; 00021 00022 namespace Moses 00023 { 00024 PhraseDictionaryALSuffixArray::PhraseDictionaryALSuffixArray(const std::string &line) 00025 : PhraseDictionaryMemory(1, line) 00026 { 00027 const StaticData &staticData = StaticData::Instance(); 00028 if (staticData.ThreadCount() > 1) { 00029 throw runtime_error("Suffix array implementation is not threadsafe"); 00030 } 00031 00032 ReadParameters(); 00033 } 00034 00035 void PhraseDictionaryALSuffixArray::Load(AllOptions::ptr const& opts) 00036 { 00037 m_options = opts; 00038 SetFeaturesToApply(); 00039 } 00040 00041 void PhraseDictionaryALSuffixArray::InitializeForInput(ttasksptr const& ttask) 00042 { 00043 InputType const& source = *ttask->GetSource(); 00044 // populate with rules for this sentence 00045 long translationId = source.GetTranslationId(); 00046 00047 string grammarFile = GetFilePath() + "/grammar." + SPrint(translationId) + ".gz"; 00048 00049 std::auto_ptr<RuleTableLoader> loader = 00050 RuleTableLoaderFactory::Create(grammarFile); 00051 AllOptions::ptr const& opts = ttask->options(); 00052 bool ret = loader->Load(*opts, m_input, m_output, grammarFile, m_tableLimit, *this); 00053 00054 UTIL_THROW_IF2(!ret, "Rules not successfully loaded for sentence id " 00055 << translationId); 00056 } 00057 00058 void PhraseDictionaryALSuffixArray::CleanUpAfterSentenceProcessing(const InputType &source) 00059 { 00060 m_collection.Remove(); 00061 } 00062 00063 }