blob: 9400dc0446fbc0cc44f2233c51a8d401b401f7fa (
plain)
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
|
// $Id$
#ifndef moses_ScoreIndexManager_h
#define moses_ScoreIndexManager_h
#include <iostream>
#include <vector>
#ifdef HAVE_PROTOBUF
#include "hypergraph.pb.h"
#endif
namespace Moses
{
class ScoreProducer;
class ScoreComponentCollection; // debugging only
class StatefulFeatureFunction;
class StatelessFeatureFunction;
/** Keep track of scores and score producers. Each score producer is reserved contiguous set of slots
* to put their score components. All the score components are arranged in a vector with no gaps.
* Only 1 ScoreIndexManager object should be instantiated
*/
class ScoreIndexManager
{
friend std::ostream& operator<<(std::ostream& os, const ScoreIndexManager& sim);
public:
ScoreIndexManager() : m_last(0) {}
//! new score producer to manage. Producers must be inserted in the order they are created
void AddScoreProducer(const ScoreProducer* producer);
void InitFeatureNames();
//! starting score index for a particular score producer with scoreBookkeepingID
size_t GetBeginIndex(size_t scoreBookkeepingID) const {
return m_begins[scoreBookkeepingID];
}
//! end score index for a particular score producer with scoreBookkeepingID
size_t GetEndIndex(size_t scoreBookkeepingID) const {
return m_ends[scoreBookkeepingID];
}
//! sum of all score components from every score producer
size_t GetTotalNumberOfScores() const {
return m_last;
}
//! print unweighted scores of each ScoreManager to stream os
void PrintLabeledScores(std::ostream& os, const ScoreComponentCollection& scc) const;
//! print weighted scores of each ScoreManager to stream os
void PrintLabeledWeightedScores(std::ostream& os, const ScoreComponentCollection& scc, const std::vector<float>& weights) const;
#ifdef HAVE_PROTOBUF
void SerializeFeatureNamesToPB(hgmert::Hypergraph* hg) const;
#endif
void InitWeightVectorFromFile(const std::string& fnam, std::vector<float>* m_allWeights) const;
private:
ScoreIndexManager(const ScoreIndexManager&); // don't implement
std::vector<size_t> m_begins;
std::vector<size_t> m_ends;
std::vector<const ScoreProducer*> m_producers; /**< all the score producers in this run */
std::vector<std::string> m_featureNames;
std::vector<std::string> m_featureShortNames;
size_t m_last;
};
}
#endif
|