Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Data.h « mert - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f2610c8dd908446daaa037c04ce7090fdbe23b61 (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
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
/*
 *  Data.h
 *  met - Minimum Error Training
 *
 *  Created by Nicola Bertoldi on 13/05/08.
 *
 */

#ifndef DATA_H
#define DATA_H

using namespace std;

#include <limits>
#include <vector>
#include <iostream>

#include "Util.h"
#include "FeatureData.h"
#include "ScoreData.h"

class Scorer;

class Data
{
private:
  Scorer* theScorer;
  std::string score_type;
  size_t number_of_scores;
  SparseVector sparse_weights;

protected:
  // TODO: Use smart pointers for exceptional-safety.
  ScoreData* scoredata;
  FeatureData* featdata;

public:
  explicit Data(Scorer& sc, const std::string& sparseweightsfile="");
  ~Data();

  inline void clear() {
    scoredata->clear();
    featdata->clear();
  }

  ScoreData* getScoreData() {
    return scoredata;
  }

  FeatureData* getFeatureData() {
    return featdata;
  }

  Scorer* getScorer() {
    return theScorer;
  }

  inline size_t NumberOfFeatures() const {
    return featdata->NumberOfFeatures();
  }
  inline void NumberOfFeatures(size_t v) {
    featdata->NumberOfFeatures(v);
  }
  inline std::string Features() const {
    return featdata->Features();
  }
  inline void Features(const std::string &f) {
    featdata->Features(f);
  }


  void loadnbest(const std::string &file);

  void load(const std::string &featfile,const std::string &scorefile) {
    featdata->load(featfile, sparse_weights);
    scoredata->load(scorefile);
  }

  void save(const std::string &featfile,const std::string &scorefile, bool bin=false) {

//    if (bin) cerr << "Binary write mode is selected" << endl;
//    else cerr << "Binary write mode is NOT selected" << endl;

    featdata->save(featfile, bin);
    scoredata->save(scorefile, bin);
  }

  inline bool existsFeatureNames() const {
    return featdata->existsFeatureNames();
  }

  inline std::string getFeatureName(size_t idx) const {
    return featdata->getFeatureName(idx);
  }

  inline size_t getFeatureIndex(const std::string& name) const {
    return featdata->getFeatureIndex(name);
  }

  /**
   * Create shard_count shards. If shard_size == 0, then the shards are non-overlapping
   * and exhaust the data. If 0 < shard_size <= 1, then shards are chosen by sampling
   * the data (with replacement) and shard_size is interpreted as the proportion
   * of the total size.
   */
  void createShards(size_t shard_count, float shard_size, const std::string& scorerconfig,
                    std::vector<Data>& shards);
};

#endif  // DATA_H