summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2017-02-10 14:15:12 +0800
committerPeng Wu <alexepico@gmail.com>2017-02-10 14:15:12 +0800
commit012308bb33c81978617d91aef7352c2e5dd966a4 (patch)
tree5137d9f882f4e9d8ca914330f656c639657cee63
parent809efb9334e6b8644c8c5bfb180ab32fe8648825 (diff)
downloadlibpinyin-012308bb33c81978617d91aef7352c2e5dd966a4.zip
libpinyin-012308bb33c81978617d91aef7352c2e5dd966a4.tar.gz
libpinyin-012308bb33c81978617d91aef7352c2e5dd966a4.tar.xz
write pinyin_get_candidate_nbest_index function
-rw-r--r--src/libpinyin.ver1
-rw-r--r--src/pinyin.cpp37
-rw-r--r--src/pinyin.h14
3 files changed, 52 insertions, 0 deletions
diff --git a/src/libpinyin.ver b/src/libpinyin.ver
index d59c0e9..153c762 100644
--- a/src/libpinyin.ver
+++ b/src/libpinyin.ver
@@ -57,6 +57,7 @@ LIBPINYIN {
pinyin_get_candidate;
pinyin_get_candidate_type;
pinyin_get_candidate_string;
+ pinyin_get_candidate_nbest_index;
pinyin_get_pinyin_key;
pinyin_get_pinyin_key_rest;
pinyin_get_pinyin_key_rest_positions;
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index cea16bd..62bb9c3 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -2266,6 +2266,14 @@ bool pinyin_get_candidate_string(pinyin_instance_t * instance,
return true;
}
+bool pinyin_get_candidate_nbest_index(pinyin_instance_t * instance,
+ lookup_candidate_t * candidate,
+ guint8 * index) {
+ assert(NBEST_MATCH_CANDIDATE == candidate->m_candidate_type);
+ *index = candidate->m_nbest_index;
+ return true;
+}
+
#if 0
bool pinyin_get_n_pinyin(pinyin_instance_t * instance,
guint * num) {
@@ -2620,6 +2628,35 @@ bool pinyin_get_character_offset(pinyin_instance_t * instance,
return result;
}
+#if 0
+bool pinyin_get_character_offset(pinyin_instance_t * instance,
+ size_t offset,
+ size_t * plength) {
+ pinyin_context_t * context = instance->m_context;
+ FacadePhraseIndex * phrase_index = context->m_phrase_index;
+
+ PhoneticKeyMatrix & matrix = instance->m_matrix;
+ MatchResults results = instance->m_match_results;
+ _check_offset(matrix, offset);
+
+ size_t length = 0;
+ PhraseItem item;
+ for (size_t i = 0; i < offset; ++i) {
+ phrase_token_t token = g_array_index(results, phrase_token_t, i);
+ if (null_token == token)
+ continue;
+
+ int retval = phrase_index->get_phrase_item(token, item);
+ assert(ERROR_OK == retval);
+ guint8 len = item.get_phrase_length();
+ length += len;
+ }
+
+ *plength = length;
+ return true;
+}
+#endif
+
bool pinyin_get_n_phrase(pinyin_instance_t * instance,
guint * num) {
*num = instance->m_phrase_result->len;
diff --git a/src/pinyin.h b/src/pinyin.h
index 07ca2fc..7ebb82f 100644
--- a/src/pinyin.h
+++ b/src/pinyin.h
@@ -790,6 +790,20 @@ bool pinyin_get_candidate_string(pinyin_instance_t * instance,
const gchar ** utf8_str);
/**
+ * pinyin_get_candidate_nbest_index:
+ * @instance: the pinyin instance.
+ * @candidate: the lookup candidate.
+ * @index: the index of the nbest result.
+ * @returns: whether the get operation is successful.
+ *
+ * Get the nbest index of the candidate.
+ *
+ */
+bool pinyin_get_candidate_nbest_index(pinyin_instance_t * instance,
+ lookup_candidate_t * candidate,
+ guint8 * index);
+
+/**
* pinyin_get_pinyin_key:
* @instance: the pinyin instance.
* @offset: the offset of the pinyin key.