Skip to content

Resolves [BUG] tot_len_ratio being inf when src.size() is zero #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/fast_align.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ void InitialPass(const unsigned kNULL, const bool use_null, TTable* s2t,
string line;
bool flag = false;
int lc = 0;
int skipped_lines = 0;
cerr << "INITIAL PASS " << endl;
while (true) {
getline(in, line);
Expand All @@ -259,7 +260,9 @@ void InitialPass(const unsigned kNULL, const bool use_null, TTable* s2t,
if (is_reverse)
swap(src, trg);
if (src.size() == 0 || trg.size() == 0) {
cerr << "Error in line " << lc << "\n" << line << endl;
cerr << "Error in line " << lc << ". Skipped.\n" << line << endl;
skipped_lines++;
continue;
}
*tot_len_ratio += static_cast<double>(trg.size()) / static_cast<double>(src.size());
*n_target_tokens += trg.size();
Expand Down Expand Up @@ -288,10 +291,11 @@ void InitialPass(const unsigned kNULL, const bool use_null, TTable* s2t,
}
AddTranslationOptions(insert_buffer, s2t);

mean_srclen_multiplier = (*tot_len_ratio) / lc;
mean_srclen_multiplier = (*tot_len_ratio) / (lc - skipped_lines);
if (flag) {
cerr << endl;
}
cerr << "number of skipped lines = " << skipped_lines << endl;
cerr << "expected target length = source length * " << mean_srclen_multiplier << endl;
}

Expand Down