From 356d9d9ae9868edef76441e575d8b5588574e108 Mon Sep 17 00:00:00 2001 From: magese Date: Tue, 12 Nov 2019 11:29:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E4=B8=BB=E8=AF=8D=E5=85=B8useMainDict=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/wltea/analyzer/cfg/Configuration.java | 21 ++++++++-- .../org/wltea/analyzer/cfg/DefaultConfig.java | 42 +++++++++++++++---- 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/wltea/analyzer/cfg/Configuration.java b/src/main/java/org/wltea/analyzer/cfg/Configuration.java index 7a3a9f1..e13354a 100644 --- a/src/main/java/org/wltea/analyzer/cfg/Configuration.java +++ b/src/main/java/org/wltea/analyzer/cfg/Configuration.java @@ -1,6 +1,6 @@ /* - * IK 中文分词 版本 8.2.0 - * IK Analyzer release 8.2.0 + * IK 中文分词 版本 8.3.0 + * IK Analyzer release 8.3.0 * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -21,8 +21,8 @@ * 版权声明 2012,乌龙茶工作室 * provided by Linliangyi and copyright 2012 by Oolong studio * - * 8.2.0版本 由 Magese (magese@live.cn) 更新 - * release 8.2.0 update by Magese(magese@live.cn) + * 8.3.0版本 由 Magese (magese@live.cn) 更新 + * release 8.3.0 update by Magese(magese@live.cn) * */ package org.wltea.analyzer.cfg; @@ -50,6 +50,19 @@ public interface Configuration { */ void setUseSmart(boolean useSmart); + /** + * 获取是否使用主词典 + * + * @return = true 默认加载主词典, = false 不加载主词典 + */ + boolean useMainDict(); + + /** + * 设置是否使用主词典 + * + * @param useMainDic = true 默认加载主词典, = false 不加载主词典 + */ + void setUseMainDict(boolean useMainDic); /** * 获取主词典路径 diff --git a/src/main/java/org/wltea/analyzer/cfg/DefaultConfig.java b/src/main/java/org/wltea/analyzer/cfg/DefaultConfig.java index 302f834..dafe596 100644 --- a/src/main/java/org/wltea/analyzer/cfg/DefaultConfig.java +++ b/src/main/java/org/wltea/analyzer/cfg/DefaultConfig.java @@ -1,6 +1,6 @@ /* - * IK 中文分词 版本 8.2.0 - * IK Analyzer release 8.2.0 + * IK 中文分词 版本 8.3.0 + * IK Analyzer release 8.3.0 * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -21,8 +21,8 @@ * 版权声明 2012,乌龙茶工作室 * provided by Linliangyi and copyright 2012 by Oolong studio * - * 8.2.0版本 由 Magese (magese@live.cn) 更新 - * release 8.2.0 update by Magese(magese@live.cn) + * 8.3.0版本 由 Magese (magese@live.cn) 更新 + * release 8.3.0 update by Magese(magese@live.cn) * */ package org.wltea.analyzer.cfg; @@ -48,17 +48,21 @@ public class DefaultConfig implements Configuration { * 分词器配置文件路径 */ private static final String FILE_NAME = "IKAnalyzer.cfg.xml"; + // 配置属性——是否使用主词典 + private static final String USE_MAIN = "use_main_dict"; // 配置属性——扩展字典 private static final String EXT_DICT = "ext_dict"; // 配置属性——扩展停止词典 private static final String EXT_STOP = "ext_stopwords"; private Properties props; - /* - * 是否使用smart方式分词 - */ + + // 是否使用smart方式分词 private boolean useSmart; + // 是否加载主词典 + private boolean useMainDict = true; + /** * 返回单例 * @@ -100,10 +104,33 @@ public class DefaultConfig implements Configuration { * * @param useSmart =true ,分词器使用智能切分策略, =false则使用细粒度切分 */ + @Override public void setUseSmart(boolean useSmart) { this.useSmart = useSmart; } + /** + * 获取是否使用主词典 + * + * @return = true 默认加载主词典, = false 不加载主词典 + */ + public boolean useMainDict() { + String useMainDictCfg = props.getProperty(USE_MAIN); + if (useMainDictCfg != null && useMainDictCfg.trim().length() > 0) + setUseMainDict(Boolean.parseBoolean(useMainDictCfg)); + return useMainDict; + } + + /** + * 设置是否使用主词典 + * + * @param useMainDict = true 默认加载主词典, = false 不加载主词典 + */ + @Override + public void setUseMainDict(boolean useMainDict) { + this.useMainDict = useMainDict; + } + /** * 获取主词典路径 * @@ -142,7 +169,6 @@ public class DefaultConfig implements Configuration { return extDictFiles; } - /** * 获取扩展停止词典配置路径 *