Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add settings to enable/disable stopwords in analyzer #763

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/org/wltea/analyzer/cfg/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class Configuration {
//是否启用智能分词
private boolean useSmart;

//是否使用停止词
private boolean useStopWords;

//是否启用远程词典加载
private boolean enableRemoteDict=false;

Expand All @@ -34,6 +37,7 @@ public Configuration(Environment env,Settings settings) {
this.settings=settings;

this.useSmart = settings.get("use_smart", "false").equals("true");
this.useStopWords = settings.get("use_stopwords", "true").equals("true");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change this config name from use_lowercase to enable_lowercase , to better align with the below config;

this.enableLowercase = settings.get("enable_lowercase", "true").equals("true");
this.enableRemoteDict = settings.get("enable_remote_dict", "true").equals("true");

Expand All @@ -52,6 +56,10 @@ public boolean isUseSmart() {
return useSmart;
}

public boolean isUseStopWords() {
return useStopWords;
}

public Configuration setUseSmart(boolean useSmart) {
this.useSmart = useSmart;
return this;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/wltea/analyzer/core/AnalyzeContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ Lexeme getNextLexeme(){
while(result != null){
//数量词合并
this.compound(result);
if(Dictionary.getSingleton().isStopWord(this.segmentBuff , result.getBegin() , result.getLength())){
if(cfg.isUseStopWords() && Dictionary.getSingleton().isStopWord(this.segmentBuff , result.getBegin() , result.getLength())){
//是停止词继续取列表的下一个
result = this.results.pollFirst();
}else{
Expand Down