summaryrefslogtreecommitdiff
path: root/decoder/trule.cc
diff options
context:
space:
mode:
Diffstat (limited to 'decoder/trule.cc')
-rw-r--r--decoder/trule.cc26
1 files changed, 14 insertions, 12 deletions
diff --git a/decoder/trule.cc b/decoder/trule.cc
index 141b8faa..187a003d 100644
--- a/decoder/trule.cc
+++ b/decoder/trule.cc
@@ -18,7 +18,7 @@ bool TRule::IsGoal() const {
}
static WordID ConvertTrgString(const string& w) {
- int len = w.size();
+ const unsigned len = w.size();
WordID id = 0;
// [X,0] or [0]
// for target rules, we ignore the category, just keep the index
@@ -33,7 +33,7 @@ static WordID ConvertTrgString(const string& w) {
}
static WordID ConvertSrcString(const string& w, bool mono = false) {
- int len = w.size();
+ const unsigned len = w.size();
// [X,0]
// for source rules, we keep the category and ignore the index (source rules are
// always numbered 1, 2, 3...
@@ -60,7 +60,7 @@ static WordID ConvertSrcString(const string& w, bool mono = false) {
static WordID ConvertLHS(const string& w) {
if (w[0] == '[') {
- int len = w.size();
+ const unsigned len = w.size();
if (len < 3) { cerr << "Format error: " << w << endl; exit(1); }
return TD::Convert(w.substr(1, len-2)) * -1;
} else {
@@ -100,6 +100,8 @@ namespace {
// callback for lexer
int n_assigned=0;
void assign_trule(const TRulePtr& new_rule, const unsigned int ctf_level, const TRulePtr& coarse_rule, void* extra) {
+ (void) ctf_level;
+ (void) coarse_rule;
TRule *assignto=(TRule *)extra;
*assignto=*new_rule;
++n_assigned;
@@ -143,15 +145,15 @@ bool TRule::ReadFromString(const string& line, bool strict, bool mono) {
string ss;
getline(is, ss);
//cerr << "L: " << ss << endl;
- int start = 0;
- int len = ss.size();
+ unsigned start = 0;
+ unsigned len = ss.size();
const size_t ppos = ss.find(" |||");
if (ppos != string::npos) { len = ppos; }
while (start < len) {
while(start < len && (ss[start] == ' ' || ss[start] == ';'))
++start;
if (start == len) break;
- int end = start + 1;
+ unsigned end = start + 1;
while(end < len && (ss[end] != '=' && ss[end] != ' ' && ss[end] != ';'))
++end;
if (end == len || ss[end] == ' ' || ss[end] == ';') {
@@ -188,7 +190,7 @@ bool TRule::ReadFromString(const string& line, bool strict, bool mono) {
while(is>>w && w!="|||") { e_.push_back(ConvertTrgString(w)); }
f_ = e_;
int x = ConvertLHS("[X]");
- for (int i = 0; i < f_.size(); ++i)
+ for (unsigned i = 0; i < f_.size(); ++i)
if (f_[i] <= 0) { f_[i] = x; }
} else {
cerr << "F: " << format << endl;
@@ -197,7 +199,7 @@ bool TRule::ReadFromString(const string& line, bool strict, bool mono) {
if (mono) {
e_ = f_;
int ci = 0;
- for (int i = 0; i < e_.size(); ++i)
+ for (unsigned i = 0; i < e_.size(); ++i)
if (e_[i] < 0)
e_[i] = ci--;
}
@@ -208,7 +210,7 @@ bool TRule::ReadFromString(const string& line, bool strict, bool mono) {
bool TRule::SanityCheck() const {
vector<int> used(f_.size(), 0);
int ac = 0;
- for (int i = 0; i < e_.size(); ++i) {
+ for (unsigned i = 0; i < e_.size(); ++i) {
int ind = e_[i];
if (ind > 0) continue;
ind = -ind;
@@ -238,7 +240,7 @@ string TRule::AsString(bool verbose) const {
if (lhs_ && verbose) {
os << '[' << TD::Convert(lhs_ * -1) << "] |||";
}
- for (int i = 0; i < f_.size(); ++i) {
+ for (unsigned i = 0; i < f_.size(); ++i) {
const WordID& w = f_[i];
if (w < 0) {
int wi = w * -1;
@@ -249,7 +251,7 @@ string TRule::AsString(bool verbose) const {
}
}
os << " ||| ";
- for (int i =0; i<e_.size(); ++i) {
+ for (unsigned i =0; i<e_.size(); ++i) {
if (i) os << ' ';
const WordID& w = e_[i];
if (w < 1)
@@ -261,7 +263,7 @@ string TRule::AsString(bool verbose) const {
os << " ||| " << scores_;
if (!a_.empty()) {
os << " |||";
- for (int i = 0; i < a_.size(); ++i)
+ for (unsigned i = 0; i < a_.size(); ++i)
os << ' ' << a_[i];
}
}