mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-28 06:22:14 +03:00
281bf610b8
added names of features in the header added methods to access the features by name git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@1819 1f5c12ca-751b-0410-a591-d2e778427230
75 lines
1.7 KiB
C++
75 lines
1.7 KiB
C++
/*
|
|
* FeatureStats.h
|
|
* met - Minimum Error Training
|
|
*
|
|
* Created by Nicola Bertoldi on 13/05/08.
|
|
*
|
|
*/
|
|
|
|
#ifndef FEATURE_STATS_H
|
|
#define FEATURE_STATS_H
|
|
|
|
using namespace std;
|
|
|
|
#include <limits>
|
|
#include <vector>
|
|
#include <iostream>
|
|
|
|
#include "Util.h"
|
|
|
|
#define FEATURE_STATS_MIN (numeric_limits<FeatureStatsType>::min())
|
|
#define ATOFST(str) ((FeatureStatsType) atof(str))
|
|
|
|
#define bytes_ (entries_*sizeof(FeatureStatsType))
|
|
|
|
class FeatureStats
|
|
{
|
|
private:
|
|
featstats_t array2_;
|
|
size_t entries_;
|
|
size_t available_;
|
|
|
|
public:
|
|
FeatureStats();
|
|
FeatureStats(const size_t size);
|
|
FeatureStats(const FeatureStats &stats);
|
|
FeatureStats(std::string &theString);
|
|
FeatureStats& operator=(const FeatureStats &stats);
|
|
|
|
~FeatureStats();
|
|
|
|
bool isfull(){return (entries_ < available_)?0:1; }
|
|
void expand();
|
|
void add(FeatureStatsType v);
|
|
|
|
inline void clear() { memset((void*) array2_,0,bytes_); }
|
|
|
|
inline FeatureStatsType get(size_t i){ return array2_[i]; }
|
|
inline FeatureStatsType get(size_t i)const{ return array2_[i]; }
|
|
inline featstats_t getArray() const { return array2_; }
|
|
|
|
void set(std::string &theString);
|
|
|
|
inline size_t bytes() const{ return bytes_; }
|
|
inline size_t size() const{ return entries_; }
|
|
inline size_t available() const{ return available_; }
|
|
|
|
void savetxt(const std::string &file);
|
|
void savetxt(ofstream& outFile);
|
|
void savebin(ofstream& outFile);
|
|
inline void savetxt(){ savetxt("/dev/stdout"); }
|
|
|
|
void loadtxt(const std::string &file);
|
|
void loadtxt(ifstream& inFile);
|
|
void loadbin(ifstream& inFile);
|
|
|
|
inline void reset(){ entries_ = 0; clear(); }
|
|
|
|
/**write the whole object to a stream*/
|
|
friend ostream& operator<<(ostream& o, const FeatureStats& e);
|
|
};
|
|
|
|
#endif
|
|
|
|
|