com.hankcs.hanlp.dictionary.CustomDictionary Java Examples
The following examples show how to use
com.hankcs.hanlp.dictionary.CustomDictionary.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Nlputil.java From dk-fitting with Apache License 2.0 | 6 votes |
/** * 添加词库 * * @param filePath 新的词库文件,每个词使用回车换行分隔 * @param encoding 编码 * @return 空—完成,其它—错误信息 */ public static String addCK(String filePath, String encoding) { if (filePath == null || encoding == null) return String.format("参数错误:addCK(%s, %s)", filePath, encoding); try { BufferedReader br = new BufferedReader(new InputStreamReader(IOUtil.newInputStream(filePath), encoding)); String line; synchronized (lockCustomDictionary) { while ((line = br.readLine()) != null) { CustomDictionary.insert(line); } } br.close(); } catch (Exception e) { System.out.println(e); return TextUtility.exceptionToString(e); } return "添加成功"; }
Example #2
Source File: DKNLPBase.java From dk-fitting with Apache License 2.0 | 6 votes |
/** * 添加词库 * * @param filePath 新的词库文件,每个词使用回车换行分隔 * @param encoding 编码 * @return 空—完成,其它—错误信息 */ public static String addCK(String filePath, String encoding) { if (filePath == null || encoding == null) return String.format("参数错误:addCK(%s, %s)", filePath, encoding); try { BufferedReader br = new BufferedReader(new InputStreamReader(IOUtil.newInputStream(filePath), encoding)); String line; synchronized (lockCustomDictionary) { while ((line = br.readLine()) != null) { CustomDictionary.insert(line); } } br.close(); } catch (Exception e) { return TextUtility.exceptionToString(e); } return null; }
Example #3
Source File: CustomDictionaryUtility.java From elasticsearch-analysis-hanlp with Apache License 2.0 | 5 votes |
public static boolean reload() { CustomDictionary.dat.getSize(); String[] paths = HanLP.Config.CustomDictionaryPath; if (paths == null || paths.length == 0) { return false; } logger.debug("begin delete hanlp custom dictionary cache"); IOUtil.deleteFile(paths[0] + Predefine.BIN_EXT); logger.debug("delete hanlp custom dictionary cache successfully"); return loadMainDictionary(paths[0]); }