summaryrefslogtreecommitdiffstats
path: root/src/lookup/phonetic_lookup.h
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2017-01-19 17:20:13 +0800
committerPeng Wu <alexepico@gmail.com>2017-01-19 17:20:13 +0800
commit05e009b90626d989349e9cf60e2af45aac4a4ffe (patch)
tree1b8537a77e145bb65403352061ed096023e5412c /src/lookup/phonetic_lookup.h
parent91de72879019d2461330dbcd16991f1b73d41f82 (diff)
downloadlibpinyin-05e009b90626d989349e9cf60e2af45aac4a4ffe.tar.gz
libpinyin-05e009b90626d989349e9cf60e2af45aac4a4ffe.tar.xz
libpinyin-05e009b90626d989349e9cf60e2af45aac4a4ffe.zip
write trellis_value_less_than function
Diffstat (limited to 'src/lookup/phonetic_lookup.h')
-rw-r--r--src/lookup/phonetic_lookup.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lookup/phonetic_lookup.h b/src/lookup/phonetic_lookup.h
index 065a31b..fc8272f 100644
--- a/src/lookup/phonetic_lookup.h
+++ b/src/lookup/phonetic_lookup.h
@@ -24,6 +24,7 @@
#include "novel_types.h"
#include <limits.h>
+#include <math.h>
#include "phonetic_key_matrix.h"
#include "ngram.h"
@@ -53,6 +54,27 @@ struct trellis_value_t {
}
};
+template <gint32 nbest>
+static bool inline trellis_value_less_than(const trellis_value_t * exist_item,
+ const trellis_value_t * new_item) {
+ /* shorter sentence */
+ if (exist_item->m_sentence_length > new_item->m_sentence_length ||
+ /* the same length but better possibility */
+ (exist_item->m_sentence_length == new_item->m_sentence_length &&
+ exist_item->m_poss < new_item->m_poss))
+ return true;
+
+ if (nbest > 1) {
+ /* allow longer sentence */
+ if (exist_item->m_current_index == 0 &&
+ exist_item->m_sentence_length == new_item->m_sentence_length + 1 &&
+ exist_item->m_poss < new_item->m_poss)
+ return true;
+ }
+
+ return false;
+}
+
#if 0
struct matrix_value_t {
phrase_token_t m_cur_token;