File size: 3,050 Bytes
fd49381 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
/*
* FeatureFunctions.h
*
* Created on: 27 Oct 2015
* Author: hieu
*/
#pragma once
#include <boost/unordered_map.hpp>
#include <vector>
#include <string>
#include "../legacy/Parameter.h"
#include "../Phrase.h"
namespace Moses2
{
template<typename WORD>
class TargetPhrase;
class System;
class FeatureFunction;
class StatefulFeatureFunction;
class PhraseTable;
class Manager;
class MemPool;
class PhraseImpl;
class TargetPhrases;
class TargetPhraseImpl;
class Scores;
class Hypothesis;
class UnknownWordPenalty;
class Weights;
class InputType;
namespace SCFG
{
class TargetPhraseImpl;
class TargetPhrases;
class Word;
}
class FeatureFunctions
{
public:
std::vector<const PhraseTable*> phraseTables;
FeatureFunctions(System &system);
virtual ~FeatureFunctions();
const std::vector<FeatureFunction*> &GetFeatureFunctions() const {
return m_featureFunctions;
}
const std::vector<const StatefulFeatureFunction*> &GetStatefulFeatureFunctions() const {
return m_statefulFeatureFunctions;
}
const std::vector<const FeatureFunction*> &GetWithPhraseTableInd() const {
return m_withPhraseTableInd;
}
size_t GetNumScores() const {
return m_ffStartInd;
}
void Create();
void Load();
const FeatureFunction *FindFeatureFunction(const std::string &name) const;
const PhraseTable *GetPhraseTableExcludeUnknownWordPenalty(size_t ptInd);
const UnknownWordPenalty *GetUnknownWordPenalty() const {
return m_unkWP;
}
// the pool here must be the system pool if the rule was loaded during load, or the mgr pool if it was loaded on demand
void EvaluateInIsolation(MemPool &pool, const System &system,
const Phrase<Moses2::Word> &source, TargetPhraseImpl &targetPhrase) const;
void EvaluateInIsolation(MemPool &pool, const System &system,
const Phrase<SCFG::Word> &source, SCFG::TargetPhraseImpl &targetPhrase) const;
void EvaluateAfterTablePruning(MemPool &pool, const TargetPhrases &tps,
const Phrase<Moses2::Word> &sourcePhrase) const;
void EvaluateAfterTablePruning(MemPool &pool, const SCFG::TargetPhrases &tps,
const Phrase<SCFG::Word> &sourcePhrase) const;
void EvaluateWhenAppliedBatch(const Batch &batch) const;
void InitializeForInput(const ManagerBase &mgr, const InputType &input);
void CleanUpAfterSentenceProcessing(const InputType &input) const;
void ShowWeights(const Weights &allWeights);
protected:
std::vector<FeatureFunction*> m_featureFunctions;
std::vector<const StatefulFeatureFunction*> m_statefulFeatureFunctions;
std::vector<const FeatureFunction*> m_withPhraseTableInd;
const UnknownWordPenalty *m_unkWP;
boost::unordered_map<std::string, size_t> m_defaultNames;
System &m_system;
size_t m_ffStartInd;
FeatureFunction *Create(const std::string &line);
std::string GetDefaultName(const std::string &stub);
void OverrideFeatures();
FeatureFunction *FindFeatureFunction(const std::string &name);
};
}
|