diff options
Diffstat (limited to 'mteval')
-rw-r--r-- | mteval/mbr_kbest.cc | 8 | ||||
-rw-r--r-- | mteval/ns_ter.cc | 8 | ||||
-rw-r--r-- | mteval/scorer.cc | 23 | ||||
-rw-r--r-- | mteval/ter.cc | 8 |
4 files changed, 35 insertions, 12 deletions
diff --git a/mteval/mbr_kbest.cc b/mteval/mbr_kbest.cc index 2519bc01..787c03bd 100644 --- a/mteval/mbr_kbest.cc +++ b/mteval/mbr_kbest.cc @@ -1,9 +1,14 @@ #include <iostream> #include <vector> -#include <tr1/unordered_map> #include <boost/program_options.hpp> #include <boost/functional/hash.hpp> +#ifdef HAVE_CXX11 +# include <unordered_map> +#else +# include <tr1/unordered_map> +namespace std { using std::tr1::unordered_map; } +#endif #include "prob.h" #include "tdict.h" @@ -12,7 +17,6 @@ #include "stringlib.h" using namespace std; -using namespace std::tr1; namespace po = boost::program_options; diff --git a/mteval/ns_ter.cc b/mteval/ns_ter.cc index 0e1008db..f0d84098 100644 --- a/mteval/ns_ter.cc +++ b/mteval/ns_ter.cc @@ -4,7 +4,12 @@ #include <cassert> #include <iostream> #include <limits> -#include <tr1/unordered_map> +#ifdef HAVE_CXX11 +# include <unordered_map> +#else +# include <tr1/unordered_map> +namespace std { using std::tr1::unordered_map; } +#endif #include <set> #include <boost/functional/hash.hpp> #include "tdict.h" @@ -20,7 +25,6 @@ static const unsigned kREF_WORDCOUNT = 4; static const unsigned kDUMMY_LAST_ENTRY = 5; using namespace std; -using namespace std::tr1; bool TERMetric::IsErrorMetric() const { return true; diff --git a/mteval/scorer.cc b/mteval/scorer.cc index de84e076..9eb9a76e 100644 --- a/mteval/scorer.cc +++ b/mteval/scorer.cc @@ -594,26 +594,29 @@ void DocScorer::Init( const ScoreType type, const vector<string>& ref_files, const string& src_file, bool verbose) { + cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" + "!!! This code is using the deprecated DocScorer interface, please fix !!!\n" + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"; scorers_.clear(); - // TODO stop using valarray, start using ReadFile + static const WordID kDIV = TD::Convert("|||"); cerr << "Loading references (" << ref_files.size() << " files)\n"; ReadFile srcrf; if (type == AER && src_file.size() > 0) { cerr << " (source=" << src_file << ")\n"; srcrf.Init(src_file); } + std::vector<WordID> tmp; std::vector<ReadFile> ifs(ref_files.begin(),ref_files.end()); for (int i=0; i < ref_files.size(); ++i) ifs[i].Init(ref_files[i]); char buf[64000]; bool expect_eof = false; int line=0; while (ifs[0].get()) { - vector<vector<WordID> > refs(ref_files.size()); + vector<vector<WordID> > refs; for (int i=0; i < ref_files.size(); ++i) { istream &in=ifs[i].get(); if (in.eof()) break; in.getline(buf, 64000); - refs[i].clear(); if (strlen(buf) == 0) { if (in.eof()) { if (!expect_eof) { @@ -622,9 +625,17 @@ void DocScorer::Init( } break; } - } else { - TD::ConvertSentence(buf, &refs[i]); - assert(!refs[i].empty()); + } else { // process reference + tmp.clear(); + TD::ConvertSentence(buf, &tmp); + unsigned last = 0; + for (unsigned j = 0; j < tmp.size(); ++j) { + if (tmp[j] == kDIV) { + refs.push_back(vector<WordID>(tmp.begin() + last, tmp.begin() + j)); + last = j + 1; + } + } + refs.push_back(vector<WordID>(tmp.begin() + last, tmp.end())); } assert(!expect_eof); } diff --git a/mteval/ter.cc b/mteval/ter.cc index cacc5b00..9da54306 100644 --- a/mteval/ter.cc +++ b/mteval/ter.cc @@ -5,7 +5,12 @@ #include <iostream> #include <limits> #include <sstream> -#include <tr1/unordered_map> +#ifdef HAVE_CXX11 +# include <unordered_map> +#else +# include <tr1/unordered_map> +namespace std { using std::tr1::unordered_map; } +#endif #include <set> #include <valarray> #include <boost/functional/hash.hpp> @@ -16,7 +21,6 @@ const bool ter_use_average_ref_len = true; const int ter_short_circuit_long_sentences = -1; using namespace std; -using namespace std::tr1; struct COSTS { static const float substitution; |