mosesdecoder/mert/ScorerFactory.cpp

65 lines
1.6 KiB
C++
Raw Normal View History

2011-11-14 15:06:10 +04:00
#include "ScorerFactory.h"
#include <stdexcept>
#include "Scorer.h"
#include "BleuScorer.h"
#include "BleuDocScorer.h"
2011-11-14 15:06:10 +04:00
#include "PerScorer.h"
#include "TerScorer.h"
#include "CderScorer.h"
#include "InterpolatedScorer.h"
#include "SemposScorer.h"
#include "PermutationScorer.h"
2011-11-14 15:06:10 +04:00
using namespace std;
namespace MosesTuning
{
2013-05-29 21:16:15 +04:00
vector<string> ScorerFactory::getTypes()
{
2011-11-14 15:06:10 +04:00
vector<string> types;
types.push_back(string("BLEU"));
types.push_back(string("BLEUDOC"));
2011-11-14 15:06:10 +04:00
types.push_back(string("PER"));
types.push_back(string("TER"));
types.push_back(string("CDER"));
types.push_back(string("WER"));
2011-11-14 15:06:10 +04:00
types.push_back(string("MERGE"));
types.push_back(string("SEMPOS"));
types.push_back(string("LRSCORE"));
2011-11-14 15:06:10 +04:00
return types;
}
2013-05-29 21:16:15 +04:00
Scorer* ScorerFactory::getScorer(const string& type, const string& config)
{
2011-11-14 15:06:10 +04:00
if (type == "BLEU") {
return new BleuScorer(config);
} else if (type == "BLEUDOC") {
return new BleuDocScorer(config);
2011-11-14 15:06:10 +04:00
} else if (type == "PER") {
return new PerScorer(config);
2011-11-14 15:06:10 +04:00
} else if (type == "TER") {
return new TerScorer(config);
2011-11-14 15:06:10 +04:00
} else if (type == "CDER") {
return new CderScorer(config, true);
} else if (type == "WER") {
// CderScorer can compute both CDER and WER metric
return new CderScorer(config, false);
} else if (type == "SEMPOS") {
return new SemposScorer(config);
2012-07-10 12:25:00 +04:00
} else if ((type == "HAMMING") || (type == "KENDALL")) {
return (PermutationScorer*) new PermutationScorer(type, config);
2011-11-14 15:06:10 +04:00
} else {
if (type.find(',') != string::npos) {
return new InterpolatedScorer(type, config);
2013-05-29 21:16:15 +04:00
} else {
throw runtime_error("Unknown scorer type: " + type);
}
2011-11-14 15:06:10 +04:00
}
}
}