Skip to content

Commit

Permalink
对双数组trie树的小优化
Browse files Browse the repository at this point in the history
  • Loading branch information
hankcs committed Sep 4, 2016
1 parent 275b06b commit 727166e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Expand Up @@ -669,14 +669,12 @@ public int exactMatchSearch(String key, int pos, int len, int nodePos)

int result = -1;

char[] keyChars = key.toCharArray();

int b = base[nodePos];
int p;

for (int i = pos; i < len; i++)
{
p = b + (int) (keyChars[i]) + 1;
p = b + (int) (key.charAt(i)) + 1;
if (b == check[p])
b = base[p];
else
Expand Down
Expand Up @@ -23,25 +23,25 @@ public class DemoTraditionalChinese2SimplifiedChinese
public static void main(String[] args)
{
System.out.println(HanLP.convertToTraditionalChinese("“以后等你当上皇后,就能买草莓庆祝了”。发现一根白头发"));
System.out.println(HanLP.convertToSimplifiedChinese("憑藉筆記簿型電腦寫程式HelloWorld"));

This comment has been minimized.

Copy link
@stefanxfy

stefanxfy Dec 9, 2021

繁2简时,如果有地方获取一个检索到繁体字以及在什么位置的关系表,如[{ 繁体字1: [offset list] }, { 繁体字2: [offset list] }] 就更好了。
同理简2繁。
我debug了一下是可以获取offset的,但是代码没办法修改,希望能给使用者更大的自由度。

System.out.println(HanLP.convertToSimplifiedChinese("憑藉筆記簿型電腦寫程式HanLP"));
// 简体转台湾繁体
System.out.println(HanLP.s2tw("我在台湾写代码"));
System.out.println(HanLP.s2tw("hankcs在台湾写代码"));
// 台湾繁体转简体
System.out.println(HanLP.tw2s("我在臺灣寫程式碼"));
System.out.println(HanLP.tw2s("hankcs在臺灣寫程式碼"));
// 简体转香港繁体
System.out.println(HanLP.s2hk("我在香港写代码"));
System.out.println(HanLP.s2hk("hankcs在香港写代码"));
// 香港繁体转简体
System.out.println(HanLP.hk2s("我在香港寫代碼"));
System.out.println(HanLP.hk2s("hankcs在香港寫代碼"));
// 香港繁体转台湾繁体
System.out.println(HanLP.hk2tw("我在臺灣寫代碼"));
System.out.println(HanLP.hk2tw("hankcs在臺灣寫代碼"));
// 台湾繁体转香港繁体
System.out.println(HanLP.tw2hk("我在香港寫程式碼"));
System.out.println(HanLP.tw2hk("hankcs在香港寫程式碼"));

// 香港/台湾繁体和HanLP标准繁体的互转
System.out.println(HanLP.t2tw("我在臺灣寫代碼"));
System.out.println(HanLP.t2hk("我在臺灣寫代碼"));
System.out.println(HanLP.t2tw("hankcs在臺灣寫代碼"));
System.out.println(HanLP.t2hk("hankcs在臺灣寫代碼"));

System.out.println(HanLP.tw2t("我在臺灣寫程式碼"));
System.out.println(HanLP.hk2t("我在台灣寫代碼"));
System.out.println(HanLP.tw2t("hankcs在臺灣寫程式碼"));
System.out.println(HanLP.hk2t("hankcs在台灣寫代碼"));
}
}

0 comments on commit 727166e

Please sign in to comment.