mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 19:27:11 +03:00
init moses2
This commit is contained in:
parent
e10eed6436
commit
58b5086984
@ -19,6 +19,8 @@ public:
|
||||
|
||||
size_t GetStartInd() const
|
||||
{ return m_startInd; }
|
||||
size_t GetNumScores() const
|
||||
{ return m_numScores; }
|
||||
|
||||
protected:
|
||||
size_t m_startInd;
|
||||
|
@ -10,11 +10,14 @@
|
||||
#include "Scores.h"
|
||||
#include "FeatureFunction.h"
|
||||
#include "Util.h"
|
||||
#include "Weights.h"
|
||||
#include "StaticData.h"
|
||||
#include "moses/Util.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
Scores::Scores(util::Pool &pool, size_t numScores)
|
||||
:m_total(0)
|
||||
{
|
||||
m_scores = new (pool.Allocate<SCORE>(numScores)) SCORE[numScores];
|
||||
Init<SCORE>(m_scores, numScores, 0);
|
||||
@ -24,11 +27,24 @@ Scores::~Scores() {
|
||||
delete m_scores;
|
||||
}
|
||||
|
||||
void Scores::CreateFromString(const std::string &str, const FeatureFunction &featureFunction, const StaticData &staticData)
|
||||
void Scores::PlusEquals(const std::vector<SCORE> &scores, const FeatureFunction &featureFunction, const StaticData &staticData)
|
||||
{
|
||||
assert(scores.size() == featureFunction.GetNumScores());
|
||||
|
||||
const Weights &weights = staticData.GetWeights();
|
||||
|
||||
size_t ffStartInd = featureFunction.GetStartInd();
|
||||
vector<SCORE> toks = Moses::Tokenize<SCORE>(str);
|
||||
for (size_t i = 0; i < toks.size(); ++i) {
|
||||
m_scores[ffStartInd + i] = toks[i];
|
||||
for (size_t i = 0; i < scores.size(); ++i) {
|
||||
SCORE incrScore = scores[i];
|
||||
m_scores[ffStartInd + i] += incrScore;
|
||||
|
||||
SCORE weight = weights[ffStartInd + i];
|
||||
m_total += incrScore * weight;
|
||||
}
|
||||
}
|
||||
|
||||
void Scores::CreateFromString(const std::string &str, const FeatureFunction &featureFunction, const StaticData &staticData)
|
||||
{
|
||||
vector<SCORE> scores = Moses::Tokenize<SCORE>(str);
|
||||
PlusEquals(scores, featureFunction, staticData);
|
||||
}
|
||||
|
@ -15,11 +15,14 @@ class StaticData;
|
||||
|
||||
class Scores {
|
||||
public:
|
||||
Scores(util::Pool &pool, size_t numScores);
|
||||
virtual ~Scores();
|
||||
Scores(util::Pool &pool, size_t numScores);
|
||||
virtual ~Scores();
|
||||
|
||||
void CreateFromString(const std::string &str, const FeatureFunction &featureFunction, const StaticData &staticData);
|
||||
void CreateFromString(const std::string &str, const FeatureFunction &featureFunction, const StaticData &staticData);
|
||||
|
||||
void PlusEquals(const std::vector<SCORE> &scores, const FeatureFunction &featureFunction, const StaticData &staticData);
|
||||
protected:
|
||||
SCORE *m_scores;
|
||||
SCORE m_total;
|
||||
};
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "Vocab.h"
|
||||
#include "Weights.h"
|
||||
#include "util/pool.hh"
|
||||
|
||||
class FeatureFunction;
|
||||
@ -21,6 +22,9 @@ public:
|
||||
size_t GetNumScores() const
|
||||
{ return 55; }
|
||||
|
||||
const Weights &GetWeights() const
|
||||
{ return m_weights; }
|
||||
|
||||
util::Pool &GetPool()
|
||||
{ return m_pool; }
|
||||
|
||||
@ -33,5 +37,6 @@ protected:
|
||||
std::vector<const PhraseTable*> m_phraseTables;
|
||||
util::Pool m_pool;
|
||||
size_t m_ffStartInd;
|
||||
Weights m_weights;
|
||||
};
|
||||
|
||||
|
18
contrib/other-builds/moses2/Weights.cpp
Normal file
18
contrib/other-builds/moses2/Weights.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Weights.cpp
|
||||
*
|
||||
* Created on: 24 Oct 2015
|
||||
* Author: hieu
|
||||
*/
|
||||
|
||||
#include "Weights.h"
|
||||
|
||||
Weights::Weights() {
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
}
|
||||
|
||||
Weights::~Weights() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
24
contrib/other-builds/moses2/Weights.h
Normal file
24
contrib/other-builds/moses2/Weights.h
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Weights.h
|
||||
*
|
||||
* Created on: 24 Oct 2015
|
||||
* Author: hieu
|
||||
*/
|
||||
|
||||
#ifndef WEIGHTS_H_
|
||||
#define WEIGHTS_H_
|
||||
|
||||
#include "TypeDef.h"
|
||||
|
||||
class Weights {
|
||||
public:
|
||||
Weights();
|
||||
virtual ~Weights();
|
||||
|
||||
SCORE operator[](size_t ind) const {
|
||||
return 444.5f;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /* WEIGHTS_H_ */
|
@ -12,6 +12,7 @@ g++ -I../../.. -I../../../boost/include -L../../../lib -lmoses -lz -o moses2 \
|
||||
TargetPhrase.cpp \
|
||||
TargetPhrases.cpp \
|
||||
Vocab.cpp \
|
||||
Weights.cpp \
|
||||
Word.cpp \
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user