mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-25 21:03:22 +03:00
load hiero format for reading suffix arrays
This commit is contained in:
parent
86b9bf8bed
commit
bb2385657e
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -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();
|
||||
|
@ -189,6 +189,8 @@ public:
|
||||
return m_nonTermMap;
|
||||
}
|
||||
|
||||
void Clear();
|
||||
|
||||
TO_STRING();
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user