load hiero format for reading suffix arrays

This commit is contained in:
Hieu Hoang 2011-11-06 16:08:37 +07:00
parent 86b9bf8bed
commit bb2385657e
4 changed files with 85 additions and 3 deletions

View File

@ -7,3 +7,58 @@
//
#include <iostream>
#include "PhraseDictionaryALSuffixArray.h"
#include "InputType.h"
#include "InputFileStream.h"
#include "RuleTableLoader.h"
#include "RuleTableLoaderFactory.h"
#include "TypeDef.h"
using namespace std;
namespace Moses
{
bool PhraseDictionaryALSuffixArray::Load(const std::vector<FactorType> &input
, const std::vector<FactorType> &output
, const std::string &filePath
, const std::vector<float> &weight
, size_t tableLimit
, const LMList &languageModels
, const WordPenaltyProducer* wpProducer)
{
// file path is the directory of the rules for eacg, NOT the file of all the rules
m_filePath = filePath;
m_tableLimit = tableLimit;
m_input = &input;
m_output = &output;
m_languageModels = &languageModels;
m_wpProducer = wpProducer;
m_weight = &weight;
return true;
}
void PhraseDictionaryALSuffixArray::InitializeForInput(InputType const& source)
{
// clear out rules for previous sentence
m_collection.Clear();
// populate with rules for this sentence
long translationId = source.GetTranslationId();
string grammarFile = m_filePath + "/grammar.out." + SPrint(translationId);
// data from file
InputFileStream inFile(grammarFile);
std::auto_ptr<RuleTableLoader> loader =
RuleTableLoaderFactory::Create(grammarFile);
bool ret = loader->Load(*m_input, *m_output, inFile, *m_weight, m_tableLimit,
*m_languageModels, m_wpProducer, *this);
assert(ret);
}
}

View File

@ -9,15 +9,32 @@
#ifndef moses_PhraseDictionaryALSuffixArray_h
#define moses_PhraseDictionaryALSuffixArray_h
#include "PhraseDictionaryHiero.h"
#include "PhraseDictionarySCFG.h"
namespace Moses {
class PhraseDictionaryALSuffixArray : public PhraseDictionaryHiero
class PhraseDictionaryALSuffixArray : public PhraseDictionarySCFG
{
public:
PhraseDictionaryALSuffixArray(size_t numScoreComponent, PhraseDictionaryFeature* feature)
: PhraseDictionaryHiero(numScoreComponent,feature) {}
: PhraseDictionarySCFG(numScoreComponent,feature) {}
bool Load(const std::vector<FactorType> &input
, const std::vector<FactorType> &output
, const std::string &filePath
, const std::vector<float> &weight
, size_t tableLimit
, const LMList &languageModels
, const WordPenaltyProducer* wpProducer);
void InitializeForInput(InputType const& source);
protected:
const std::vector<FactorType> *m_input, *m_output;
const LMList *m_languageModels;
const WordPenaltyProducer *m_wpProducer;
const std::vector<float> *m_weight;
};

View File

@ -104,6 +104,14 @@ const PhraseDictionaryNodeSCFG *PhraseDictionaryNodeSCFG::GetChild(const Word &s
return (p == m_nonTermMap.end()) ? NULL : &p->second;
}
void PhraseDictionaryNodeSCFG::Clear()
{
m_sourceTermMap.clear();
m_nonTermMap.clear();
delete m_targetPhraseCollection;
}
std::ostream& operator<<(std::ostream &out, const PhraseDictionaryNodeSCFG &node)
{
out << node.GetTargetPhraseCollection();

View File

@ -189,6 +189,8 @@ public:
return m_nonTermMap;
}
void Clear();
TO_STRING();
};