import classes into moses2

This commit is contained in:
Hieu Hoang 2015-11-13 10:40:55 +00:00
parent 8d7e273057
commit e58e2fd777
17 changed files with 54 additions and 26 deletions

View File

@ -31,6 +31,7 @@
<option id="gnu.cpp.compiler.option.debugging.level.769854045" name="Debug Level" superClass="gnu.cpp.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/> <option id="gnu.cpp.compiler.option.debugging.level.769854045" name="Debug Level" superClass="gnu.cpp.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.include.paths.1502531988" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath"> <option id="gnu.cpp.compiler.option.include.paths.1502531988" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc}/../../boost/include&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc}/../../boost/include&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc}/../../&quot;"/>
</option> </option>
<option id="gnu.cpp.compiler.option.preprocessor.def.1025143565" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" useByScannerDiscovery="false" valueType="definedSymbols"> <option id="gnu.cpp.compiler.option.preprocessor.def.1025143565" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" useByScannerDiscovery="false" valueType="definedSymbols">
<listOptionValue builtIn="false" value="KENLM_MAX_ORDER=7"/> <listOptionValue builtIn="false" value="KENLM_MAX_ORDER=7"/>

View File

@ -9,6 +9,7 @@
#include "FeatureFunction.h" #include "FeatureFunction.h"
#include "../System.h" #include "../System.h"
#include "../legacy/Util2.h" #include "../legacy/Util2.h"
#include "util/exception.hh"
using namespace std; using namespace std;
@ -54,7 +55,7 @@ void FeatureFunction::ParseLine(const std::string &line)
// name // name
if (m_name == "") { if (m_name == "") {
m_name = Moses::SPrint(nameStub) + Moses::SPrint(0); m_name = SPrint(nameStub) + SPrint(0);
} }
} }

View File

@ -21,6 +21,7 @@
#include "../TranslationModel/UnknownWordPenalty.h" #include "../TranslationModel/UnknownWordPenalty.h"
#include "../LM/LanguageModel.h" #include "../LM/LanguageModel.h"
#include "../LM/KENLM.h" #include "../LM/KENLM.h"
#include "util/exception.hh"
using namespace std; using namespace std;
@ -33,7 +34,7 @@ FeatureFunctions::FeatureFunctions(System &system)
} }
FeatureFunctions::~FeatureFunctions() { FeatureFunctions::~FeatureFunctions() {
Moses::RemoveAllInColl(m_featureFunctions); RemoveAllInColl(m_featureFunctions);
} }
void FeatureFunctions::Create() void FeatureFunctions::Create()

View File

@ -10,7 +10,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include "moses/Parameter.h" #include "../legacy/Parameter.h"
class System; class System;
class FeatureFunction; class FeatureFunction;

View File

@ -14,7 +14,7 @@
#include "../Search/Manager.h" #include "../Search/Manager.h"
#include "lm/state.hh" #include "lm/state.hh"
#include "lm/left.hh" #include "lm/left.hh"
#include "moses/FactorCollection.h" #include "../legacy/FactorCollection.h"
using namespace std; using namespace std;
@ -196,7 +196,7 @@ void KENLM::EvaluateWhenApplied(const Manager &mgr,
stateCast.state = *state0; stateCast.state = *state0;
} }
score = Moses::TransformLMScore(score); score = TransformLMScore(score);
bool OOVFeatureEnabled = false; bool OOVFeatureEnabled = false;
if (OOVFeatureEnabled) { if (OOVFeatureEnabled) {
@ -246,8 +246,8 @@ void KENLM::CalcScore(const Phrase &phrase, float &fullScore, float &ngramScore,
} }
fullScore += scorer.Finish(); fullScore += scorer.Finish();
ngramScore = Moses::TransformLMScore(fullScore - before_boundary); ngramScore = TransformLMScore(fullScore - before_boundary);
fullScore = Moses::TransformLMScore(fullScore); fullScore = TransformLMScore(fullScore);
} }
lm::WordIndex KENLM::TranslateID(const Word &word) const { lm::WordIndex KENLM::TranslateID(const Word &word) const {

View File

@ -12,7 +12,7 @@
#include "../FF/StatefulFeatureFunction.h" #include "../FF/StatefulFeatureFunction.h"
#include "lm/model.hh" #include "lm/model.hh"
#include "../legacy/Factor.h" #include "../legacy/Factor.h"
#include "moses/TypeDef.h" #include "../legacy/Util2.h"
class Word; class Word;
@ -45,7 +45,7 @@ public:
protected: protected:
std::string m_path; std::string m_path;
Moses::FactorType m_factorType; FactorType m_factorType;
bool m_lazy; bool m_lazy;
const Factor *m_bos; const Factor *m_bos;
const Factor *m_eos; const Factor *m_eos;

View File

@ -83,7 +83,7 @@ void LanguageModel::Load(System &system)
assert(substrings.size() == 2 || substrings.size() == 3); assert(substrings.size() == 2 || substrings.size() == 3);
SCORE prob = Moses::TransformLMScore(Scan<SCORE>(substrings[0])); SCORE prob = TransformLMScore(Scan<SCORE>(substrings[0]));
if (substrings[1] == "<unk>") { if (substrings[1] == "<unk>") {
m_oov = prob; m_oov = prob;
continue; continue;
@ -91,7 +91,7 @@ void LanguageModel::Load(System &system)
SCORE backoff = 0.f; SCORE backoff = 0.f;
if (substrings.size() == 3) { if (substrings.size() == 3) {
backoff = Moses::TransformLMScore(Scan<SCORE>(substrings[2])); backoff = TransformLMScore(Scan<SCORE>(substrings[2]));
} }
// ngram // ngram

View File

@ -12,7 +12,7 @@
#include "../TypeDef.h" #include "../TypeDef.h"
#include "../MorphoTrie/MorphTrie.h" #include "../MorphoTrie/MorphTrie.h"
#include "../legacy/Factor.h" #include "../legacy/Factor.h"
#include "moses/TypeDef.h" #include "../legacy/Util2.h"
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
struct LMScores struct LMScores
@ -67,7 +67,7 @@ public:
protected: protected:
std::string m_path; std::string m_path;
Moses::FactorType m_factorType; FactorType m_factorType;
size_t m_order; size_t m_order;
MorphTrie<const Factor*, LMScores> m_root; MorphTrie<const Factor*, LMScores> m_root;

View File

@ -4,8 +4,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "legacy/Util2.h" #include "legacy/Util2.h"
#include "moses/Factor.h" #include "../legacy/Factor.h"
#include "moses/InputFileStream.h" #include "../legacy/InputFileStream.h"
using namespace std; using namespace std;

View File

@ -12,7 +12,7 @@
#include <iostream> #include <iostream>
#include "Word.h" #include "Word.h"
#include "MemPool.h" #include "MemPool.h"
#include "moses/FactorCollection.h" #include "legacy/FactorCollection.h"
class SubPhrase; class SubPhrase;

View File

@ -148,7 +148,7 @@ void Scores::CreateFromString(const std::string &str,
{ {
vector<SCORE> scores = Tokenize<SCORE>(str); vector<SCORE> scores = Tokenize<SCORE>(str);
if (transformScores) { if (transformScores) {
std::transform(scores.begin(), scores.end(), scores.begin(), Moses::TransformScore); std::transform(scores.begin(), scores.end(), scores.begin(), TransformScore);
} }
/* /*

View File

@ -28,7 +28,7 @@ public:
class Stack { class Stack {
protected: protected:
typedef boost::unordered_set<const Hypothesis*, Moses::UnorderedComparer<Hypothesis>, Moses::UnorderedComparer<Hypothesis> > _HCType; typedef boost::unordered_set<const Hypothesis*, UnorderedComparer<Hypothesis>, UnorderedComparer<Hypothesis> > _HCType;
_HCType m_hypos; _HCType m_hypos;
public: public:
typedef _HCType::iterator iterator; typedef _HCType::iterator iterator;

View File

@ -23,10 +23,10 @@ System::System(const Parameter &paramsArg)
{ {
ini_performance_options(); ini_performance_options();
params.SetParameter(stackSize, "stack", Moses::DEFAULT_MAX_HYPOSTACK_SIZE); params.SetParameter(stackSize, "stack", DEFAULT_MAX_HYPOSTACK_SIZE);
params.SetParameter(maxDistortion, "distortion-limit", -1); params.SetParameter(maxDistortion, "distortion-limit", -1);
params.SetParameter(maxPhraseLength, "max-phrase-length", params.SetParameter(maxPhraseLength, "max-phrase-length",
Moses::DEFAULT_MAX_PHRASE_LENGTH); DEFAULT_MAX_PHRASE_LENGTH);
featureFunctions.Create(); featureFunctions.Create();
LoadWeights(); LoadWeights();
@ -50,7 +50,7 @@ void System::LoadWeights()
void System::LoadMappings() void System::LoadMappings()
{ {
const Moses::PARAM_VEC *vec = params.GetParam("mapping"); const PARAM_VEC *vec = params.GetParam("mapping");
UTIL_THROW_IF2(vec == NULL, "Must have [mapping] section"); UTIL_THROW_IF2(vec == NULL, "Must have [mapping] section");
BOOST_FOREACH(const std::string &line, *vec) { BOOST_FOREACH(const std::string &line, *vec) {
@ -102,7 +102,7 @@ void
System System
::ini_performance_options() ::ini_performance_options()
{ {
const Moses::PARAM_VEC *paramsVec; const PARAM_VEC *paramsVec;
// m_parameter->SetParameter<size_t>(m_timeout_threshold, "time-out", -1); // m_parameter->SetParameter<size_t>(m_timeout_threshold, "time-out", -1);
// m_timeout = (GetTimeoutThreshold() == (size_t)-1) ? false : true; // m_timeout = (GetTimeoutThreshold() == (size_t)-1) ? false : true;

View File

@ -8,7 +8,7 @@
#ifndef PHRASETABLEMEMORY_H_ #ifndef PHRASETABLEMEMORY_H_
#define PHRASETABLEMEMORY_H_ #define PHRASETABLEMEMORY_H_
#include "PhraseTable.h" #include "PhraseTable.h"
#include "../legacy/Util2.h"
class PhraseTableMemory : public PhraseTable class PhraseTableMemory : public PhraseTable
{ {
@ -24,7 +24,7 @@ class PhraseTableMemory : public PhraseTable
void SortAndPrune(size_t tableLimit); void SortAndPrune(size_t tableLimit);
protected: protected:
typedef boost::unordered_map<Word, Node, Moses::UnorderedComparer<Word>, Moses::UnorderedComparer<Word> > Children; typedef boost::unordered_map<Word, Node, UnorderedComparer<Word>, UnorderedComparer<Word> > Children;
Children m_children; Children m_children;
TargetPhrases::shared_ptr m_targetPhrases; TargetPhrases::shared_ptr m_targetPhrases;

View File

@ -12,6 +12,7 @@
#include "../Search/Manager.h" #include "../Search/Manager.h"
#include "../legacy/FactorCollection.h" #include "../legacy/FactorCollection.h"
#include "../legacy/ProbingPT/quering.hh" #include "../legacy/ProbingPT/quering.hh"
#include "../legacy/Util2.h"
using namespace std; using namespace std;
@ -154,7 +155,7 @@ TargetPhrase *ProbingPT::CreateTargetPhrase(MemPool &pool, const System &system,
// score for this phrase table // score for this phrase table
vector<SCORE> scores = probingTargetPhrase.prob; vector<SCORE> scores = probingTargetPhrase.prob;
std::transform(scores.begin(), scores.end(), scores.begin(), Moses::TransformScore); std::transform(scores.begin(), scores.end(), scores.begin(), TransformScore);
tp->GetScores().PlusEquals(system, *this, scores); tp->GetScores().PlusEquals(system, *this, scores);
// // alignment // // alignment

View File

@ -9,7 +9,7 @@
#include <iostream> #include <iostream>
#include "TypeDef.h" #include "TypeDef.h"
#include "moses/Factor.h" #include "legacy/Factor.h"
#include "legacy/FactorCollection.h" #include "legacy/FactorCollection.h"
class Word { class Word {

View File

@ -6,9 +6,12 @@
#include <limits> #include <limits>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
#include <cmath>
#define NOT_FOUND std::numeric_limits<size_t>::max() #define NOT_FOUND std::numeric_limits<size_t>::max()
typedef size_t FactorType; typedef size_t FactorType;
const size_t DEFAULT_MAX_PHRASE_LENGTH = 20;
const size_t DEFAULT_MAX_HYPOSTACK_SIZE = 200;
template<typename T> template<typename T>
class UnorderedComparer class UnorderedComparer
@ -208,3 +211,24 @@ inline bool FileExists(const std::string& filePath)
const std::string ToLower(const std::string& str); const std::string ToLower(const std::string& str);
//! delete and remove every element of a collection object such as set, list etc
template<class COLL>
void RemoveAllInColl(COLL &coll)
{
for (typename COLL::const_iterator iter = coll.begin() ; iter != coll.end() ; ++iter) {
delete (*iter);
}
coll.clear();
}
//! irst number are in log 10, transform to natural log
inline float TransformLMScore(float irstScore)
{
return irstScore * 2.30258509299405f;
}
//! transform prob to natural log score
inline float TransformScore(float prob)
{
return log(prob);
}