问:如何使用模糊音功能?
答:开启常规 模糊音功能的代码如下:
if (DWIMECore.init(DWIMECore.DWL_Chinese, keyType==26 ? DWIMECore.DWKBT_QWERTY : DWIMECore.DWKBT_DIGIT, DWIMECore.DWIM_PINYIN) == DWIMECore.DWR_OK) { // 这里演示开启 C<=>CH, S<=>SH, Z<=>ZH, AN<=>ANG, EN<=>ENG IN<=>ING 的模糊音,其它模糊同样方法添加。 DWIMECore.setPYFuzzy( DWIMECore.FUZZY_C_CH | DWIMECore.FUZZY_S_SH | DWIMECore.FUZZY_Z_ZH | DWIMECore.FUZZY_AN_ANG | DWIMECore.FUZZY_EN_ENG | DWIMECore.FUZZY_IN_ING ); }
我们的引擎还支持自定义模糊音,用于实现少数民族各种不同发音的需求,方法如何:
步骤1:初始化前,添加自定义模糊音,这里演示添加 j<=>c, zh<=>s 的模糊音, 代码如下:
// 配合 DWIMECore.FUZZY_CUSTOM1, DWIMECore.FUZZY_CUSTOM2 使用,最多5个 Object[] fuzzyFirst = {"j".toCharArray(), "c".toCharArray() }; Object[] fuzzySecond = {"zh".toCharArray(), "s".toCharArray()}; if (DWIMECore.customPYFuzzy(fuzzyFirst, fuzzySecond) != DWIMECore.DWR_OK) { // 设置失败 return false; }
步骤2:初始化后,开启模糊音,见下方代码:
if (DWIMECore.init(DWIMECore.DWL_Chinese, keyType==26 ? DWIMECore.DWKBT_QWERTY : DWIMECore.DWKBT_DIGIT, DWIMECore.DWIM_PINYIN) == DWIMECore.DWR_OK) { DWIMECore.setPYFuzzy( DWIMECore.FUZZY_C_CH | DWIMECore.FUZZY_S_SH | DWIMECore.FUZZY_Z_ZH | DWIMECore.FUZZY_AN_ANG | DWIMECore.FUZZY_EN_ENG | DWIMECore.FUZZY_IN_ING | DWIMECore.FUZZY_CUSTOM1 // j <=> zh 少数民族专用 | DWIMECore.FUZZY_CUSTOM2 // c <=> s 少数民族专用 ); }