From 3c3a7f89f9b8fc225f62d1675a194b4daa1a9cb7 Mon Sep 17 00:00:00 2001 From: youshipeng <745045993@qq.com> Date: Fri, 25 Nov 2022 17:10:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A2=9E=E9=87=8F=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dictionary/SynonymDictionary.java | 5 ++-- .../com/hanlp/tokenizer/update/HotUpdate.java | 27 +++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/hanlp/tokenizer/dictionary/SynonymDictionary.java b/src/main/java/com/hanlp/tokenizer/dictionary/SynonymDictionary.java index b491899..10c7db9 100644 --- a/src/main/java/com/hanlp/tokenizer/dictionary/SynonymDictionary.java +++ b/src/main/java/com/hanlp/tokenizer/dictionary/SynonymDictionary.java @@ -31,8 +31,9 @@ public class SynonymDictionary { private SynonymDictionary() {} public synchronized static void reloadCustomerSynonyms(TreeMap> treeMap) { - customerTrie = new DoubleArrayTrie<>(); - customerTrie.build(treeMap); + DoubleArrayTrie> newCustomerTrie = new DoubleArrayTrie<>(); + newCustomerTrie.build(treeMap); + customerTrie = newCustomerTrie; } // private synchronized static void reload() { diff --git a/src/main/java/com/hanlp/tokenizer/update/HotUpdate.java b/src/main/java/com/hanlp/tokenizer/update/HotUpdate.java index 697fa8d..ed890f4 100644 --- a/src/main/java/com/hanlp/tokenizer/update/HotUpdate.java +++ b/src/main/java/com/hanlp/tokenizer/update/HotUpdate.java @@ -99,7 +99,7 @@ public class HotUpdate { } else { CustomDictionary.insert(line); } - logger.info(line); + logger.info("add " + line); } } }, 10, 60, TimeUnit.SECONDS); @@ -111,8 +111,13 @@ public class HotUpdate { void processResponse(BufferedReader reader) throws IOException { String line; while ((line = reader.readLine()) != null) { - CustomDictionary.remove(line); - logger.info(line); + String[] message = line.split(","); + if (message.length == 2) { + CustomDictionary.remove(message[0]); + } else { + CustomDictionary.remove(line); + } + logger.info("remove " + line); } } }, 10, 60, TimeUnit.SECONDS); @@ -133,7 +138,7 @@ public class HotUpdate { treeMap.put(word, new HashSet<>(words)); } }); - logger.info(line); + logger.info("synonym " + line); } SynonymDictionary.reloadCustomerSynonyms(treeMap); logger.info("synonymous sync success."); @@ -199,9 +204,9 @@ public class HotUpdate { if ((!isEmpty(currentLastModified) && !currentLastModified.equals(lastModified)) || (!isEmpty(currentETags) && !currentETags.equals(eTags))) { logger.info(address.getDomain() + " update dictionary."); + updateDictionary(); lastModified = currentLastModified; eTags = currentETags; - updateDictionary(); } else { logger.info(address.getDomain() + " result no changed and skip current request."); } @@ -227,6 +232,18 @@ public class HotUpdate { return address; } + @Override + public HashMap getHeaders() { + return new HashMap() {{ + if (lastModified != null) { + put("If-Modified-Since", lastModified); + } + if (eTags != null) { + put("If-None-Match", eTags); + } + }}; + } + @Override public Void readResult(int statusCode, HashMap headers, HttpEntity httpEntity) { BufferedReader reader = null; -- Gitee