diff options
author | Peng Wu <alexepico@gmail.com> | 2017-01-22 15:32:02 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2017-01-22 15:32:02 +0800 |
commit | ec83c02c3779a82489829d8284506a88bc73534b (patch) | |
tree | 975cc419c9d8d70252ec94f596a51072b6b3e4bf /src/lookup/phonetic_lookup.cpp | |
parent | 70d3d40b972b8b582782d72c05ce2b2d3fcac82c (diff) | |
download | libpinyin-ec83c02c3779a82489829d8284506a88bc73534b.tar.gz libpinyin-ec83c02c3779a82489829d8284506a88bc73534b.tar.xz libpinyin-ec83c02c3779a82489829d8284506a88bc73534b.zip |
write diff_result method
Diffstat (limited to 'src/lookup/phonetic_lookup.cpp')
-rw-r--r-- | src/lookup/phonetic_lookup.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/lookup/phonetic_lookup.cpp b/src/lookup/phonetic_lookup.cpp index aa1fc60..5c3a6ce 100644 --- a/src/lookup/phonetic_lookup.cpp +++ b/src/lookup/phonetic_lookup.cpp @@ -172,4 +172,43 @@ bool ForwardPhoneticConstraints::validate_constraint(PhoneticKeyMatrix * matrix) } +bool ForwardPhoneticConstraints::diff_result(MatchResults best, + MatchResults other){ + bool changed = false; + + assert(best->len == other->len); + + for (size_t pos = 0; pos < other->len; ++pos) { + phrase_token_t other_token = g_array_index(other, phrase_token_t, pos); + + if (null_token == other_token) + continue; + + phrase_token_t best_token = g_array_index(best, phrase_token_t, pos); + + /* the same token */ + if (best_token == other_token) + continue; + + changed = true; + + /* skip the tail node, as not searched in nbest algorithm. */ + size_t next_pos = other->len - 1; + for (size_t i = pos + 1; i < other->len; ++i) { + phrase_token_t token = g_array_index(other, phrase_token_t, i); + + if (null_token != token) { + next_pos = i; + break; + } + } + + assert(add_constraint(pos, next_pos, other_token)); + } + + /* best and other results should be different. */ + assert(changed); + return changed; +} + }; |