All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hankcs.hanlp.dictionary.ts.SimplifiedToTaiwanChineseDictionary Maven / Gradle / Ivy

There is a newer version: portable-1.8.5
Show newest version
/*
 * 
 * Hankcs
 * [email protected]
 * 2016-08-30 AM10:29
 *
 * 
 * Copyright (c) 2008-2016, 码农场. All Right Reserved, http://www.hankcs.com/
 * This source is subject to Hankcs. Please contact Hankcs to get more information.
 * 
 */
package com.hankcs.hanlp.dictionary.ts;

import com.hankcs.hanlp.HanLP;
import com.hankcs.hanlp.collection.AhoCorasick.AhoCorasickDoubleArrayTrie;

import java.util.TreeMap;

import static com.hankcs.hanlp.utility.Predefine.BIN_EXT;
import static com.hankcs.hanlp.utility.Predefine.logger;

/**
 * 简体转台湾繁体
 * @author hankcs
 */
public class SimplifiedToTaiwanChineseDictionary extends BaseChineseDictionary
{
    static AhoCorasickDoubleArrayTrie trie = new AhoCorasickDoubleArrayTrie();
    static
    {
        long start = System.currentTimeMillis();
        String datPath = HanLP.Config.tcDictionaryRoot + "s2tw";
        if (!loadDat(datPath, trie))
        {
            TreeMap s2t = new TreeMap();
            TreeMap t2tw = new TreeMap();
            if (!load(s2t, false, HanLP.Config.tcDictionaryRoot + "s2t.txt") ||
                    !load(t2tw, false, HanLP.Config.tcDictionaryRoot + "t2tw.txt"))
            {
                throw new IllegalArgumentException("简体转台湾繁体词典加载失败");
            }
            combineChain(s2t, t2tw);
            trie.build(s2t);
            saveDat(datPath, trie, s2t.entrySet());
        }
        logger.info("简体转台湾繁体词典加载成功,耗时" + (System.currentTimeMillis() - start) + "ms");
    }

    public static String convertToTraditionalTaiwanChinese(String simplifiedChineseString)
    {
        return segLongest(simplifiedChineseString.toCharArray(), trie);
    }

    public static String convertToTraditionalTaiwanChinese(char[] simplifiedChinese)
    {
        return segLongest(simplifiedChinese, trie);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy