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

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Haddow <barry.haddow@gmail.com>2012-05-25 00:11:35 +0400
committerBarry Haddow <barry.haddow@gmail.com>2012-05-25 00:11:35 +0400
commitc397d2068bd65fc1eca6bf49057cfda154fa3ce5 (patch)
treee8a8c4e6f60c2b0d47592371d981b9d1a1ac9f85 /mert/FeatureArray.h
parent5a17ef82b3c7449d9fb3686875a7936193e14a89 (diff)
parent277fd38bbd345c083b762a0fb36c0a69da2ca7eb (diff)
Merge branch 'trunk' into miramerge. Still to fix build.
Conflicts: Jamroot mert/Data.cpp mert/Data.h mert/FeatureArray.cpp mert/FeatureArray.h mert/FeatureData.cpp mert/FeatureData.h mert/FeatureStats.cpp mert/FeatureStats.h mert/mert.cpp moses-chart-cmd/src/IOWrapper.h moses-chart-cmd/src/Main.cpp moses-cmd/src/IOWrapper.cpp moses-cmd/src/IOWrapper.h moses-cmd/src/Main.cpp moses/src/GlobalLexicalModel.cpp moses/src/Jamfile moses/src/Parameter.cpp moses/src/PhraseDictionary.cpp moses/src/ScoreIndexManager.h moses/src/TargetPhrase.h regression-testing/tests/phrase.lexicalized-reordering-bin/truth/results.txt regression-testing/tests/phrase.lexicalized-reordering-cn/truth/results.txt regression-testing/tests/phrase.lexicalized-reordering/truth/results.txt regression-testing/tests/phrase.multiple-translation-system-lr/truth/results.txt regression-testing/tests/phrase.show-weights.lex-reorder/truth/results.txt regression-testing/tests/phrase.show-weights/truth/results.txt scripts/ems/experiment.meta scripts/ems/experiment.perl scripts/training/filter-model-given-input.pl scripts/training/mert-moses.pl
Diffstat (limited to 'mert/FeatureArray.h')
-rw-r--r--mert/FeatureArray.h93
1 files changed, 39 insertions, 54 deletions
diff --git a/mert/FeatureArray.h b/mert/FeatureArray.h
index f96c6d7d4..5ce5e1b1a 100644
--- a/mert/FeatureArray.h
+++ b/mert/FeatureArray.h
@@ -1,21 +1,18 @@
/*
* FeatureArray.h
- * met - Minimum Error Training
+ * mert - Minimum Error Rate Training
*
* Created by Nicola Bertoldi on 13/05/08.
*
*/
-#ifndef FEATURE_ARRAY_H
-#define FEATURE_ARRAY_H
+#ifndef MERT_FEATURE_ARRAY_H_
+#define MERT_FEATURE_ARRAY_H_
#include <vector>
-#include <iostream>
-#include <fstream>
+#include <iosfwd>
#include "FeatureStats.h"
-using namespace std;
-
const char FEATURES_TXT_BEGIN[] = "FEATURES_TXT_BEGIN_0";
const char FEATURES_TXT_END[] = "FEATURES_TXT_END_0";
const char FEATURES_BIN_BEGIN[] = "FEATURES_BIN_BEGIN_0";
@@ -26,70 +23,58 @@ class FeatureArray
private:
// idx to identify the utterance. It can differ from
// the index inside the vector.
- std::string idx;
-protected:
- featarray_t array_;
- size_t number_of_features;
- std::string features;
+ std::string m_index;
+ featarray_t m_array;
+ std::size_t m_num_features;
+ std::string m_features;
public:
FeatureArray();
~FeatureArray();
- inline void clear() {
- array_.clear();
- }
+ void clear() { m_array.clear(); }
- inline std::string getIndex() const {
- return idx;
- }
- inline void setIndex(const std::string& value) {
- idx = value;
- }
- inline FeatureStats& get(size_t i) {
- return array_.at(i);
- }
- inline const FeatureStats& get(size_t i)const {
- return array_.at(i);
+ std::string getIndex() const { return m_index; }
+ void setIndex(const std::string& value) { m_index = value; }
+
+ FeatureStats& get(std::size_t i) { return m_array.at(i); }
+ const FeatureStats& get(std::size_t i) const { return m_array.at(i); }
+
+ void add(FeatureStats& e) { m_array.push_back(e); }
+
+ //ADDED BY TS
+ void swap(std::size_t i, std::size_t j) {
+ std::swap(m_array[i], m_array[j]);
}
- void add(FeatureStats& e) {
- array_.push_back(e);
+
+ void resize(std::size_t new_size) {
+ m_array.resize(std::min(new_size, m_array.size()));
}
+ //END_ADDED
void merge(FeatureArray& e);
- inline size_t size() const {
- return array_.size();
- }
- inline size_t NumberOfFeatures() const {
- return number_of_features;
- }
- inline void NumberOfFeatures(size_t v) {
- number_of_features = v;
- }
- inline std::string Features() const {
- return features;
- }
- inline void Features(const std::string& f) {
- features = f;
- }
+ std::size_t size() const { return m_array.size(); }
+
+ std::size_t NumberOfFeatures() const { return m_num_features; }
+ void NumberOfFeatures(std::size_t v) { m_num_features = v; }
- void savetxt(ofstream& outFile);
- void savebin(ofstream& outFile);
- void save(ofstream& outFile, bool bin=false);
+ std::string Features() const { return m_features; }
+ void Features(const std::string& f) { m_features = f; }
+
+ void savetxt(std::ostream* os);
+ void savebin(std::ostream* os);
+ void save(std::ostream* os, bool bin=false);
void save(const std::string &file, bool bin=false);
- inline void save(bool bin=false) {
- save("/dev/stdout",bin);
- }
+ void save(bool bin=false);
- void loadtxt(ifstream& inFile, const SparseVector& sparseWeights, size_t n);
- void loadbin(ifstream& inFile, size_t n);
- void load(ifstream& inFile, const SparseVector& sparseWeights);
- //void load(const std::string &file);
+ void loadtxt(std::istream* is, const SparseVector& sparseWeights, std::size_t n);
+ void loadbin(std::istream* is, std::size_t n);
+ void load(std::istream* is, const SparseVector& sparseWeights);
bool check_consistency() const;
};
-#endif // FEATURE_ARRAY_H
+#endif // MERT_FEATURE_ARRAY_H_