diff options
author | Hieu Hoang <fishandfrolick@gmail.com> | 2012-06-30 23:23:45 +0400 |
---|---|---|
committer | Hieu Hoang <fishandfrolick@gmail.com> | 2012-06-30 23:23:45 +0400 |
commit | e3dd3a8d2c72f5f1d60b4ec12a628f319a1f1906 (patch) | |
tree | 46544c1e642100fd4f0367d0b2b9786e9cdac676 | |
parent | 1cf1c2e51561bac3b3ca0b7e5b63fb93f978a064 (diff) |
namespace all classes in mert directory
72 files changed, 431 insertions, 16 deletions
diff --git a/mert/BleuScorer.cpp b/mert/BleuScorer.cpp index 8c68e362f..50227352c 100644 --- a/mert/BleuScorer.cpp +++ b/mert/BleuScorer.cpp @@ -26,6 +26,10 @@ const char REFLEN_CLOSEST[] = "closest"; } // namespace +namespace MosesTuning +{ + + BleuScorer::BleuScorer(const string& config) : StatisticsBasedScorer("BLEU", config), m_ref_length_type(CLOSEST) { @@ -273,3 +277,6 @@ float unsmoothedBleu(const std::vector<float>& stats) { } return exp(logbleu); } + +} + diff --git a/mert/BleuScorer.h b/mert/BleuScorer.h index 8e0acf366..38669b740 100644 --- a/mert/BleuScorer.h +++ b/mert/BleuScorer.h @@ -10,10 +10,13 @@ #include "StatisticsBasedScorer.h" #include "ScopedVector.h" +namespace MosesTuning +{ + const int kBleuNgramOrder = 4; class NgramCounts; -class Reference; +class Reference; /** * Bleu scoring @@ -80,4 +83,6 @@ float sentenceLevelBackgroundBleu(const std::vector<float>& sent, const std::vec */ float unsmoothedBleu(const std::vector<float>& stats); +} + #endif // MERT_BLEU_SCORER_H_ diff --git a/mert/CderScorer.cpp b/mert/CderScorer.cpp index 8a835f17d..cece29034 100644 --- a/mert/CderScorer.cpp +++ b/mert/CderScorer.cpp @@ -14,6 +14,10 @@ inline int CalcDistance(int word1, int word2) { } // namespace +namespace MosesTuning +{ + + CderScorer::CderScorer(const string& config, bool allowed_long_jumps) : StatisticsBasedScorer(allowed_long_jumps ? "CDER" : "WER", config), m_allowed_long_jumps(allowed_long_jumps) {} @@ -124,3 +128,5 @@ void CderScorer::computeCD(const sent_t& cand, const sent_t& ref, delete row; } + +} diff --git a/mert/CderScorer.h b/mert/CderScorer.h index 14cd96f12..60b6ad125 100644 --- a/mert/CderScorer.h +++ b/mert/CderScorer.h @@ -6,6 +6,10 @@ #include "Types.h" #include "StatisticsBasedScorer.h" +namespace MosesTuning +{ + + /** * CderScorer class can compute both CDER and WER metric. */ @@ -38,4 +42,6 @@ class CderScorer: public StatisticsBasedScorer { CderScorer& operator=(const CderScorer&); }; +} + #endif // MERT_CDER_SCORER_H_ diff --git a/mert/Data.cpp b/mert/Data.cpp index 19a89f754..1be7d26ca 100644 --- a/mert/Data.cpp +++ b/mert/Data.cpp @@ -19,6 +19,10 @@ using namespace std; +namespace MosesTuning +{ + + Data::Data() : m_scorer(NULL), m_num_scores(0), @@ -269,3 +273,6 @@ void Data::createShards(size_t shard_count, float shard_size, const string& scor //cerr << endl; } } + +} + diff --git a/mert/Data.h b/mert/Data.h index 37d4b5473..aa69f4edf 100644 --- a/mert/Data.h +++ b/mert/Data.h @@ -16,6 +16,9 @@ #include "FeatureData.h" #include "ScoreData.h" +namespace MosesTuning +{ + class Scorer; typedef boost::shared_ptr<ScoreData> ScoreDataHandle; @@ -97,4 +100,6 @@ public: const std::string& sentence_index); }; +} + #endif // MERT_DATA_H_ diff --git a/mert/Fdstream.h b/mert/Fdstream.h index 93f705dfe..6dbdb40a6 100644 --- a/mert/Fdstream.h +++ b/mert/Fdstream.h @@ -13,6 +13,9 @@ #define BUFFER_SIZE (32768) +namespace MosesTuning +{ + class _fdstream { protected: @@ -164,4 +167,6 @@ private: #error "Not supported" #endif +} + #endif // _FDSTREAM_ diff --git a/mert/FeatureArray.cpp b/mert/FeatureArray.cpp index 4bfe90e8e..0f297e8cb 100644 --- a/mert/FeatureArray.cpp +++ b/mert/FeatureArray.cpp @@ -14,6 +14,10 @@ using namespace std; +namespace MosesTuning +{ + + FeatureArray::FeatureArray() : m_index(""), m_num_features(0), m_sparse_flag(false) {} @@ -165,3 +169,6 @@ bool FeatureArray::check_consistency() const } return true; } + +} + diff --git a/mert/FeatureArray.h b/mert/FeatureArray.h index 4459a4f79..bac743fe1 100644 --- a/mert/FeatureArray.h +++ b/mert/FeatureArray.h @@ -13,6 +13,10 @@ #include <iosfwd> #include "FeatureStats.h" +namespace MosesTuning +{ + + 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"; @@ -79,4 +83,6 @@ public: bool check_consistency() const; }; +} + #endif // MERT_FEATURE_ARRAY_H_ diff --git a/mert/FeatureData.cpp b/mert/FeatureData.cpp index acc144d1a..8daec204a 100644 --- a/mert/FeatureData.cpp +++ b/mert/FeatureData.cpp @@ -14,6 +14,10 @@ using namespace std; +namespace MosesTuning +{ + + static const float MIN_FLOAT = -1.0 * numeric_limits<float>::max(); static const float MAX_FLOAT = numeric_limits<float>::max(); @@ -174,3 +178,6 @@ string FeatureData::ToString() const { return res; } + +} + diff --git a/mert/FeatureData.h b/mert/FeatureData.h index d30630ab7..5bd0f5d6f 100644 --- a/mert/FeatureData.h +++ b/mert/FeatureData.h @@ -14,6 +14,10 @@ #include <stdexcept> #include "FeatureArray.h" +namespace MosesTuning +{ + + class FeatureData { private: @@ -130,4 +134,6 @@ public: std::string ToString() const; }; +} + #endif // MERT_FEATURE_DATA_H_ diff --git a/mert/FeatureDataIterator.cpp b/mert/FeatureDataIterator.cpp index c0ace87e6..f9acbb64c 100644 --- a/mert/FeatureDataIterator.cpp +++ b/mert/FeatureDataIterator.cpp @@ -29,6 +29,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA using namespace std; using namespace util; +namespace MosesTuning +{ + + int ParseInt(const StringPiece& str ) { char* errIndex; //could wrap? @@ -130,3 +134,6 @@ bool FeatureDataIterator::equal(const FeatureDataIterator& rhs) const { const vector<FeatureDataItem>& FeatureDataIterator::dereference() const { return m_next; } + +} + diff --git a/mert/FeatureDataIterator.h b/mert/FeatureDataIterator.h index 9bc5f03f7..b8f138c49 100644 --- a/mert/FeatureDataIterator.h +++ b/mert/FeatureDataIterator.h @@ -37,6 +37,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "FeatureStats.h" +namespace MosesTuning +{ + class FileFormatException : public util::Exception { @@ -91,4 +94,6 @@ class FeatureDataIterator : std::vector<FeatureDataItem> m_next; }; +} + #endif // MERT_FEATURE_DATA_ITERATOR_H_ diff --git a/mert/FeatureStats.cpp b/mert/FeatureStats.cpp index 2c6cdb88f..6f80d5f89 100644 --- a/mert/FeatureStats.cpp +++ b/mert/FeatureStats.cpp @@ -20,6 +20,10 @@ namespace { const int kAvailableSize = 8; } // namespace +namespace MosesTuning +{ + + SparseVector::name2id_t SparseVector::m_name_to_id; SparseVector::id2name_t SparseVector::m_id_to_name; @@ -263,7 +267,6 @@ ostream& operator<<(ostream& o, const FeatureStats& e) return o; } -//ADEED_BY_TS bool operator==(const FeatureStats& f1, const FeatureStats& f2) { size_t size = f1.size(); @@ -277,4 +280,5 @@ bool operator==(const FeatureStats& f1, const FeatureStats& f2) { return true; } -//END_ADDED + +} diff --git a/mert/FeatureStats.h b/mert/FeatureStats.h index 2a4e9882c..9085fb7dc 100644 --- a/mert/FeatureStats.h +++ b/mert/FeatureStats.h @@ -16,6 +16,10 @@ #include <vector> #include "Types.h" +namespace MosesTuning +{ + + // Minimal sparse vector class SparseVector { public: @@ -120,8 +124,8 @@ public: friend std::ostream& operator<<(std::ostream& o, const FeatureStats& e); }; -//ADEED_BY_TS bool operator==(const FeatureStats& f1, const FeatureStats& f2); -//END_ADDED + +} #endif // MERT_FEATURE_STATS_H_ diff --git a/mert/HypPackEnumerator.cpp b/mert/HypPackEnumerator.cpp index 7bccd0122..776c02857 100644 --- a/mert/HypPackEnumerator.cpp +++ b/mert/HypPackEnumerator.cpp @@ -6,6 +6,10 @@ using namespace std; +namespace MosesTuning +{ + + StreamingHypPackEnumerator::StreamingHypPackEnumerator ( vector<std::string> const& featureFiles, @@ -195,3 +199,5 @@ size_t RandomAccessHypPackEnumerator::cur_id() { // mode:c++ // c-basic-offset:2 // End: + +} diff --git a/mert/HypPackEnumerator.h b/mert/HypPackEnumerator.h index f22a9ca87..690e53103 100644 --- a/mert/HypPackEnumerator.h +++ b/mert/HypPackEnumerator.h @@ -18,6 +18,10 @@ #include "ScoreDataIterator.h" #include "MiraFeatureVector.h" +namespace MosesTuning +{ + + // Start with these abstract classes class HypPackEnumerator { @@ -97,6 +101,8 @@ private: std::vector<std::vector<ScoreDataItem> > m_scores; }; +} + #endif // MERT_HYP_PACK_COLLECTION_H // --Emacs trickery-- diff --git a/mert/InterpolatedScorer.cpp b/mert/InterpolatedScorer.cpp index 9db147d91..f8ff36744 100644 --- a/mert/InterpolatedScorer.cpp +++ b/mert/InterpolatedScorer.cpp @@ -4,6 +4,10 @@ using namespace std; +namespace MosesTuning +{ + + // TODO: This is too long. Consider creating a function for // initialization such as Init(). InterpolatedScorer::InterpolatedScorer(const string& name, const string& config) @@ -195,3 +199,6 @@ void InterpolatedScorer::setFilter(const string& filterCommand) m_scorers[i]->setFilter(csplit[i]); } } + +} + diff --git a/mert/InterpolatedScorer.h b/mert/InterpolatedScorer.h index 321b50d20..aba08852c 100644 --- a/mert/InterpolatedScorer.h +++ b/mert/InterpolatedScorer.h @@ -8,6 +8,10 @@ #include "Scorer.h" #include "ScopedVector.h" +namespace MosesTuning +{ + + /** * Class that includes other scorers eg. * Interpolated HAMMING and BLEU scorer **/ @@ -52,4 +56,6 @@ protected: std::vector<float> m_scorer_weights; }; +} + #endif // MERT_INTERPOLATED_SCORER_H_ diff --git a/mert/MergeScorer.cpp b/mert/MergeScorer.cpp index dbdd31cf7..3f26df7e7 100644 --- a/mert/MergeScorer.cpp +++ b/mert/MergeScorer.cpp @@ -14,6 +14,10 @@ using namespace std; using namespace TERCpp; +namespace MosesTuning +{ + + MergeScorer::MergeScorer(const string& config) : StatisticsBasedScorer("MERGE", config) {} @@ -121,3 +125,6 @@ float MergeScorer::calculateScore(const std::vector< int >& comps) const } return result; } + +} + diff --git a/mert/MergeScorer.h b/mert/MergeScorer.h index 2abb8a285..5800b3d2a 100644 --- a/mert/MergeScorer.h +++ b/mert/MergeScorer.h @@ -6,6 +6,10 @@ #include "StatisticsBasedScorer.h" +namespace MosesTuning +{ + + class PerScorer; class ScoreStats; @@ -33,4 +37,6 @@ protected: MergeScorer& operator=(const MergeScorer&); }; +} + #endif // MERT_MERGE_SCORER_H_ diff --git a/mert/MiraFeatureVector.cpp b/mert/MiraFeatureVector.cpp index 68007820a..95805c295 100644 --- a/mert/MiraFeatureVector.cpp +++ b/mert/MiraFeatureVector.cpp @@ -5,6 +5,10 @@ using namespace std; +namespace MosesTuning +{ + + MiraFeatureVector::MiraFeatureVector(const FeatureDataItem& vec) : m_dense(vec.dense) { @@ -156,3 +160,6 @@ ostream& operator<<(ostream& o, const MiraFeatureVector& e) // mode:c++ // c-basic-offset:2 // End: + +} + diff --git a/mert/MiraFeatureVector.h b/mert/MiraFeatureVector.h index 89c7fc126..c9bf09636 100644 --- a/mert/MiraFeatureVector.h +++ b/mert/MiraFeatureVector.h @@ -17,6 +17,10 @@ #include "FeatureDataIterator.h" +namespace MosesTuning +{ + + typedef FeatureStatsType ValType; class MiraFeatureVector { @@ -50,3 +54,5 @@ private: // mode:c++ // c-basic-offset:2 // End: + +} diff --git a/mert/MiraWeightVector.cpp b/mert/MiraWeightVector.cpp index 092c5a44b..c6f0261dc 100644 --- a/mert/MiraWeightVector.cpp +++ b/mert/MiraWeightVector.cpp @@ -4,6 +4,10 @@ using namespace std; +namespace MosesTuning +{ + + /** * Constructor, initializes to the zero vector */ @@ -156,3 +160,5 @@ size_t AvgWeightVector::size() const { // mode:c++ // c-basic-offset:2 // End: +} + diff --git a/mert/MiraWeightVector.h b/mert/MiraWeightVector.h index 20d7e0314..30f8adfa4 100644 --- a/mert/MiraWeightVector.h +++ b/mert/MiraWeightVector.h @@ -15,6 +15,10 @@ #include "MiraFeatureVector.h" +namespace MosesTuning +{ + + class AvgWeightVector; class MiraWeightVector { @@ -105,3 +109,5 @@ private: // mode:c++ // c-basic-offset:2 // End: + +} diff --git a/mert/Ngram.h b/mert/Ngram.h index 846604f3f..d3e8041a3 100644 --- a/mert/Ngram.h +++ b/mert/Ngram.h @@ -5,6 +5,9 @@ #include <map> #include <string> +namespace MosesTuning +{ + /** A simple STL-std::map based n-gram counts. Basically, we provide * typical accessors and mutaors, but we intentionally does not allow * erasing elements. @@ -95,4 +98,6 @@ class NgramCounts { std::map<Key, Value, NgramComparator> m_counts; }; +} + #endif // MERT_NGRAM_H_ diff --git a/mert/Optimizer.cpp b/mert/Optimizer.cpp index 39e9aac1b..e5f5854b2 100644 --- a/mert/Optimizer.cpp +++ b/mert/Optimizer.cpp @@ -33,6 +33,10 @@ inline float intersect(float m1, float b1, float m2, float b2) } // namespace +namespace MosesTuning +{ + + Optimizer::Optimizer(unsigned Pd, const vector<unsigned>& i2O, const vector<bool>& pos, const vector<parameter_t>& start, unsigned int nrandom) : m_scorer(NULL), m_feature_data(), m_num_random_directions(nrandom), m_positive(pos) { @@ -472,3 +476,5 @@ statscore_t RandomOptimizer::TrueRun(Point& P) const P.SetScore(score); return score; } + +} diff --git a/mert/Optimizer.h b/mert/Optimizer.h index f196878f2..f81d59d96 100644 --- a/mert/Optimizer.h +++ b/mert/Optimizer.h @@ -10,6 +10,10 @@ static const float kMaxFloat = std::numeric_limits<float>::max(); +namespace MosesTuning +{ + + class Point; /** @@ -109,4 +113,6 @@ public: virtual statscore_t TrueRun(Point&) const; }; +} + #endif // OPTIMIZER_H diff --git a/mert/OptimizerFactory.cpp b/mert/OptimizerFactory.cpp index 6cafd15b0..b33194f33 100644 --- a/mert/OptimizerFactory.cpp +++ b/mert/OptimizerFactory.cpp @@ -3,6 +3,10 @@ using namespace std; +namespace MosesTuning +{ + + vector<string> OptimizerFactory::m_type_names; void OptimizerFactory::SetTypeNames() @@ -65,3 +69,5 @@ Optimizer* OptimizerFactory::BuildOptimizer(unsigned dim, return NULL; } } + +} diff --git a/mert/OptimizerFactory.h b/mert/OptimizerFactory.h index 7d5e02323..ae34bcb00 100644 --- a/mert/OptimizerFactory.h +++ b/mert/OptimizerFactory.h @@ -4,6 +4,10 @@ #include <vector> #include "Types.h" +namespace MosesTuning +{ + + class Optimizer; class OptimizerFactory @@ -39,4 +43,7 @@ class OptimizerFactory static std::vector<std::string> m_type_names; }; +} + + #endif // MERT_OPTIMIZER_FACTORY_H_ diff --git a/mert/PerScorer.cpp b/mert/PerScorer.cpp index 67b633872..06b53436f 100644 --- a/mert/PerScorer.cpp +++ b/mert/PerScorer.cpp @@ -8,6 +8,10 @@ using namespace std; +namespace MosesTuning +{ + + PerScorer::PerScorer(const string& config) : StatisticsBasedScorer("PER",config) {} @@ -86,3 +90,6 @@ float PerScorer::calculateScore(const vector<int>& comps) const return num/denom; } } + +} + diff --git a/mert/PerScorer.h b/mert/PerScorer.h index 83181014c..76ea9bfd7 100644 --- a/mert/PerScorer.h +++ b/mert/PerScorer.h @@ -7,6 +7,10 @@ #include "Types.h" #include "StatisticsBasedScorer.h" +namespace MosesTuning +{ + + class ScoreStats; /** @@ -36,4 +40,6 @@ private: std::vector<std::multiset<int> > m_ref_tokens; }; +} + #endif // MERT_PER_SCORER_H_ diff --git a/mert/Permutation.cpp b/mert/Permutation.cpp index f03d54477..56887c188 100644 --- a/mert/Permutation.cpp +++ b/mert/Permutation.cpp @@ -14,6 +14,10 @@ using namespace std; +namespace MosesTuning +{ + + Permutation::Permutation(const string &alignment, const int sourceLength, const int targetLength ) { if (sourceLength > 0) { @@ -318,3 +322,5 @@ string Permutation::convertMosesToStandard(string const & alignment) return out; } +} + diff --git a/mert/Permutation.h b/mert/Permutation.h index e03133d7b..2c47487b6 100644 --- a/mert/Permutation.h +++ b/mert/Permutation.h @@ -17,6 +17,9 @@ #include "Util.h" +namespace MosesTuning +{ + class Permutation { @@ -63,4 +66,6 @@ private: }; +} + #endif diff --git a/mert/PermutationScorer.cpp b/mert/PermutationScorer.cpp index ca385e912..94a2ee862 100644 --- a/mert/PermutationScorer.cpp +++ b/mert/PermutationScorer.cpp @@ -3,6 +3,10 @@ using namespace std; +namespace MosesTuning +{ + + const int PermutationScorer::SCORE_PRECISION = 5; PermutationScorer::PermutationScorer(const string &distanceMetric, const string &config) @@ -214,3 +218,5 @@ statscore_t PermutationScorer::calculateScore(const vector<int>& comps) const return comps[0]; } +} + diff --git a/mert/PermutationScorer.h b/mert/PermutationScorer.h index 4aa8bda43..6f354f03f 100644 --- a/mert/PermutationScorer.h +++ b/mert/PermutationScorer.h @@ -17,6 +17,9 @@ #include "Permutation.h" #include "StatisticsBasedScorer.h" +namespace MosesTuning +{ + /** * Permutation **/ @@ -60,6 +63,8 @@ private: }; //TODO need to read in floats for scores - necessary for selecting mean reference strategy and for BLEU? +} #endif //__PERMUTATIONSCORER_H + diff --git a/mert/Point.cpp b/mert/Point.cpp index 299e2b4d0..5c446aa8b 100644 --- a/mert/Point.cpp +++ b/mert/Point.cpp @@ -8,6 +8,9 @@ using namespace std; +namespace MosesTuning +{ + vector<unsigned> Point::m_opt_indices; unsigned Point::m_dim = 0; @@ -156,3 +159,6 @@ void Point::GetAllWeights(vector<parameter_t>& w) const } } } + +} + diff --git a/mert/Point.h b/mert/Point.h index 4be1219fe..92cb832dd 100644 --- a/mert/Point.h +++ b/mert/Point.h @@ -6,6 +6,10 @@ #include <vector> #include "Types.h" +namespace MosesTuning +{ + + class FeatureStats; class Optimizer; @@ -100,4 +104,6 @@ public: void SetScore(statscore_t score) { m_score = score; } }; +} + #endif // MERT_POINT_H diff --git a/mert/PreProcessFilter.cpp b/mert/PreProcessFilter.cpp index d1b822729..da26177f7 100644 --- a/mert/PreProcessFilter.cpp +++ b/mert/PreProcessFilter.cpp @@ -16,6 +16,10 @@ using namespace std; #define CHILD_STDERR_READ pipefds_error[0] #define CHILD_STDERR_WRITE pipefds_error[1] +namespace MosesTuning +{ + + // Child exec error signal void exec_failed (int sig) { @@ -135,3 +139,6 @@ PreProcessFilter::~PreProcessFilter() delete m_toFilter; delete m_fromFilter; } + +} + diff --git a/mert/PreProcessFilter.h b/mert/PreProcessFilter.h index 27c8d35ff..25e627f6d 100644 --- a/mert/PreProcessFilter.h +++ b/mert/PreProcessFilter.h @@ -3,6 +3,10 @@ #include <string> +namespace MosesTuning +{ + + class ofdstream; class ifdstream; @@ -22,4 +26,6 @@ private: ifdstream* m_fromFilter; }; +} + #endif // MERT_PREPROCESSFILTER_H_ diff --git a/mert/Reference.h b/mert/Reference.h index 53b715dff..1d6869a12 100644 --- a/mert/Reference.h +++ b/mert/Reference.h @@ -7,6 +7,10 @@ #include "Ngram.h" +namespace MosesTuning +{ + + /** * Reference class represents reference translations for an output * translation used in calculating BLEU score. @@ -79,4 +83,7 @@ inline int Reference::CalcShortest() const { return *std::min_element(m_length.begin(), m_length.end()); } +} + + #endif // MERT_REFERENCE_H_ diff --git a/mert/ScopedVector.h b/mert/ScopedVector.h index 0b7eda13a..c87f07071 100644 --- a/mert/ScopedVector.h +++ b/mert/ScopedVector.h @@ -3,6 +3,9 @@ #include <vector> +namespace MosesTuning +{ + template <class T> class ScopedVector { public: @@ -51,4 +54,6 @@ class ScopedVector { void operator=(const ScopedVector<T>&); }; +} + #endif // MERT_SCOPED_VECTOR_H_ diff --git a/mert/ScoreArray.cpp b/mert/ScoreArray.cpp index 83fa96ef0..da626f627 100644 --- a/mert/ScoreArray.cpp +++ b/mert/ScoreArray.cpp @@ -12,6 +12,10 @@ using namespace std; +namespace MosesTuning +{ + + ScoreArray::ScoreArray() : m_num_scores(0), m_index("") {} @@ -160,3 +164,6 @@ bool ScoreArray::check_consistency() const } return true; } + +} + diff --git a/mert/ScoreArray.h b/mert/ScoreArray.h index 64d019daf..12b9d7c70 100644 --- a/mert/ScoreArray.h +++ b/mert/ScoreArray.h @@ -15,6 +15,9 @@ #include "ScoreStats.h" +namespace MosesTuning +{ + const char SCORES_TXT_BEGIN[] = "SCORES_TXT_BEGIN_0"; const char SCORES_TXT_END[] = "SCORES_TXT_END_0"; const char SCORES_BIN_BEGIN[] = "SCORES_BIN_BEGIN_0"; @@ -83,4 +86,6 @@ public: bool check_consistency() const; }; +} + #endif // MERT_SCORE_ARRAY_H_ diff --git a/mert/ScoreData.cpp b/mert/ScoreData.cpp index 4fc4cf2c7..7eb14b4ea 100644 --- a/mert/ScoreData.cpp +++ b/mert/ScoreData.cpp @@ -16,6 +16,10 @@ using namespace std; +namespace MosesTuning +{ + + ScoreData::ScoreData(Scorer* scorer) : m_scorer(scorer) { @@ -133,3 +137,6 @@ void ScoreData::setIndex() j++; } } + +} + diff --git a/mert/ScoreData.h b/mert/ScoreData.h index 5113bcee9..f4acd9c18 100644 --- a/mert/ScoreData.h +++ b/mert/ScoreData.h @@ -16,6 +16,10 @@ #include "ScoreArray.h" #include "ScoreStats.h" +namespace MosesTuning +{ + + class Scorer; class ScoreData @@ -105,4 +109,6 @@ public: } }; +} + #endif // MERT_SCORE_DATA_H_ diff --git a/mert/ScoreDataIterator.cpp b/mert/ScoreDataIterator.cpp index 4cac63c54..6efcf5bc3 100644 --- a/mert/ScoreDataIterator.cpp +++ b/mert/ScoreDataIterator.cpp @@ -26,6 +26,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA using namespace std; using namespace util; +namespace MosesTuning +{ + + ScoreDataIterator::ScoreDataIterator() {} ScoreDataIterator::ScoreDataIterator(const string& filename) { @@ -87,3 +91,5 @@ const vector<ScoreDataItem>& ScoreDataIterator::dereference() const { return m_next; } +} + diff --git a/mert/ScoreDataIterator.h b/mert/ScoreDataIterator.h index 910e92165..92480def2 100644 --- a/mert/ScoreDataIterator.h +++ b/mert/ScoreDataIterator.h @@ -34,6 +34,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "FeatureDataIterator.h" +namespace MosesTuning +{ + + typedef std::vector<float> ScoreDataItem; class ScoreDataIterator : @@ -62,4 +66,7 @@ class ScoreDataIterator : std::vector<ScoreDataItem> m_next; }; +} + + #endif // MERT_SCORE_DATA_ITERATOR_H_ diff --git a/mert/ScoreStats.cpp b/mert/ScoreStats.cpp index bcc61391b..20e707005 100644 --- a/mert/ScoreStats.cpp +++ b/mert/ScoreStats.cpp @@ -17,6 +17,10 @@ namespace { const int kAvailableSize = 8; } // namespace +namespace MosesTuning +{ + + ScoreStats::ScoreStats() : m_available_size(kAvailableSize), m_entries(0), m_array(new ScoreStatsType[m_available_size]) {} @@ -136,7 +140,6 @@ ostream& operator<<(ostream& o, const ScoreStats& e) return o; } -//ADDED_BY_TS bool operator==(const ScoreStats& s1, const ScoreStats& s2) { size_t size = s1.size(); @@ -150,4 +153,5 @@ bool operator==(const ScoreStats& s1, const ScoreStats& s2) { return true; } -//END_ADDED + +}
\ No newline at end of file diff --git a/mert/ScoreStats.h b/mert/ScoreStats.h index 2b7756a3b..4088b655e 100644 --- a/mert/ScoreStats.h +++ b/mert/ScoreStats.h @@ -16,6 +16,10 @@ #include "Types.h" +namespace MosesTuning +{ + + class ScoreStats { private: @@ -90,8 +94,8 @@ public: friend std::ostream& operator<<(std::ostream& o, const ScoreStats& e); }; -//ADDED_BY_TS bool operator==(const ScoreStats& s1, const ScoreStats& s2); -//END_ADDED + +} #endif // MERT_SCORE_STATS_H_ diff --git a/mert/Scorer.cpp b/mert/Scorer.cpp index ba6ca1f6b..b8688eafc 100644 --- a/mert/Scorer.cpp +++ b/mert/Scorer.cpp @@ -8,6 +8,10 @@ using namespace std; +namespace MosesTuning +{ + + Scorer::Scorer(const string& name, const string& config) : m_name(name), m_vocab(mert::VocabularyFactory::GetVocabulary()), @@ -137,3 +141,4 @@ float Scorer::score(const candidates_t& candidates) const { return scores[0]; } +} diff --git a/mert/Scorer.h b/mert/Scorer.h index 8b90ec625..b1bc17bbb 100644 --- a/mert/Scorer.h +++ b/mert/Scorer.h @@ -10,15 +10,18 @@ #include "Types.h" #include "ScoreData.h" -class PreProcessFilter; -class ScoreStats; - namespace mert { class Vocabulary; } // namespace mert +namespace MosesTuning +{ + +class PreProcessFilter; +class ScoreStats; + enum ScorerRegularisationStrategy {REG_NONE, REG_AVERAGE, REG_MINIMUM}; /** @@ -193,5 +196,6 @@ namespace { } // namespace +} #endif // MERT_SCORER_H_ diff --git a/mert/ScorerFactory.cpp b/mert/ScorerFactory.cpp index d86bb8ef9..157ebb23b 100644 --- a/mert/ScorerFactory.cpp +++ b/mert/ScorerFactory.cpp @@ -13,6 +13,10 @@ using namespace std; +namespace MosesTuning +{ + + vector<string> ScorerFactory::getTypes() { vector<string> types; types.push_back(string("BLEU")); @@ -53,3 +57,6 @@ Scorer* ScorerFactory::getScorer(const string& type, const string& config) { } } } + +} + diff --git a/mert/ScorerFactory.h b/mert/ScorerFactory.h index 6752817ef..e8b33d87c 100644 --- a/mert/ScorerFactory.h +++ b/mert/ScorerFactory.h @@ -4,6 +4,10 @@ #include <vector> #include <string> +namespace MosesTuning +{ + + class Scorer; class ScorerFactory @@ -18,4 +22,6 @@ private: ~ScorerFactory() {} }; +} + #endif // MERT_SCORER_FACTORY_H_ diff --git a/mert/SemposOverlapping.cpp b/mert/SemposOverlapping.cpp index f27f188f7..ffcabaab2 100644 --- a/mert/SemposOverlapping.cpp +++ b/mert/SemposOverlapping.cpp @@ -8,10 +8,14 @@ using namespace std; namespace { -SemposOverlapping* g_overlapping = NULL; +MosesTuning::SemposOverlapping* g_overlapping = NULL; } // namespace +namespace MosesTuning +{ + + SemposOverlapping* SemposOverlappingFactory::GetOverlapping(const string& str, const SemposScorer* sempos) { if (str == "cap-micro") { return new CapMicroOverlapping(sempos); @@ -107,3 +111,5 @@ float CapMacroOverlapping::calculateScore(const vector<int>& stats) const if (n == 0) return 1; return sum / n; } + +} diff --git a/mert/SemposOverlapping.h b/mert/SemposOverlapping.h index e16ffe7bb..3b5a99f7f 100644 --- a/mert/SemposOverlapping.h +++ b/mert/SemposOverlapping.h @@ -7,6 +7,10 @@ #include <utility> #include <vector> +namespace MosesTuning +{ + + class SemposScorer; // TODO: need comments about this number. @@ -87,4 +91,6 @@ public: const SemposScorer* semposScorer; }; +} + #endif // MERT_SEMPOSOVERLAPPING_H_ diff --git a/mert/SemposScorer.cpp b/mert/SemposScorer.cpp index 7f4b3cc14..8dd1fc8ee 100644 --- a/mert/SemposScorer.cpp +++ b/mert/SemposScorer.cpp @@ -10,6 +10,10 @@ using namespace std; +namespace MosesTuning +{ + + SemposScorer::SemposScorer(const string& config) : StatisticsBasedScorer("SEMPOS", config), m_ovr(SemposOverlappingFactory::GetOverlapping(getConfig("overlapping", "cap-micro"),this)), @@ -178,3 +182,6 @@ void SemposScorer::loadWeights(const string& weightsfile) } } + +} + diff --git a/mert/SemposScorer.h b/mert/SemposScorer.h index 9d1f418f9..bde064349 100644 --- a/mert/SemposScorer.h +++ b/mert/SemposScorer.h @@ -17,6 +17,10 @@ #include "SemposOverlapping.h" #include "StatisticsBasedScorer.h" +namespace MosesTuning +{ + + /** * This class represents sempos based metrics. */ @@ -62,4 +66,6 @@ private: SemposScorer& operator=(const SemposScorer&); }; +} + #endif // MERT_SEMPOSSCORER_H_ diff --git a/mert/SentenceLevelScorer.cpp b/mert/SentenceLevelScorer.cpp index 2f047def5..df3bbb5c1 100644 --- a/mert/SentenceLevelScorer.cpp +++ b/mert/SentenceLevelScorer.cpp @@ -11,6 +11,9 @@ using namespace std; +namespace MosesTuning +{ + /** The sentence level scores have already been calculated, just need to average them and include the differences. Allows scores which are floats **/ @@ -100,3 +103,6 @@ void SentenceLevelScorer::score(const candidates_t& candidates, const diffs_t& } } } + +} + diff --git a/mert/SentenceLevelScorer.h b/mert/SentenceLevelScorer.h index f35e66325..b875c8af9 100644 --- a/mert/SentenceLevelScorer.h +++ b/mert/SentenceLevelScorer.h @@ -15,6 +15,10 @@ #include <vector> #include <boost/spirit/home/support/detail/lexer/runtime_error.hpp> +namespace MosesTuning +{ + + /** * Abstract base class for scorers that work by using sentence level * statistics eg. permutation distance metrics **/ @@ -79,5 +83,6 @@ protected: }; +} #endif diff --git a/mert/Singleton.h b/mert/Singleton.h index 9fef3e639..473517170 100644 --- a/mert/Singleton.h +++ b/mert/Singleton.h @@ -3,6 +3,10 @@ #include <cstdlib> +namespace MosesTuning +{ + + // thread *un*safe singleton. // TODO: replace this with thread-safe singleton. template <typename T> @@ -30,4 +34,6 @@ class Singleton { template <typename T> T* Singleton<T>::m_instance = NULL; +} + #endif // MERT_SINGLETON_H_ diff --git a/mert/StatisticsBasedScorer.cpp b/mert/StatisticsBasedScorer.cpp index 2da5fd211..05dd95939 100644 --- a/mert/StatisticsBasedScorer.cpp +++ b/mert/StatisticsBasedScorer.cpp @@ -11,6 +11,10 @@ using namespace std; +namespace MosesTuning +{ + + StatisticsBasedScorer::StatisticsBasedScorer(const string& name, const string& config) : Scorer(name,config) { //configure regularisation @@ -117,3 +121,6 @@ void StatisticsBasedScorer::score(const candidates_t& candidates, const diffs_t } } } + +} + diff --git a/mert/StatisticsBasedScorer.h b/mert/StatisticsBasedScorer.h index fe73f8b5e..ca32535ad 100644 --- a/mert/StatisticsBasedScorer.h +++ b/mert/StatisticsBasedScorer.h @@ -10,6 +10,11 @@ #define mert_lib_StatisticsBasedScorer_h #include "Scorer.h" + +namespace MosesTuning +{ + + /** * Abstract base class for Scorers that work by adding statistics across all * outout sentences, then apply some formula, e.g., BLEU, PER. @@ -40,6 +45,6 @@ protected: std::size_t m_regularization_window; }; - +} // namespace #endif diff --git a/mert/TerScorer.cpp b/mert/TerScorer.cpp index ef0f737ae..cc7cf1630 100644 --- a/mert/TerScorer.cpp +++ b/mert/TerScorer.cpp @@ -12,6 +12,10 @@ using namespace std; using namespace TERCpp; +namespace MosesTuning +{ + + TerScorer::TerScorer(const string& config) : StatisticsBasedScorer("TER",config), kLENGTH(2) {} @@ -108,3 +112,5 @@ float TerScorer::calculateScore(const vector<int>& comps) const return (1.0+(num / denom)); } } + +} diff --git a/mert/TerScorer.h b/mert/TerScorer.h index 48ef5e2b0..0229f5e8c 100644 --- a/mert/TerScorer.h +++ b/mert/TerScorer.h @@ -8,6 +8,10 @@ #include "Types.h" #include "StatisticsBasedScorer.h" +namespace MosesTuning +{ + + class ScoreStats; /** @@ -47,4 +51,6 @@ private: TerScorer& operator=(const TerScorer&); }; +} + #endif // MERT_TER_SCORER_H_ diff --git a/mert/Timer.cpp b/mert/Timer.cpp index 5235edb04..088be93a5 100644 --- a/mert/Timer.cpp +++ b/mert/Timer.cpp @@ -22,6 +22,10 @@ uint64_t GetTimeOfDayMicroSeconds() { } // namespace +namespace MosesTuning +{ + + void Timer::GetCPUTimeMicroSeconds(Timer::CPUTime* cpu_time) const { #if !defined(_WIN32) && !defined(_WIN64) struct rusage usage; @@ -102,3 +106,5 @@ std::string Timer::ToString() const { return res; } + +} diff --git a/mert/Timer.h b/mert/Timer.h index 7b1101b50..bae4ab6b3 100644 --- a/mert/Timer.h +++ b/mert/Timer.h @@ -5,6 +5,10 @@ #include <string> #include <stdint.h> +namespace MosesTuning +{ + + class Timer { private: @@ -102,4 +106,7 @@ inline std::ostream& operator<<(std::ostream& os, const Timer& t) { return os; } +} + + #endif // MERT_TIMER_H_ diff --git a/mert/Types.h b/mert/Types.h index ae452afa6..b4c03a89a 100644 --- a/mert/Types.h +++ b/mert/Types.h @@ -6,6 +6,9 @@ #include <string> #include <utility> +namespace MosesTuning +{ + class FeatureStats; class FeatureArray; class FeatureData; @@ -42,4 +45,6 @@ typedef std::map<std::string, std::size_t> name2idx; typedef enum { HAMMING_DISTANCE=0, KENDALL_DISTANCE } distanceMetric_t; typedef enum { REFERENCE_CHOICE_AVERAGE=0, REFERENCE_CHOICE_CLOSEST } distanceMetricReferenceChoice_t; +} + #endif // MERT_TYPE_H_ diff --git a/mert/Util.cpp b/mert/Util.cpp index 952aaf9aa..ac7d1803b 100644 --- a/mert/Util.cpp +++ b/mert/Util.cpp @@ -13,7 +13,7 @@ using namespace std; namespace { -Timer g_timer; +MosesTuning::Timer g_timer; int g_verbose = 0; bool FindDelimiter(const std::string &str, const std::string &delim, size_t *pos) @@ -24,6 +24,9 @@ bool FindDelimiter(const std::string &str, const std::string &delim, size_t *pos } // namespace +namespace MosesTuning +{ + int verboselevel() { return g_verbose; @@ -86,3 +89,5 @@ double GetUserTime() { return g_timer.get_elapsed_cpu_time(); } + +} diff --git a/mert/Util.h b/mert/Util.h index abbd39306..e2071bf1f 100644 --- a/mert/Util.h +++ b/mert/Util.h @@ -22,6 +22,9 @@ #include "Types.h" +namespace MosesTuning +{ + #ifdef TRACE_ENABLE #define TRACE_ERR(str) { std::cerr << str; } #else @@ -130,4 +133,6 @@ void ResetUserTime(); void PrintUserTime(const std::string &message); double GetUserTime(); +} + #endif // MERT_UTIL_H_ diff --git a/mert/Vocabulary.cpp b/mert/Vocabulary.cpp index ccabe2d84..239d88ced 100644 --- a/mert/Vocabulary.cpp +++ b/mert/Vocabulary.cpp @@ -30,7 +30,7 @@ bool Vocabulary::Lookup(const std::string&str , int* v) const { Vocabulary* VocabularyFactory::GetVocabulary() { if (g_vocab == NULL) { - return Singleton<Vocabulary>::GetInstance(); + return MosesTuning::Singleton<Vocabulary>::GetInstance(); } else { return g_vocab; } diff --git a/mert/mert.cpp b/mert/mert.cpp index bbad8fe38..5f43e2b16 100644 --- a/mert/mert.cpp +++ b/mert/mert.cpp @@ -28,6 +28,7 @@ #include "../moses/src/ThreadPool.h" using namespace std; +using namespace MosesTuning; namespace { |