From ef28d970d0bb1aa16d033387b30857e4533356da Mon Sep 17 00:00:00 2001 From: hankcs Date: Thu, 21 Feb 2019 19:08:16 -0500 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3CustomDictionary.reload();=20?= =?UTF-8?q?fix=20https://github.com/hankcs/HanLP/issues/1100?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/hankcs/hanlp/dictionary/CustomDictionary.java | 1 + .../com/hankcs/hanlp/dictionary/CustomDictionaryTest.java | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/main/java/com/hankcs/hanlp/dictionary/CustomDictionary.java b/src/main/java/com/hankcs/hanlp/dictionary/CustomDictionary.java index 2a32be950..3eae2101f 100644 --- a/src/main/java/com/hankcs/hanlp/dictionary/CustomDictionary.java +++ b/src/main/java/com/hankcs/hanlp/dictionary/CustomDictionary.java @@ -654,6 +654,7 @@ public static boolean reload() String path[] = HanLP.Config.CustomDictionaryPath; if (path == null || path.length == 0) return false; IOUtil.deleteFile(path[0] + Predefine.BIN_EXT); // 删掉缓存 + dat = new DoubleArrayTrie(); return loadMainDictionary(path[0]); } } diff --git a/src/test/java/com/hankcs/hanlp/dictionary/CustomDictionaryTest.java b/src/test/java/com/hankcs/hanlp/dictionary/CustomDictionaryTest.java index 978636fc9..884e8bbaa 100644 --- a/src/test/java/com/hankcs/hanlp/dictionary/CustomDictionaryTest.java +++ b/src/test/java/com/hankcs/hanlp/dictionary/CustomDictionaryTest.java @@ -169,4 +169,10 @@ public void testIssue540() throws Exception CustomDictionary.remove("123"); CustomDictionary.remove("摩根"); } + + public void testReload() + { + CustomDictionary.reload(); + System.out.println(HanLP.segment("自然语言处理")); + } } \ No newline at end of file