diff --git a/src/main/java/org/wltea/analyzer/configuration/Configuration.java b/src/main/java/org/wltea/analyzer/configuration/Configuration.java index bb78cc09..9b8f0bc1 100644 --- a/src/main/java/org/wltea/analyzer/configuration/Configuration.java +++ b/src/main/java/org/wltea/analyzer/configuration/Configuration.java @@ -62,7 +62,7 @@ public Configuration(Environment env, Settings settings) { Asserts.check(Objects.nonNull(settingEtymology), message); // 领域 String domain = settings.get("domain", "default-domain"); - logger.info("new configuration for domain {} etymology {}", domain, etymology); + logger.info("new configuration for domain '{}' etymology '{}'", domain, etymology); // 配置初始化 Configuration.initial(env); // 构造词源及领域 diff --git a/src/main/java/org/wltea/analyzer/dictionary/Dictionary.java b/src/main/java/org/wltea/analyzer/dictionary/Dictionary.java index 8b55eaa9..9bd8f509 100644 --- a/src/main/java/org/wltea/analyzer/dictionary/Dictionary.java +++ b/src/main/java/org/wltea/analyzer/dictionary/Dictionary.java @@ -88,7 +88,7 @@ private void initial(boolean enableRemoteDict) { this.loadStopWordDict(); if (enableRemoteDict) { - logger.info("Remote Dictionary enabled!"); + logger.info("Remote Dictionary enabled for '{}'!", this.domainUri); ConfigurationProperties properties = Configuration.getProperties(); ConfigurationProperties.Remote.Refresh remoteRefresh = properties.getRemoteRefresh(); // 建立监控线程 - 主词库 @@ -121,7 +121,7 @@ public Hit matchInMainDict(char[] charArray) { * @return Hit 匹配结果描述 */ public Hit matchInMainDict(char[] charArray, int begin, int length) { - logger.info("matchInMainDict for {}", this.domainUri); + logger.info("matchInMainDict for '{}'", this.domainUri); return this.mainDictionary.match(charArray, begin, length); } @@ -131,7 +131,7 @@ public Hit matchInMainDict(char[] charArray, int begin, int length) { * @return Hit 匹配结果描述 */ public Hit matchInQuantifierDict(char[] charArray, int begin, int length) { - logger.info("matchInQuantifierDict for {}", this.domainUri); + logger.info("matchInQuantifierDict for '{}'", this.domainUri); return this.quantifierDictionary.match(charArray, begin, length); } @@ -141,7 +141,7 @@ public Hit matchInQuantifierDict(char[] charArray, int begin, int length) { * @return boolean */ public boolean isStopWord(char[] charArray, int begin, int length) { - logger.info("isStopWord for {}", this.domainUri); + logger.info("isStopWord for '{}'", this.domainUri); return this.stopWordsDictionary.match(charArray, begin, length).isMatch(); } @@ -157,7 +157,7 @@ private void loadMainDict() { this.mainDictionary.fillSegment(file, "Main DictFile"); // 加载扩展词典 List mainExtDictFiles = Configuration.getProperties().getMainExtDictFiles(); - this.loadLocalExtDict(this.mainDictionary, DictionaryType.MAIN_WORDS, mainExtDictFiles, "Main Extra DictFile"); + this.loadLocalExtDict(this.mainDictionary, mainExtDictFiles, "Main Extra DictFile"); // 加载远程自定义词库 this.loadRemoteExtDict(this.mainDictionary, DictionaryType.MAIN_WORDS); @@ -186,14 +186,13 @@ private void loadStopWordDict() { // 加载扩展停止词典 List extStopDictFiles = Configuration.getProperties().getExtStopDictFiles(); - this.loadLocalExtDict(this.stopWordsDictionary, DictionaryType.STOP_WORDS, extStopDictFiles, "Extra Stopwords"); + this.loadLocalExtDict(this.stopWordsDictionary, extStopDictFiles, "Extra Stopwords"); // 加载远程停用词典 this.loadRemoteExtDict(this.stopWordsDictionary, DictionaryType.STOP_WORDS); } private void loadLocalExtDict(DictSegment dictSegment, - DictionaryType dictionaryType, List extDictFiles, String name) { // 加载扩展词典配置 @@ -208,17 +207,16 @@ private void loadLocalExtDict(DictSegment dictSegment, private void loadRemoteExtDict(DictSegment dictSegment, DictionaryType dictionaryType) { - logger.info("[Remote DictFile Loading] for domain {}", this.domainUri); + logger.info("[Remote DictFile Loading] for domain '{}'", this.domainUri); Set remoteWords = DictionaryHelper.getRemoteWords(this, dictionaryType, this.domainUri); - //this.addWords(remoteWords, dictionaryType, true); // 如果找不到扩展的字典,则忽略 if (remoteWords.isEmpty()) { - logger.info("[Remote DictFile Loading] no new words for {}", this.domainUri); + logger.info("[Remote DictFile Loading] no new words for '{}'", this.domainUri); return; } remoteWords.forEach(word -> { // 加载远程词典数据到主内存中 - logger.info("[New {} Word] {}", dictionaryType.dictName, word); + logger.info("[New '{}' Word] '{}'", dictionaryType.dictName, word); dictSegment.fillSegment(word.toLowerCase().toCharArray()); }); } @@ -227,7 +225,7 @@ private void loadRemoteExtDict(DictSegment dictSegment, * 重新加载词典 */ public synchronized void reload(DictionaryType dictionaryType) { - logger.info("[Begin to reload] ik {} dictionary.", dictionaryType); + logger.info("[Begin to reload] ik '{}' dictionary.", dictionaryType); // 新开一个实例加载词典,减少加载过程对当前词典使用的影响 Dictionary tmpDict = new Dictionary(enableRemoteDict, domainUri); switch (dictionaryType) { @@ -248,6 +246,6 @@ public synchronized void reload(DictionaryType dictionaryType) { this.stopWordsDictionary = tmpDict.stopWordsDictionary; } } - logger.info("Reload ik {} dictionary finished.", dictionaryType); + logger.info("Reload ik '{}' dictionary finished.", dictionaryType); } } diff --git a/src/main/java/org/wltea/analyzer/dictionary/remote/HttpRemoteDictionary.java b/src/main/java/org/wltea/analyzer/dictionary/remote/HttpRemoteDictionary.java index 149b9cf8..02a7b03f 100644 --- a/src/main/java/org/wltea/analyzer/dictionary/remote/HttpRemoteDictionary.java +++ b/src/main/java/org/wltea/analyzer/dictionary/remote/HttpRemoteDictionary.java @@ -48,7 +48,7 @@ class HttpRemoteDictionary extends AbstractRemoteDictionary { public Set getRemoteWords(org.wltea.analyzer.dictionary.Dictionary dictionary, DictionaryType dictionaryType, URI domainUri) { - logger.info("[Remote DictFile Loading] For etymology 'http' and domain {}", domainUri); + logger.info("[Remote DictFile Loading] For etymology 'http' and domain '{}'", domainUri); Set words = new HashSet<>(); CloseableHttpResponse response; BufferedReader in; @@ -84,7 +84,7 @@ public Set getRemoteWords(org.wltea.analyzer.dictionary.Dictionary dicti } response.close(); } catch (IllegalStateException | IOException e) { - logger.error("getRemoteWords error {} location {}", e, location); + logger.error("getRemoteWords error '{}' location '{}'", e, location); } return words; } @@ -100,7 +100,7 @@ public Set getRemoteWords(org.wltea.analyzer.dictionary.Dictionary dicti public void reloadRemoteDictionary(Dictionary dictionary, DictionaryType dictionaryType, URI domainUri) { - logger.info("[Remote DictFile Reloading] For etymology 'http' and domain {}", domainUri); + logger.info("[Remote DictFile Reloading] For etymology 'http' and domain '{}'", domainUri); String location = this.getLocation(dictionaryType, domainUri); HttpHead head = new HttpHead(location); head.setConfig(REQUEST_CONFIG); @@ -145,9 +145,9 @@ public void reloadRemoteDictionary(Dictionary dictionary, } return; } - logger.info("remote_ext_dict {} return bad code {}", location, statusCode); + logger.info("remote_ext_dict '{}' return bad code '{}'", location, statusCode); } catch (Exception e) { - logger.error("remote_ext_dict error {} location {} !", e, location); + logger.error("remote_ext_dict error '{}' location '{}' !", e, location); } finally { try { if (response != null) { diff --git a/src/main/java/org/wltea/analyzer/dictionary/remote/MySQLRemoteDictionary.java b/src/main/java/org/wltea/analyzer/dictionary/remote/MySQLRemoteDictionary.java index 251a42b1..4694062b 100644 --- a/src/main/java/org/wltea/analyzer/dictionary/remote/MySQLRemoteDictionary.java +++ b/src/main/java/org/wltea/analyzer/dictionary/remote/MySQLRemoteDictionary.java @@ -33,7 +33,7 @@ public Set getRemoteWords(org.wltea.analyzer.dictionary.Dictionary dicti DictionaryType dictionaryType, String etymology, String domain) { - logger.info("[Remote DictFile Loading] For etymology 'mysql' and domain {}", domain); + logger.info("[Remote DictFile Loading] For etymology 'mysql' and domain '{}'", domain); Set words = new HashSet<>(); Connection connection = null; PreparedStatement statement = null; @@ -61,7 +61,7 @@ public Set getRemoteWords(org.wltea.analyzer.dictionary.Dictionary dicti public void reloadRemoteDictionary(Dictionary dictionary, DictionaryType dictionaryType, String domain) { - logger.info("[Remote DictFile Reloading] For etymology 'mysql' and domain {}", domain); + logger.info("[Remote DictFile Reloading] For etymology 'mysql' and domain '{}'", domain); Connection connection = null; PreparedStatement statement = null; ResultSet resultSet = null; @@ -72,17 +72,17 @@ public void reloadRemoteDictionary(Dictionary dictionary, statement.setString(1, domain); resultSet = statement.executeQuery(); if (!resultSet.next()) { - logger.info("Cannot find the `ik_sequence` and dictionary {} data", domain); + logger.info("Cannot find the `ik_sequence` and dictionary '{}' data", domain); return; } long maxId = resultSet.getLong("max_id"); long currentId = resultSet.getLong("current_id"); - logger.info("[Remote DictFile] maxId {} currentId {}", maxId, currentId); + logger.info("[Remote DictFile] maxId '{}' currentId '{}'", maxId, currentId); if (maxId != currentId) { // 更新currentId sql = String.format("current_id = %s WHERE domain = '%s'", maxId, domain); sql = String.format("UPDATE ik_sequence SET %s", sql); - logger.info("sql {}", sql); + logger.info("sql '{}'", sql); statement.execute(sql); dictionary.reload(dictionaryType); } diff --git a/src/main/java/org/wltea/analyzer/dictionary/remote/RedisRemoteDictionary.java b/src/main/java/org/wltea/analyzer/dictionary/remote/RedisRemoteDictionary.java index af4d8de1..5290f579 100644 --- a/src/main/java/org/wltea/analyzer/dictionary/remote/RedisRemoteDictionary.java +++ b/src/main/java/org/wltea/analyzer/dictionary/remote/RedisRemoteDictionary.java @@ -27,7 +27,7 @@ class RedisRemoteDictionary extends AbstractRemoteDictionary { private final StatefulRedisConnection redisConnection; - private final String KEY_PREFIX = "es-ik-words"; + private final static String KEY_PREFIX = "es-ik-words"; RedisRemoteDictionary() { // lettuce 默认支持connection的重连 @@ -40,7 +40,7 @@ public Set getRemoteWords(Dictionary dictionary, DictionaryType dictionaryType, String etymology, String domain) { - logger.info("[Remote DictFile reloading] For etymology 'redis' domain {}", domain); + logger.info("[Remote DictFile reloading] For etymology 'redis' domain '{}'", domain); RedisCommands sync = this.redisConnection.sync(); String key = this.getKey(dictionaryType, domain); List words = sync.lrange(key, 0, -1); @@ -51,13 +51,13 @@ public Set getRemoteWords(Dictionary dictionary, public void reloadRemoteDictionary(Dictionary dictionary, DictionaryType dictionaryType, String domain) { - logger.info("[Remote DictFile reloading] For etymology 'redis'"); + logger.info("[Remote DictFile reloading] For etymology 'redis' and domain '{}'", domain); RedisCommands sync = this.redisConnection.sync(); // 当前 对应的 *-state key为true时,进行reload String key = this.getKey(dictionaryType, domain); String state = String.format("%s:state", key); String currentState = sync.get(state); - logger.info("[Remote Dict File] state {} = {}", state, currentState); + logger.info("[Remote Dict File] state '{}' = '{}'", state, currentState); if ("true".equals(currentState)) { sync.set(state, "false"); dictionary.reload(dictionaryType); diff --git a/src/main/java/org/wltea/analyzer/dictionary/remote/RemoteDictionary.java b/src/main/java/org/wltea/analyzer/dictionary/remote/RemoteDictionary.java index 092194d0..786b305b 100644 --- a/src/main/java/org/wltea/analyzer/dictionary/remote/RemoteDictionary.java +++ b/src/main/java/org/wltea/analyzer/dictionary/remote/RemoteDictionary.java @@ -23,7 +23,7 @@ public final class RemoteDictionary { private static void addRemoteDictionary(AbstractRemoteDictionary remoteDictionary) { String etymology = remoteDictionary.etymology(); REMOTE_DICTIONARY.put(etymology, remoteDictionary); - logger.info("The Remote Dictionary For etymology {} is loaded!", etymology); + logger.info("The Remote Dictionary For etymology '{}' is loaded!", etymology); } public static void initial() { @@ -35,7 +35,7 @@ public static void initial() { public static AbstractRemoteDictionary getRemoteDictionary(URI uri) { String etymology = uri.getScheme(); - logger.info("Remote Dictionary etymology {}", etymology); + logger.info("Remote Dictionary etymology '{}'", etymology); AbstractRemoteDictionary remoteDictionary = REMOTE_DICTIONARY.get(etymology); if (Objects.isNull(remoteDictionary)) { logger.error("Load Remote Dictionary Error");