blob: 6ba74030d3943c491aed1e6820748af246eab371 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#include "translator.h"
#include <iostream>
#include <vector>
#include "verbose.h"
using namespace std;
Translator::~Translator() {}
std::string Translator::GetDecoderType() const {
return "UNKNOWN";
}
void Translator::ProcessMarkupHints(const map<string, string>& kv) {
if (state_ != kUninitialized) {
cerr << "Translator::ProcessMarkupHints in wrong state: " << state_ << endl;
abort();
}
ProcessMarkupHintsImpl(kv);
state_ = kReadyToTranslate;
}
bool Translator::Translate(const std::string& src,
SentenceMetadata* smeta,
const std::vector<double>& weights,
Hypergraph* minus_lm_forest) {
if (state_ == kUninitialized) {
cerr << "Translator::Translate(...) must not be in uninitialized state!\n";
abort();
}
const bool result = TranslateImpl(src, smeta, weights, minus_lm_forest);
state_ = kTranslated;
return result;
}
void Translator::SentenceComplete() {
if (state_ != kTranslated) {
cerr << "Translator::Complete in unexpected state: " << state_ << endl;
// not fatal
}
SentenceCompleteImpl();
state_ = kUninitialized; // return to start state
}
// this may be overridden by translators that want to accept
// metadata
void Translator::ProcessMarkupHintsImpl(const map<string, string>& kv) {
int unprocessed = kv.size() - kv.count("id") - kv.count("psg");
if (!SILENT) cerr << "Inside translator process hints\n";
if (unprocessed > 0) {
cerr << "Sentence markup contains unprocessed data:\n";
for (map<string, string>::const_iterator it = kv.begin(); it != kv.end(); ++it) {
if (it->first == "id") continue;
cerr << " KEY[" << it->first << "] --> " << it->second << endl;
}
abort();
}
}
void Translator::SentenceCompleteImpl() {}
|