summaryrefslogtreecommitdiffstats
path: root/src/storage
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-11-17 17:31:17 +0800
committerPeng Wu <alexepico@gmail.com>2011-11-17 17:31:53 +0800
commit77b35d500b9307793ab87870403e8db8b316c250 (patch)
tree5185dc5ba15c38c34a5aba7b41ed72d66f339119 /src/storage
parent96b2e5ba48baa9ada8e64eba9ad43001a90524ce (diff)
downloadlibpinyin-77b35d500b9307793ab87870403e8db8b316c250.tar.gz
libpinyin-77b35d500b9307793ab87870403e8db8b316c250.tar.xz
libpinyin-77b35d500b9307793ab87870403e8db8b316c250.zip
add compute lower/upper pinyin
Diffstat (limited to 'src/storage')
-rw-r--r--src/storage/pinyin_phrase2.h112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/storage/pinyin_phrase2.h b/src/storage/pinyin_phrase2.h
index 0f96856..65266fc 100644
--- a/src/storage/pinyin_phrase2.h
+++ b/src/storage/pinyin_phrase2.h
@@ -103,6 +103,118 @@ inline int pinyin_compare_with_ambiguities2(guint32 options,
return 0;
}
+/* compute pinyin lower bound */
+inline void compute_lower_value2(guint32 options,
+ ChewingKey * in_keys,
+ ChewingKey * out_keys,
+ int phrase_length) {
+ ChewingKey aKey;
+
+ for (int i = 0; i < phrase_length; ++i) {
+ int k; int sel;
+ aKey = in_keys[i];
+
+ /* compute lower initial */
+ sel = aKey.m_initial;
+ for (k = aKey.m_initial - 1; k >= CHEWING_ZERO_INITIAL; --k) {
+ if (0 != pinyin_compare_initial2
+ (options, (ChewingInitial)aKey.m_initial, (ChewingInitial)k))
+ break;
+ else
+ sel = k;
+ }
+ aKey.m_initial = (ChewingInitial)sel;
+
+ /* compute lower middle, skipped as no fuzzy pinyin here.
+ * if needed in future, still use pinyin_compare_middle_and_final2
+ * to check lower bound.
+ */
+
+ /* compute lower final */
+ sel = aKey.m_final;
+ for (k = aKey.m_final - 1; k >= CHEWING_ZERO_FINAL, --k) {
+ if (0 != pinyin_compare_middle_and_final2
+ (options,
+ (ChewingMiddle)aKey.m_middle, (ChewingMiddle) aKey.m_middle,
+ (ChewingFinal)aKey.m_final, (ChewingFinal)k))
+ break;
+ else
+ sel = k;
+ }
+ aKey.m_final = (ChewingFinal)sel;
+
+ /* compute lower tone */
+ sel = aKey.m_tone;
+ for (k = aKey.m_tone - 1; k >= CHEWING_ZERO_TONE; --k) {
+ if (0 != pinyin_compare_tone2
+ (options, (ChewingTone)aKey.m_tone, (ChewingTone)k))
+ break;
+ else
+ sel = k;
+ }
+ aKey.m_tone = (ChewingTone)sel;
+
+ /* save the result */
+ out_keys[i] = aKey;
+ }
+}
+
+/* compute pinyin upper bound */
+inline void compute_upper_value2(guint32 options,
+ ChewingKey * in_keys,
+ ChewingKey * out_keys,
+ int phrase_length) {
+ ChewingKey aKey;
+
+ for (int i = 0; i < phrase_length; ++i) {
+ int k; int sel;
+ aKey = in_keys[i];
+
+ /* compute upper initial */
+ sel = aKey.m_initial;
+ for (k = aKey.m_initial + 1; k <= CHEWING_LAST_INITIAL; ++k) {
+ if (0 != pinyin_compare_initial2
+ (options, (ChewingInitial)aKey.m_initial, (ChewingInitial)k))
+ break;
+ else
+ sel = k;
+ }
+ aKey.m_initial = (ChewingInitial)sel;
+
+ /* compute upper middle, skipped as no fuzzy pinyin here.
+ * if needed in future, still use pinyin_compare_middle_and_final2
+ * to check upper bound.
+ */
+
+ /* compute upper final */
+ sel = aKey.m_final;
+ for (k = aKey.m_final + 1; k <= CHEWING_LAST_FINAL; ++k) {
+ if (0 != pinyin_compare_middle_and_final2
+ (options,
+ (ChewingMiddle)aKey.m_middle, (ChewingMiddle)aKey.m_middle,
+ (ChewingFinal)aKey.m_final, (ChewingFinal)k))
+ break;
+ else
+ sel = k;
+ }
+ aKey.m_final = (ChewingFinal)sel;
+
+ /* compute upper tone */
+ sel = aKey.m_tone;
+ for (k = aKey.m_tone + 1; k <= CHEWING_LAST_TONE; ++k) {
+ if (0 != pinyin_compare_tone2
+ (options, (ChewingTone)aKey.m_tone, (ChewingTone)k))
+ break;
+ else
+ sel = k;
+ }
+ aKey.m_tone = (ChewingTone)sel;
+
+ /* save the result */
+ out_keys[i] = aKey;
+ }
+}
+
};
#endif