Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
iiopsd
elasticsearch-analysis-ik
提交
9eaa2b90
E
elasticsearch-analysis-ik
项目概览
iiopsd
/
elasticsearch-analysis-ik
与 Fork 源项目一致
从无法访问的项目Fork
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
elasticsearch-analysis-ik
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9eaa2b90
编写于
3月 06, 2019
作者:
weixin_43283383
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix NPE
上级
1d750a9b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
42 addition
and
46 deletion
+42
-46
src/main/java/org/wltea/analyzer/dic/Dictionary.java
src/main/java/org/wltea/analyzer/dic/Dictionary.java
+42
-46
未找到文件。
src/main/java/org/wltea/analyzer/dic/Dictionary.java
浏览文件 @
9eaa2b90
...
...
@@ -43,6 +43,8 @@ import java.util.concurrent.Executors;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
import
org.apache.http.Header
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.client.ClientProtocolException
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
...
...
@@ -69,14 +71,8 @@ public class Dictionary {
private
DictSegment
_MainDict
;
private
DictSegment
_SurnameDict
;
private
DictSegment
_QuantifierDict
;
private
DictSegment
_SuffixDict
;
private
DictSegment
_PrepDict
;
private
DictSegment
_StopWords
;
/**
...
...
@@ -88,12 +84,12 @@ public class Dictionary {
private
static
ScheduledExecutorService
pool
=
Executors
.
newScheduledThreadPool
(
1
);
p
ublic
static
final
String
PATH_DIC_MAIN
=
"main.dic"
;
p
ublic
static
final
String
PATH_DIC_SURNAME
=
"surname.dic"
;
p
ublic
static
final
String
PATH_DIC_QUANTIFIER
=
"quantifier.dic"
;
p
ublic
static
final
String
PATH_DIC_SUFFIX
=
"suffix.dic"
;
p
ublic
static
final
String
PATH_DIC_PREP
=
"preposition.dic"
;
p
ublic
static
final
String
PATH_DIC_STOP
=
"stopword.dic"
;
p
rivate
static
final
String
PATH_DIC_MAIN
=
"main.dic"
;
p
rivate
static
final
String
PATH_DIC_SURNAME
=
"surname.dic"
;
p
rivate
static
final
String
PATH_DIC_QUANTIFIER
=
"quantifier.dic"
;
p
rivate
static
final
String
PATH_DIC_SUFFIX
=
"suffix.dic"
;
p
rivate
static
final
String
PATH_DIC_PREP
=
"preposition.dic"
;
p
rivate
static
final
String
PATH_DIC_STOP
=
"stopword.dic"
;
private
final
static
String
FILE_NAME
=
"IKAnalyzer.cfg.xml"
;
private
final
static
String
EXT_DICT
=
"ext_dict"
;
...
...
@@ -128,15 +124,13 @@ public class Dictionary {
if
(
input
!=
null
)
{
try
{
props
.
loadFromXML
(
input
);
}
catch
(
InvalidPropertiesFormatException
e
)
{
logger
.
error
(
"ik-analyzer"
,
e
);
}
catch
(
IOException
e
)
{
logger
.
error
(
"ik-analyzer"
,
e
);
}
}
}
p
ublic
String
getProperty
(
String
key
){
p
rivate
String
getProperty
(
String
key
){
if
(
props
!=
null
){
return
props
.
getProperty
(
key
);
}
...
...
@@ -148,7 +142,7 @@ public class Dictionary {
*
* @return Dictionary
*/
public
static
synchronized
Dictionary
initial
(
Configuration
cfg
)
{
public
static
synchronized
void
initial
(
Configuration
cfg
)
{
if
(
singleton
==
null
)
{
synchronized
(
Dictionary
.
class
)
{
if
(
singleton
==
null
)
{
...
...
@@ -172,14 +166,12 @@ public class Dictionary {
}
}
return
singleton
;
}
}
}
return
singleton
;
}
private
List
<
String
>
walkFileTree
(
List
<
String
>
files
,
Path
path
)
{
private
void
walkFileTree
(
List
<
String
>
files
,
Path
path
)
{
if
(
Files
.
isRegularFile
(
path
))
{
files
.
add
(
path
.
toString
());
}
else
if
(
Files
.
isDirectory
(
path
))
try
{
...
...
@@ -200,7 +192,6 @@ public class Dictionary {
}
else
{
logger
.
warn
(
"[Ext Loading] file not found: "
+
path
);
}
return
files
;
}
private
void
loadDictFile
(
DictSegment
dict
,
Path
file
,
boolean
critical
,
String
name
)
{
...
...
@@ -225,7 +216,7 @@ public class Dictionary {
}
}
p
ublic
List
<
String
>
getExtDictionarys
()
{
p
rivate
List
<
String
>
getExtDictionarys
()
{
List
<
String
>
extDictFiles
=
new
ArrayList
<
String
>(
2
);
String
extDictCfg
=
getProperty
(
EXT_DICT
);
if
(
extDictCfg
!=
null
)
{
...
...
@@ -242,7 +233,7 @@ public class Dictionary {
return
extDictFiles
;
}
p
ublic
List
<
String
>
getRemoteExtDictionarys
()
{
p
rivate
List
<
String
>
getRemoteExtDictionarys
()
{
List
<
String
>
remoteExtDictFiles
=
new
ArrayList
<
String
>(
2
);
String
remoteExtDictCfg
=
getProperty
(
REMOTE_EXT_DICT
);
if
(
remoteExtDictCfg
!=
null
)
{
...
...
@@ -258,7 +249,7 @@ public class Dictionary {
return
remoteExtDictFiles
;
}
p
ublic
List
<
String
>
getExtStopWordDictionarys
()
{
p
rivate
List
<
String
>
getExtStopWordDictionarys
()
{
List
<
String
>
extStopWordDictFiles
=
new
ArrayList
<
String
>(
2
);
String
extStopWordDictCfg
=
getProperty
(
EXT_STOP
);
if
(
extStopWordDictCfg
!=
null
)
{
...
...
@@ -275,7 +266,7 @@ public class Dictionary {
return
extStopWordDictFiles
;
}
p
ublic
List
<
String
>
getRemoteExtStopWordDictionarys
()
{
p
rivate
List
<
String
>
getRemoteExtStopWordDictionarys
()
{
List
<
String
>
remoteExtStopWordDictFiles
=
new
ArrayList
<
String
>(
2
);
String
remoteExtStopWordDictCfg
=
getProperty
(
REMOTE_EXT_STOP
);
if
(
remoteExtStopWordDictCfg
!=
null
)
{
...
...
@@ -291,7 +282,7 @@ public class Dictionary {
return
remoteExtStopWordDictFiles
;
}
p
ublic
String
getDictRoot
()
{
p
rivate
String
getDictRoot
()
{
return
conf_dir
.
toAbsolutePath
().
toString
();
}
...
...
@@ -468,25 +459,30 @@ public class Dictionary {
String
charset
=
"UTF-8"
;
// 获取编码,默认为utf-8
if
(
response
.
getEntity
().
getContentType
().
getValue
().
contains
(
"charset="
))
{
String
contentType
=
response
.
getEntity
().
getContentType
().
getValue
();
charset
=
contentType
.
substring
(
contentType
.
lastIndexOf
(
"="
)
+
1
);
}
in
=
new
BufferedReader
(
new
InputStreamReader
(
response
.
getEntity
().
getContent
(),
charset
));
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
buffer
.
add
(
line
);
}
in
.
close
();
response
.
close
();
return
buffer
;
HttpEntity
entity
=
response
.
getEntity
();
if
(
entity
!=
null
){
Header
contentType
=
entity
.
getContentType
();
if
(
contentType
!=
null
&&
contentType
.
getValue
()!=
null
){
String
typeValue
=
contentType
.
getValue
();
if
(
typeValue
!=
null
&&
typeValue
.
contains
(
"charset="
)){
charset
=
typeValue
.
substring
(
typeValue
.
lastIndexOf
(
"="
)
+
1
);
}
}
if
(
entity
.
getContentLength
()
>
0
)
{
in
=
new
BufferedReader
(
new
InputStreamReader
(
entity
.
getContent
(),
charset
));
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
buffer
.
add
(
line
);
}
in
.
close
();
response
.
close
();
return
buffer
;
}
}
}
response
.
close
();
}
catch
(
ClientProtocolException
e
)
{
logger
.
error
(
"getRemoteWords {} error"
,
e
,
location
);
}
catch
(
IllegalStateException
e
)
{
logger
.
error
(
"getRemoteWords {} error"
,
e
,
location
);
}
catch
(
IOException
e
)
{
}
catch
(
IllegalStateException
|
IOException
e
)
{
logger
.
error
(
"getRemoteWords {} error"
,
e
,
location
);
}
return
buffer
;
...
...
@@ -548,24 +544,24 @@ public class Dictionary {
}
private
void
loadSurnameDict
()
{
_SurnameDict
=
new
DictSegment
((
char
)
0
);
DictSegment
_SurnameDict
=
new
DictSegment
((
char
)
0
);
Path
file
=
PathUtils
.
get
(
getDictRoot
(),
Dictionary
.
PATH_DIC_SURNAME
);
loadDictFile
(
_SurnameDict
,
file
,
true
,
"Surname"
);
}
private
void
loadSuffixDict
()
{
_SuffixDict
=
new
DictSegment
((
char
)
0
);
DictSegment
_SuffixDict
=
new
DictSegment
((
char
)
0
);
Path
file
=
PathUtils
.
get
(
getDictRoot
(),
Dictionary
.
PATH_DIC_SUFFIX
);
loadDictFile
(
_SuffixDict
,
file
,
true
,
"Suffix"
);
}
private
void
loadPrepDict
()
{
_PrepDict
=
new
DictSegment
((
char
)
0
);
DictSegment
_PrepDict
=
new
DictSegment
((
char
)
0
);
Path
file
=
PathUtils
.
get
(
getDictRoot
(),
Dictionary
.
PATH_DIC_PREP
);
loadDictFile
(
_PrepDict
,
file
,
true
,
"Preposition"
);
}
public
void
reLoadMainDict
()
{
void
reLoadMainDict
()
{
logger
.
info
(
"重新加载词典..."
);
// 新开一个实例加载词典,减少加载过程对当前词典使用的影响
Dictionary
tmpDict
=
new
Dictionary
(
configuration
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录