From 8ee039b68b401d552728af5d3be88d01baf02385 Mon Sep 17 00:00:00 2001 From: hankcs Date: Thu, 17 Jun 2021 22:10:28 -0400 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E7=A6=81=E7=94=A8=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=88=B7=E6=96=B0=E8=AF=8D=E5=85=B8=E7=BC=93=E5=AD=98?= =?UTF-8?q?=EF=BC=88CustomDictionaryAutoRefreshCache=3Dfalse=EF=BC=89fix?= =?UTF-8?q?=20https://github.com/hankcs/HanLP/issues/1655?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/hankcs/hanlp/HanLP.java | 5 +++++ .../com/hankcs/hanlp/dictionary/DynamicCustomDictionary.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/hankcs/hanlp/HanLP.java b/src/main/java/com/hankcs/hanlp/HanLP.java index cd0ea0764..4f196c367 100644 --- a/src/main/java/com/hankcs/hanlp/HanLP.java +++ b/src/main/java/com/hankcs/hanlp/HanLP.java @@ -75,6 +75,10 @@ public static final class Config * 用户自定义词典路径 */ public static String CustomDictionaryPath[] = new String[]{"data/dictionary/custom/CustomDictionary.txt"}; + /** + * 用户自定义词典是否自动重新生成缓存(根据词典文件的最后修改时间是否大于缓存文件的时间判断) + */ + public static boolean CustomDictionaryAutoRefreshCache = true; /** * 2元语法词典路径 */ @@ -274,6 +278,7 @@ public static final class Config } } CustomDictionaryPath = pathArray; + CustomDictionaryAutoRefreshCache = "true".equals(p.getProperty("CustomDictionaryAutoRefreshCache", "true")); tcDictionaryRoot = root + p.getProperty("tcDictionaryRoot", tcDictionaryRoot); if (!tcDictionaryRoot.endsWith("/")) tcDictionaryRoot += '/'; PinyinDictionaryPath = root + p.getProperty("PinyinDictionaryPath", PinyinDictionaryPath); diff --git a/src/main/java/com/hankcs/hanlp/dictionary/DynamicCustomDictionary.java b/src/main/java/com/hankcs/hanlp/dictionary/DynamicCustomDictionary.java index c6c1f1ae9..b8cf7f5c1 100644 --- a/src/main/java/com/hankcs/hanlp/dictionary/DynamicCustomDictionary.java +++ b/src/main/java/com/hankcs/hanlp/dictionary/DynamicCustomDictionary.java @@ -386,7 +386,7 @@ public static boolean loadDat(String path, String customDicPath[], DoubleArrayTr { try { - if (isDicNeedUpdate(path, customDicPath)) + if (HanLP.Config.CustomDictionaryAutoRefreshCache && isDicNeedUpdate(path, customDicPath)) { return false; }