14 Commits

Author SHA1 Message Date
magese 95ba364090 Update README.md 2019-11-12 11:46:03 +08:00
magese 0c8992fd80 Update lucene version to 8.3.0 2019-11-12 11:30:57 +08:00
magese 356d9d9ae9 增加是否加载主词典useMainDict属性。 2019-11-12 11:29:56 +08:00
magese cd43d4b9ee 增加use_main_dict配置选项,可配置是否加载主词典。 2019-11-12 11:27:22 +08:00
magese 5068a58e0f Update jdk version 2019-09-27 14:31:16 +08:00
magese 107b4ced30 Update travis properties 2019-09-27 14:29:12 +08:00
magese e6817ecba5 Extract method from duplicate code 2019-09-27 09:54:15 +08:00
magese 0916f3f8bd Update lucene to 8.2.0 2019-09-27 09:52:45 +08:00
magese a3705f5753 Merge remote-tracking branch 'origin/master' 2019-07-11 15:08:40 +08:00
magese cc9f0d7bea Update lucene to 8.1.1 2019-07-11 13:51:05 +08:00
Magese 7a2515a134 Update README.md
Add HitCount
2019-05-29 08:58:17 +08:00
magese 2ebf31fed5 Update README.md 2019-05-27 13:23:53 +08:00
magese fd35153cce Update lucene to 8.1.0 2019-05-27 10:23:32 +08:00
magese 48a0234bb6 更新搜狗2019流行词汇; 2019-05-27 10:21:00 +08:00
29 changed files with 15781 additions and 294 deletions
+2 -1
View File
@@ -1,3 +1,4 @@
language: java
jdk:
- oraclejdk8
- openjdk8
+24 -6
View File
@@ -6,6 +6,7 @@ ik-analyzer for solr 7.x-8.x
[![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/magese/ik-analyzer-solr/releases)
[![Crates.io](https://img.shields.io/crates/l/rustc-serialize.svg)](./LICENSE)
[![Build Status](https://travis-ci.org/magese/ik-analyzer-solr.svg?branch=master)](https://travis-ci.org/magese/ik-analyzer-solr)
[![HitCount](http://hits.dwyl.io/magese/ik-analyzer-solr.svg)](http://hits.dwyl.io/magese/ik-analyzer-solr)
[![GitHub forks](https://img.shields.io/github/forks/magese/ik-analyzer-solr.svg?style=social&label=Fork)](https://github.com/magese/ik-analyzer-solr/network/members)
[![GitHub stars](https://img.shields.io/github/stars/magese/ik-analyzer-solr.svg?style=social&label=Star)](https://github.com/magese/ik-analyzer-solr/stargazers)
@@ -21,15 +22,15 @@ ik-analyzer for solr 7.x-8.x
| word | 64.2万 | 2014年 |
| jieba | 58.4万 | 2012年 |
| jcesg | 16.6万 | 2018年 |
| sougou词库 | 115.2万 | 2018年 |
#### 将以上词库进行整理后约188.5万条词汇;
| sougou词库 | 115.2万 | 2019年 |
#### 将以上词库进行整理后约187.1万条词汇;
#### 添加动态加载词典表功能,在不需要重启solr服务的情况下加载新增的词典。
* IKAnalyzer的原作者为林良益<linliangyi2007@gmail.com>,项目网站为<http://code.google.com/p/ik-analyzer>
* 该项目动态加载功能根据博主[@星火燎原智勇](http://www.cnblogs.com/liang1101/articles/6395016.html)的博客进行修改,其GITHUB地址为[@liang68](https://github.com/liang68)
## 使用说明
* jar包下载地址:[![GitHub version](https://img.shields.io/badge/version-8.0.0-519dd9.svg)](https://search.maven.org/remotecontent?filepath=com/github/magese/ik-analyzer/8.0.0/ik-analyzer-8.0.0.jar)
* jar包下载地址:[![GitHub version](https://img.shields.io/badge/version-8.3.0-519dd9.svg)](https://search.maven.org/remotecontent?filepath=com/github/magese/ik-analyzer/8.3.0/ik-analyzer-8.3.0.jar)
* 历史版本:[![GitHub version](https://img.shields.io/maven-central/v/com.github.magese/ik-analyzer.svg?style=flat-square)](https://search.maven.org/search?q=g:com.github.magese%20AND%20a:ik-analyzer&core=gav)
```console
@@ -37,7 +38,7 @@ ik-analyzer for solr 7.x-8.x
<dependency>
<groupId>com.github.magese</groupId>
<artifactId>ik-analyzer</artifactId>
<version>8.0.0</version>
<version>8.3.0</version>
</dependency>
```
@@ -75,7 +76,15 @@ ik-analyzer for solr 7.x-8.x
![analyzer](./img/analyzer.png)
5. `ik.conf`文件说明:
5. `IKAnalyzer.cfg.xml`配置文件说明:
| 名称 | 类型 | 描述 | 默认 |
| :------: | :------: | :------: | :------: |
| use_main_dict | boolean | 是否使用默认主词典 | true |
| ext_dict | String | 扩展词典文件名称,多个用分号隔开 | ext.dic; |
| ext_stopwords | String | 停用词典文件名称,多个用分号隔开 | stopword.dic; |
6. `ik.conf`文件说明:
```console
files=dynamicdic.txt
lastupdate=0
@@ -84,13 +93,22 @@ ik-analyzer for solr 7.x-8.x
1. `files`为动态词典列表,可以设置多个词典表,用逗号进行分隔,默认动态词典表为`dynamicdic.txt`
2. `lastupdate`默认值为`0`,每次对动态词典表修改后请+1,不然不会将词典表中新的词语添加到内存中。<s>`lastupdate`采用的是`int`类型,不支持时间戳,如果使用时间戳的朋友可以把源码中的`int`改成`long`即可;</s> `2018-08-23` 已将源码中`lastUpdate`改为`long`类型,现可以用时间戳了。
6. `dynamicdic.txt` 为动态词典
7. `dynamicdic.txt` 为动态词典
在此文件配置的词语不需重启服务即可加载进内存中。
以`#`开头的词语视为注释,将不会加载到内存中。
## 更新说明
- `2019-11-12:`
- 升级lucene版本为`8.3.0`
- `IKAnalyzer.cfg.xml`增加配置项`use_main_dict`,用于配置是否启用默认主词典
- `2019-09-27:` 升级lucene版本为`8.2.0`
- `2019-07-11:` 升级lucene版本为`8.1.1`
- `2019-05-27:`
- 升级lucene版本为`8.1.0`
- 优化原词典部分重复词语
- 更新搜狗2019最新流行词汇词典,约20k词汇量
- `2019-05-15:` 升级lucene版本为`8.0.0`,并支持Solr8使用
- `2019-03-01:` 升级lucene版本为`7.7.1`
- `2019-02-15:` 升级lucene版本为`7.7.0`
+2 -2
View File
@@ -4,7 +4,7 @@
<groupId>com.github.magese</groupId>
<artifactId>ik-analyzer</artifactId>
<version>8.0.0</version>
<version>8.3.0</version>
<packaging>jar</packaging>
<name>ik-analyzer-solr</name>
@@ -13,7 +13,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<lucene.version>8.0.0</lucene.version>
<lucene.version>8.3.0</lucene.version>
<javac.src.version>1.8</javac.src.version>
<javac.target.version>1.8</javac.target.version>
<maven.compiler.plugin.version>3.3</maven.compiler.plugin.version>
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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);
/**
* 获取主词典路径
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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;
}
/**
* 获取扩展停止词典配置路径
*
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.core;
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.core;
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.core;
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.core;
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.core;
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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,21 +21,21 @@
* 版权声明 2012,乌龙茶工作室
* provided by Linliangyi and copyright 2012 by Oolong studio
*
* 8.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.core;
import org.wltea.analyzer.cfg.Configuration;
import org.wltea.analyzer.cfg.DefaultConfig;
import org.wltea.analyzer.dic.Dictionary;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;
import org.wltea.analyzer.cfg.Configuration;
import org.wltea.analyzer.cfg.DefaultConfig;
import org.wltea.analyzer.dic.Dictionary;
/**
* IK分词器主类
*/
@@ -58,7 +58,6 @@ public final class IKSegmenter {
*
* @param input 读取流
* @param useSmart 为true,使用智能分词策略
* <p>
* 非智能分词:细粒度输出所有可能的切分结果
* 智能分词: 合并数词和量词,对分词结果进行歧义判断
*/
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.core;
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.core;
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.core;
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.core;
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.0
* IK 中文分词 版本 8.3.0
* IK Analyzer release 8.2.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.0 update by Magese(magese@live.cn)
* 8.2.0版本 由 Magese (magese@live.cn) 更新
* release 8.2.0 update by Magese(magese@live.cn)
*
*/
package org.wltea.analyzer.core;
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.dic;
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.dic;
@@ -226,31 +226,25 @@ public class Dictionary {
private void loadMainDict() {
// 建立一个主词典实例
_MainDict = new DictSegment((char) 0);
// 读取主词典文件
InputStream is = this.getClass().getClassLoader().getResourceAsStream(cfg.getMainDictionary());
if (is == null) {
throw new RuntimeException("Main Dictionary not found!!!");
}
try {
BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8), 512);
String theWord;
do {
theWord = br.readLine();
if (theWord != null && !"".equals(theWord.trim())) {
_MainDict.fillSegment(theWord.trim().toLowerCase().toCharArray());
}
} while (theWord != null);
} catch (IOException ioe) {
System.err.println("Main Dictionary loading exception.");
ioe.printStackTrace();
} finally {
// 获取是否加载主词典
if (cfg.useMainDict()) {
// 读取主词典文件
InputStream is = this.getClass().getClassLoader().getResourceAsStream(cfg.getMainDictionary());
if (is == null) {
throw new RuntimeException("Main Dictionary not found!!!");
}
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
readDict(is, _MainDict);
} catch (IOException ioe) {
System.err.println("Main Dictionary loading exception.");
ioe.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
// 加载扩展词典
@@ -274,17 +268,7 @@ public class Dictionary {
continue;
}
try {
BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8), 512);
String theWord;
do {
theWord = br.readLine();
if (theWord != null && !"".equals(theWord.trim())) {
// 加载扩展词典数据到主内存词典中
// System.out.println(theWord);
_MainDict.fillSegment(theWord.trim().toLowerCase().toCharArray());
}
} while (theWord != null);
readDict(is, _MainDict);
} catch (IOException ioe) {
System.err.println("Extension Dictionary loading exception.");
ioe.printStackTrace();
@@ -319,17 +303,7 @@ public class Dictionary {
continue;
}
try {
BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8), 512);
String theWord;
do {
theWord = br.readLine();
if (theWord != null && !"".equals(theWord.trim())) {
// System.out.println(theWord);
// 加载扩展停止词典数据到内存中
_StopWordDict.fillSegment(theWord.trim().toLowerCase().toCharArray());
}
} while (theWord != null);
readDict(is, _StopWordDict);
} catch (IOException ioe) {
System.err.println("Extension Stop word Dictionary loading exception.");
ioe.printStackTrace();
@@ -357,15 +331,7 @@ public class Dictionary {
throw new RuntimeException("Quantifier Dictionary not found!!!");
}
try {
BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8), 512);
String theWord;
do {
theWord = br.readLine();
if (theWord != null && !"".equals(theWord.trim())) {
_QuantifierDict.fillSegment(theWord.trim().toLowerCase().toCharArray());
}
} while (theWord != null);
readDict(is, _QuantifierDict);
} catch (IOException ioe) {
System.err.println("Quantifier Dictionary loading exception.");
ioe.printStackTrace();
@@ -379,4 +345,21 @@ public class Dictionary {
}
}
/**
* 读取词典文件到词典树中
*
* @param is 文件输入流
* @param dictSegment 词典树分段
* @throws IOException 读取异常
*/
private void readDict(InputStream is, DictSegment dictSegment) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8), 512);
String theWord;
do {
theWord = br.readLine();
if (theWord != null && !"".equals(theWord.trim())) {
dictSegment.fillSegment(theWord.trim().toLowerCase().toCharArray());
}
} while (theWord != null);
}
}
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.dic;
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.lucene;
@@ -34,44 +34,40 @@ import org.apache.lucene.analysis.Tokenizer;
* IK分词器,Lucene Analyzer接口实现
*/
@SuppressWarnings("unused")
public final class IKAnalyzer extends Analyzer{
private boolean useSmart;
private boolean useSmart() {
return useSmart;
}
public final class IKAnalyzer extends Analyzer {
public void setUseSmart(boolean useSmart) {
this.useSmart = useSmart;
}
private boolean useSmart;
/**
* IK分词器Lucene Analyzer接口实现类
*
* 默认细粒度切分算法
*/
public IKAnalyzer(){
this(false);
}
/**
* IK分词器Lucene Analyzer接口实现类
*
* @param useSmart 当为true时,分词器进行智能切分
*/
public IKAnalyzer(boolean useSmart){
super();
this.useSmart = useSmart;
}
private boolean useSmart() {
return useSmart;
}
/**
* 重载Analyzer接口,构造分词组件
*/
@Override
protected TokenStreamComponents createComponents(String fieldName) {
Tokenizer _IKTokenizer = new IKTokenizer(this.useSmart());
return new TokenStreamComponents(_IKTokenizer);
}
/**
* IK分词器Lucene Analyzer接口实现类
* 默认细粒度切分算法
*/
public IKAnalyzer() {
this(false);
}
/**
* IK分词器Lucene Analyzer接口实现类
*
* @param useSmart 当为true时,分词器进行智能切分
*/
public IKAnalyzer(boolean useSmart) {
super();
this.useSmart = useSmart;
}
/**
* 重载Analyzer接口,构造分词组件
*/
@Override
protected TokenStreamComponents createComponents(String fieldName) {
Tokenizer _IKTokenizer = new IKTokenizer(this.useSmart());
return new TokenStreamComponents(_IKTokenizer);
}
}
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.lucene;
@@ -43,88 +43,88 @@ import java.io.IOException;
*/
@SuppressWarnings("unused")
public final class IKTokenizer extends Tokenizer {
//IK分词器实现
private IKSegmenter _IKImplement;
//词元文本属性
private CharTermAttribute termAtt;
//词元位移属性
private OffsetAttribute offsetAtt;
//词元分类属性(该属性分类参考org.wltea.analyzer.core.Lexeme中的分类常量)
private TypeAttribute typeAtt;
//记录最后一个词元的结束位置
private int endPosition;
/**
* Lucene 7.6 Tokenizer适配器类构造函数
*/
public IKTokenizer() {
this(false);
}
IKTokenizer(boolean useSmart) {
super();
init(useSmart);
}
//IK分词器实现
private IKSegmenter _IKImplement;
public IKTokenizer(AttributeFactory factory) {
this(factory, false);
}
//词元文本属性
private CharTermAttribute termAtt;
//词元位移属性
private OffsetAttribute offsetAtt;
//词元分类属性(该属性分类参考org.wltea.analyzer.core.Lexeme中的分类常量)
private TypeAttribute typeAtt;
//记录最后一个词元的结束位置
private int endPosition;
IKTokenizer(AttributeFactory factory, boolean useSmart) {
super(factory);
init(useSmart);
}
/**
* Lucene 7.6 Tokenizer适配器类构造函数
*/
public IKTokenizer() {
this(false);
}
private void init(boolean useSmart) {
offsetAtt = addAttribute(OffsetAttribute.class);
termAtt = addAttribute(CharTermAttribute.class);
typeAtt = addAttribute(TypeAttribute.class);
_IKImplement = new IKSegmenter(input , useSmart);
}
IKTokenizer(boolean useSmart) {
super();
init(useSmart);
}
/* (non-Javadoc)
* @see org.apache.lucene.analysis.TokenStream#incrementToken()
*/
@Override
public boolean incrementToken() throws IOException {
//清除所有的词元属性
clearAttributes();
Lexeme nextLexeme = _IKImplement.next();
if(nextLexeme != null){
//将Lexeme转成Attributes
//设置词元文本
termAtt.append(nextLexeme.getLexemeText());
//设置词元长度
termAtt.setLength(nextLexeme.getLength());
//设置词元位移
offsetAtt.setOffset(nextLexeme.getBeginPosition(), nextLexeme.getEndPosition());
//记录分词的最后位置
endPosition = nextLexeme.getEndPosition();
//记录词元分类
typeAtt.setType(nextLexeme.getLexemeTypeString());
//返会true告知还有下个词元
return true;
}
//返会false告知词元输出完毕
return false;
}
/*
* (non-Javadoc)
* @see org.apache.lucene.analysis.Tokenizer#reset(java.io.Reader)
*/
@Override
public void reset() throws IOException {
super.reset();
_IKImplement.reset(input);
}
@Override
public final void end() {
// set final offset
int finalOffset = correctOffset(this.endPosition);
offsetAtt.setOffset(finalOffset, finalOffset);
}
public IKTokenizer(AttributeFactory factory) {
this(factory, false);
}
IKTokenizer(AttributeFactory factory, boolean useSmart) {
super(factory);
init(useSmart);
}
private void init(boolean useSmart) {
offsetAtt = addAttribute(OffsetAttribute.class);
termAtt = addAttribute(CharTermAttribute.class);
typeAtt = addAttribute(TypeAttribute.class);
_IKImplement = new IKSegmenter(input, useSmart);
}
/* (non-Javadoc)
* @see org.apache.lucene.analysis.TokenStream#incrementToken()
*/
@Override
public boolean incrementToken() throws IOException {
//清除所有的词元属性
clearAttributes();
Lexeme nextLexeme = _IKImplement.next();
if (nextLexeme != null) {
//将Lexeme转成Attributes
//设置词元文本
termAtt.append(nextLexeme.getLexemeText());
//设置词元长度
termAtt.setLength(nextLexeme.getLength());
//设置词元位移
offsetAtt.setOffset(nextLexeme.getBeginPosition(), nextLexeme.getEndPosition());
//记录分词的最后位置
endPosition = nextLexeme.getEndPosition();
//记录词元分类
typeAtt.setType(nextLexeme.getLexemeTypeString());
//返会true告知还有下个词元
return true;
}
//返会false告知词元输出完毕
return false;
}
/*
* (non-Javadoc)
* @see org.apache.lucene.analysis.Tokenizer#reset(java.io.Reader)
*/
@Override
public void reset() throws IOException {
super.reset();
_IKImplement.reset(input);
}
@Override
public final void end() {
// set final offset
int finalOffset = correctOffset(this.endPosition);
offsetAtt.setOffset(finalOffset, finalOffset);
}
}
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.lucene;
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.lucene;
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.query;
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.query;
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.sample;
@@ -1,6 +1,6 @@
/*
* IK 中文分词 版本 8.0.0
* IK Analyzer release 8.0.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.0.0版本 由 Magese (magese@live.cn) 更新
* release 8.0.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.sample;
+9 -9
View File
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>IK Analyzer 扩展配置</comment>
<!--用户可以在这里配置自己的扩展字-->
<entry key="ext_dict">ext.dic;</entry>
<!--用户可以在这里配置自己的扩展停止词字典-->
<entry key="ext_stopwords">stopword.dic;</entry>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>IK Analyzer 扩展配置</comment>
<!-- 配置是否加载默认词-->
<entry key="use_main_dict">true</entry>
<!-- 配置自己的扩展字典,多个用分号分隔 -->
<entry key="ext_dict">ext.dic;</entry>
<!-- 配置自己的扩展停止词字典,多个用分号分隔 -->
<entry key="ext_stopwords">stopword.dic;</entry>
</properties>
File diff suppressed because it is too large Load Diff