diff options
35 files changed, 93 insertions, 146 deletions
diff --git a/mert/BleuScorer.cpp b/mert/BleuScorer.cpp index 7844d4a51..c7bd0e90f 100644 --- a/mert/BleuScorer.cpp +++ b/mert/BleuScorer.cpp @@ -1,4 +1,9 @@ #include "BleuScorer.h" +#include <cmath> +#include <fstream> +#include <iterator> +#include <stdexcept> +#include "Util.h" BleuScorer::BleuScorer(const string& config) : StatisticsBasedScorer("BLEU",config), diff --git a/mert/BleuScorer.h b/mert/BleuScorer.h index c5681ad55..7e0e18b53 100644 --- a/mert/BleuScorer.h +++ b/mert/BleuScorer.h @@ -1,16 +1,10 @@ #ifndef __BLEUSCORER_H__ #define __BLEUSCORER_H__ -#include <algorithm> -#include <cmath> #include <iostream> -#include <iterator> -#include <set> -#include <sstream> -#include <stdexcept> #include <string> #include <vector> -#include <limits.h> + #include "Types.h" #include "ScoreData.h" #include "Scorer.h" diff --git a/mert/CderScorer.cpp b/mert/CderScorer.cpp index e503eb7e5..fc8d69f5f 100644 --- a/mert/CderScorer.cpp +++ b/mert/CderScorer.cpp @@ -1,8 +1,6 @@ #include "CderScorer.h" - +#include <fstream> #include <stdexcept> -#include <iostream> -#include <algorithm> CderScorer::CderScorer(const string& config) : StatisticsBasedScorer("CDER",config) {} diff --git a/mert/CderScorer.h b/mert/CderScorer.h index 802690a99..359ac31e9 100644 --- a/mert/CderScorer.h +++ b/mert/CderScorer.h @@ -3,10 +3,10 @@ #include <algorithm> #include <iostream> +#include <iterator> #include <string> #include <vector> #include "Types.h" -#include "ScoreData.h" #include "Scorer.h" using namespace std; diff --git a/mert/Data.cpp b/mert/Data.cpp index 2d3318753..a9b09357a 100644 --- a/mert/Data.cpp +++ b/mert/Data.cpp @@ -7,6 +7,7 @@ */ #include <cassert> +#include <cmath> #include <fstream> #include "Data.h" diff --git a/mert/FeatureArray.cpp b/mert/FeatureArray.cpp index 3b3dd8c38..cffafa82a 100644 --- a/mert/FeatureArray.cpp +++ b/mert/FeatureArray.cpp @@ -6,10 +6,9 @@ * */ -#include <fstream> #include "FeatureArray.h" -#include "Util.h" #include "FileStream.h" +#include "Util.h" namespace { const char FEATURES_TXT_BEGIN[] = "FEATURES_TXT_BEGIN_0"; diff --git a/mert/FeatureArray.h b/mert/FeatureArray.h index c1c12fc47..9012e0830 100644 --- a/mert/FeatureArray.h +++ b/mert/FeatureArray.h @@ -9,16 +9,13 @@ #ifndef FEATURE_ARRAY_H #define FEATURE_ARRAY_H -using namespace std; - -#include <limits> #include <vector> #include <iostream> #include <fstream> - -#include "Util.h" #include "FeatureStats.h" +using namespace std; + class FeatureArray { private: diff --git a/mert/FeatureData.cpp b/mert/FeatureData.cpp index 07bfa6a02..ed76bca3b 100644 --- a/mert/FeatureData.cpp +++ b/mert/FeatureData.cpp @@ -6,8 +6,9 @@ * */ -#include <fstream> #include "FeatureData.h" + +#include <limits> #include "FileStream.h" #include "Util.h" diff --git a/mert/FeatureData.h b/mert/FeatureData.h index 3a96e74f1..6934cdcba 100644 --- a/mert/FeatureData.h +++ b/mert/FeatureData.h @@ -11,11 +11,9 @@ using namespace std; -#include <limits> #include <vector> #include <iostream> - -#include "Util.h" +#include <stdexcept> #include "FeatureArray.h" class FeatureData diff --git a/mert/FeatureStats.cpp b/mert/FeatureStats.cpp index 86778e770..e7682518c 100644 --- a/mert/FeatureStats.cpp +++ b/mert/FeatureStats.cpp @@ -6,10 +6,11 @@ * */ -#include <cmath> -#include <fstream> #include "FeatureStats.h" +#include <cmath> +#include "Util.h" + namespace { const int kAvailableSize = 8; } // namespace diff --git a/mert/FeatureStats.h b/mert/FeatureStats.h index fb7d46350..2ba17aed8 100644 --- a/mert/FeatureStats.h +++ b/mert/FeatureStats.h @@ -11,11 +11,12 @@ using namespace std; -#include <limits> -#include <vector> +#include <fstream> #include <iostream> - -#include "Util.h" +#include <map> +#include <string> +#include <vector> +#include "Types.h" // Minimal sparse vector class SparseVector { diff --git a/mert/Makefile.am b/mert/Makefile.am index fe2909e1a..a93be4b81 100644 --- a/mert/Makefile.am +++ b/mert/Makefile.am @@ -13,6 +13,7 @@ BleuScorer.cpp \ Point.cpp \ PerScorer.cpp \ Scorer.cpp \ +ScorerFactory.cpp \ Optimizer.cpp \ TERsrc/alignmentStruct.cpp \ TERsrc/hashMap.cpp \ diff --git a/mert/MergeScorer.cpp b/mert/MergeScorer.cpp index 2e3fb5de4..0b9de73f1 100644 --- a/mert/MergeScorer.cpp +++ b/mert/MergeScorer.cpp @@ -1,9 +1,17 @@ #include "MergeScorer.h" + +#include <cmath> +#include <stdexcept> +#include "ScoreStats.h" +#include "TerScorer.h" +#include "BleuScorer.h" +#include "PerScorer.h" +#include "CderScorer.h" + #include "TERsrc/tercalc.h" #include "TERsrc/terAlignment.h" using namespace TERCpp; -using namespace std; MergeScorer::MergeScorer(const string& config) : StatisticsBasedScorer("MERGE",config), kLENGTH(4) {} diff --git a/mert/MergeScorer.h b/mert/MergeScorer.h index 67b4b5e48..10e034ac6 100644 --- a/mert/MergeScorer.h +++ b/mert/MergeScorer.h @@ -1,31 +1,19 @@ #ifndef __MERGESCORER_H__ #define __MERGESCORER_H__ -#include <algorithm> -#include <cmath> #include <iostream> -#include <iterator> #include <set> -#include <sstream> -#include <stdexcept> #include <string> #include <vector> -#include <limits.h> -#include "Types.h" -#include "ScoreData.h" + #include "Scorer.h" -#include "TerScorer.h" -#include "BleuScorer.h" -#include "PerScorer.h" -#include "CderScorer.h" -//#include "TERsrc/tercalc.h" -//#include "TERsrc/terAlignment.h" using namespace std; -using namespace TERCpp; // enum MergeReferenceLengthStrategy { MERGE_AVERAGE, MERGE_SHORTEST, MERGE_CLOSEST }; +class PerScorer; +class ScoreStats; /** * Merge scoring. diff --git a/mert/Optimizer.cpp b/mert/Optimizer.cpp index 13067ea1d..cd9703ddd 100644 --- a/mert/Optimizer.cpp +++ b/mert/Optimizer.cpp @@ -1,11 +1,15 @@ +#include "Optimizer.h" + +#include <cmath> #include <cassert> #include <vector> #include <limits> -#include <list> +#include <map> #include <cfloat> #include <iostream> -#include "Optimizer.h" +#include "Point.h" +#include "Util.h" using namespace std; diff --git a/mert/Optimizer.h b/mert/Optimizer.h index 8ca804926..aa588994d 100644 --- a/mert/Optimizer.h +++ b/mert/Optimizer.h @@ -2,16 +2,16 @@ #define OPTIMIZER_H #include <vector> -#include "FeatureStats.h" +#include <string> #include "FeatureData.h" -#include "FeatureArray.h" #include "Scorer.h" -#include "Point.h" #include "Types.h" +using namespace std; + typedef float featurescore; -using namespace std; +class Point; /** * Abstract optimizer class. diff --git a/mert/PerScorer.cpp b/mert/PerScorer.cpp index 6564a7f22..765cb0876 100644 --- a/mert/PerScorer.cpp +++ b/mert/PerScorer.cpp @@ -1,5 +1,13 @@ #include "PerScorer.h" +#include <fstream> +#include <stdexcept> + +#include "ScoreStats.h" +#include "Util.h" + +using namespace std; + PerScorer::PerScorer(const string& config) : StatisticsBasedScorer("PER",config) {} diff --git a/mert/PerScorer.h b/mert/PerScorer.h index f8d0fa59c..800a3caf1 100644 --- a/mert/PerScorer.h +++ b/mert/PerScorer.h @@ -1,22 +1,18 @@ #ifndef __PERSCORER_H__ #define __PERSCORER_H__ -#include <algorithm> -#include <cmath> #include <iostream> -#include <iterator> #include <set> #include <sstream> -#include <stdexcept> #include <string> #include <vector> #include "Types.h" -#include "ScoreData.h" #include "Scorer.h" - using namespace std; +class ScoreStats; + /** * An implementation of position-independent word error rate. * This is defined as diff --git a/mert/Point.cpp b/mert/Point.cpp index a21c754fb..9b4899dc5 100644 --- a/mert/Point.cpp +++ b/mert/Point.cpp @@ -1,7 +1,9 @@ #include "Point.h" + #include <cmath> #include <cstdlib> #include <cassert> +#include "FeatureStats.h" using namespace std; diff --git a/mert/Point.h b/mert/Point.h index 0aa649b1a..55d173215 100644 --- a/mert/Point.h +++ b/mert/Point.h @@ -1,10 +1,12 @@ #ifndef POINT_H #define POINT_H +#include <fstream> +#include <map> #include <vector> #include "Types.h" -#include "FeatureStats.h" +class FeatureStats; class Optimizer; /** diff --git a/mert/ScoreArray.cpp b/mert/ScoreArray.cpp index c7e4daaf6..7c2bfc423 100644 --- a/mert/ScoreArray.cpp +++ b/mert/ScoreArray.cpp @@ -6,7 +6,6 @@ * */ -#include <fstream> #include "ScoreArray.h" #include "Util.h" #include "FileStream.h" diff --git a/mert/ScoreArray.h b/mert/ScoreArray.h index a25943a19..83c786c3e 100644 --- a/mert/ScoreArray.h +++ b/mert/ScoreArray.h @@ -11,12 +11,10 @@ using namespace std; -#include <limits> #include <vector> #include <iostream> -#include <fstream> +#include <string> -#include "Util.h" #include "ScoreStats.h" class ScoreArray diff --git a/mert/ScoreData.cpp b/mert/ScoreData.cpp index 875d75fe9..e79595d06 100644 --- a/mert/ScoreData.cpp +++ b/mert/ScoreData.cpp @@ -6,7 +6,6 @@ * */ -#include <fstream> #include "ScoreData.h" #include "Scorer.h" #include "Util.h" diff --git a/mert/ScoreData.h b/mert/ScoreData.h index 295344ed0..cb4fb30f9 100644 --- a/mert/ScoreData.h +++ b/mert/ScoreData.h @@ -9,14 +9,15 @@ #ifndef SCORE_DATA_H #define SCORE_DATA_H -using namespace std; - -#include <limits> +#include <fstream> #include <vector> #include <iostream> - -#include "Util.h" +#include <stdexcept> +#include <string> #include "ScoreArray.h" +#include "ScoreStats.h" + +using namespace std; class Scorer; diff --git a/mert/ScoreStats.cpp b/mert/ScoreStats.cpp index 3d7ac42a1..eb1750983 100644 --- a/mert/ScoreStats.cpp +++ b/mert/ScoreStats.cpp @@ -6,7 +6,7 @@ * */ -#include <fstream> +#include "Util.h" #include "ScoreStats.h" namespace { diff --git a/mert/ScoreStats.h b/mert/ScoreStats.h index 3a609120d..43a6f1f23 100644 --- a/mert/ScoreStats.h +++ b/mert/ScoreStats.h @@ -9,14 +9,15 @@ #ifndef SCORE_STATS_H #define SCORE_STATS_H -using namespace std; - -#include <limits> #include <vector> #include <iostream> +#include <fstream> #include <cstdlib> +#include <cstring> -#include "Util.h" +#include "Types.h" + +using namespace std; class ScoreStats { diff --git a/mert/Scorer.h b/mert/Scorer.h index 801f40d98..c36f2e03a 100644 --- a/mert/Scorer.h +++ b/mert/Scorer.h @@ -1,12 +1,7 @@ #ifndef __SCORER_H__ #define __SCORER_H__ -#include <algorithm> -#include <cmath> #include <iostream> -#include <iterator> -#include <limits> -#include <set> #include <sstream> #include <stdexcept> #include <string> diff --git a/mert/ScorerFactory.h b/mert/ScorerFactory.h index 3a1da4783..f6054c770 100644 --- a/mert/ScorerFactory.h +++ b/mert/ScorerFactory.h @@ -1,53 +1,17 @@ #ifndef __SCORER_FACTORY_H #define __SCORER_FACTORY_H -#include <algorithm> -#include <cmath> -#include <iostream> -#include <iterator> -#include <set> -#include <sstream> -#include <stdexcept> -#include <string> #include <vector> -#include "Types.h" -#include "Scorer.h" -#include "BleuScorer.h" -#include "PerScorer.h" -#include "TerScorer.h" -#include "CderScorer.h" -#include "MergeScorer.h" +#include <string> -using namespace std; +class Scorer; class ScorerFactory { public: - static vector<string> getTypes() { - vector<string> types; - types.push_back(string("BLEU")); - types.push_back(string("PER")); - types.push_back(string("TER")); - types.push_back(string("CDER")); - types.push_back(string("MERGE")); - return types; - } + static std::vector<std::string> getTypes(); - static Scorer* getScorer(const string& type, const string& config = "") { - if (type == "BLEU") { - return (BleuScorer*) new BleuScorer(config); - } else if (type == "PER") { - return (PerScorer*) new PerScorer(config); - } else if (type == "TER") { - return (TerScorer*) new TerScorer(config); - } else if (type == "CDER") { - return (CderScorer*) new CderScorer(config); - } else if (type == "MERGE") { - return (MergeScorer*) new MergeScorer(config); - } else { - throw runtime_error("Unknown scorer type: " + type); - } - } + static Scorer* getScorer(const std::string& type, const std::string& config = ""); private: ScorerFactory() {} diff --git a/mert/TerScorer.cpp b/mert/TerScorer.cpp index 3efedafa0..3f4ca65e8 100644 --- a/mert/TerScorer.cpp +++ b/mert/TerScorer.cpp @@ -1,9 +1,15 @@ #include "TerScorer.h" + +#include <cmath> +#include <sstream> +#include <stdexcept> + +#include "ScoreStats.h" #include "TERsrc/tercalc.h" #include "TERsrc/terAlignment.h" +#include "Util.h" using namespace TERCpp; -using namespace std; TerScorer::TerScorer(const string& config) : StatisticsBasedScorer("TER",config), kLENGTH(2) {} diff --git a/mert/TerScorer.h b/mert/TerScorer.h index 411d942bf..0e9996a99 100644 --- a/mert/TerScorer.h +++ b/mert/TerScorer.h @@ -1,27 +1,19 @@ #ifndef __TERSCORER_H__ #define __TERSCORER_H__ -#include <algorithm> -#include <cmath> #include <iostream> -#include <iterator> #include <set> -#include <sstream> -#include <stdexcept> #include <string> #include <vector> -#include <limits.h> + #include "Types.h" -#include "ScoreData.h" #include "Scorer.h" -#include "TERsrc/tercalc.h" -#include "TERsrc/terAlignment.h" using namespace std; -using namespace TERCpp; // enum TerReferenceLengthStrategy { TER_AVERAGE, TER_SHORTEST, TER_CLOSEST }; +class ScoreStats; /** * TER scoring diff --git a/mert/Timer.cpp b/mert/Timer.cpp index 9c917408a..373eb4a2e 100644 --- a/mert/Timer.cpp +++ b/mert/Timer.cpp @@ -1,8 +1,5 @@ -#include <ctime> -#include <iostream> -#include <iomanip> -#include "Util.h" #include "Timer.h" +#include "Util.h" double Timer::elapsed_time() { diff --git a/mert/Timer.h b/mert/Timer.h index 71cc00cd8..403547620 100644 --- a/mert/Timer.h +++ b/mert/Timer.h @@ -4,7 +4,6 @@ #include <ctime> #include <iostream> #include <iomanip> -#include "Util.h" class Timer { diff --git a/mert/Util.cpp b/mert/Util.cpp index a5d68713e..3769c71e7 100644 --- a/mert/Util.cpp +++ b/mert/Util.cpp @@ -6,9 +6,7 @@ * */ -#include <stdexcept> #include "Util.h" - #include "Timer.h" using namespace std; diff --git a/mert/Util.h b/mert/Util.h index 0880a7d3d..e59a9288d 100644 --- a/mert/Util.h +++ b/mert/Util.h @@ -9,15 +9,8 @@ #ifndef UTIL_H #define UTIL_H -using namespace std; - #include <stdexcept> #include <limits> - -#define US_NOSET (numeric_limits<unsigned short>::max()) - -#define MAX_LINE 1024 - #include <vector> #include <map> #include <iostream> @@ -26,11 +19,11 @@ using namespace std; #include <cstring> #include "Types.h" -#include "ScoreStats.h" -#include "FeatureStats.h" -class ScoreStats; -class FeatureStats; +using namespace std; + +#define US_NOSET (numeric_limits<unsigned short>::max()) +#define MAX_LINE 1024 #ifdef TRACE_ENABLE #define TRACE_ERR(str) { std::cerr << str; } diff --git a/mert/evaluator.cpp b/mert/evaluator.cpp index 8545f086a..c1d6039da 100644 --- a/mert/evaluator.cpp +++ b/mert/evaluator.cpp @@ -1,3 +1,4 @@ +#include <fstream> #include <iostream> #include <string> #include <vector> |