Skip to content

Commit

Permalink
add type method
Browse files Browse the repository at this point in the history
  • Loading branch information
ansjsun committed Sep 1, 2016
1 parent 0c876e0 commit 8029385
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Set;

import org.ansj.lucene.util.AnsjTokenizer;
import org.ansj.splitWord.analysis.BaseAnalysis;
import org.ansj.splitWord.analysis.DicAnalysis;
import org.ansj.splitWord.analysis.IndexAnalysis;
import org.ansj.splitWord.analysis.ToAnalysis;
Expand All @@ -29,7 +30,7 @@ public class AnsjAnalyzer extends Analyzer {
*
*/
public static enum TYPE {
index, query, to, dic, user, search
base, index, query, to, dic, user, search
}

/** 自定义停用词 */
Expand All @@ -38,10 +39,7 @@ public static enum TYPE {
private TYPE type;

/**
* @param filter
* 停用词
* @param pstemming
* 是否分析词干
* @param filter 停用词
*/
public AnsjAnalyzer(TYPE type, Set<String> filter) {
this.type = type;
Expand All @@ -57,6 +55,10 @@ public AnsjAnalyzer(TYPE type) {
this.type = type;
}

public AnsjAnalyzer(String typeStr) {
this.type = TYPE.valueOf(typeStr);
}

private Set<String> filter(String stopwordsDir) {
if (StringUtil.isBlank(stopwordsDir)) {
return null;
Expand Down Expand Up @@ -93,6 +95,13 @@ public static Tokenizer getTokenizer(BufferedReader reader, TYPE type, Set<Strin
Tokenizer tokenizer;

switch (type) {
case base:
if (reader == null) {
tokenizer = new AnsjTokenizer(new BaseAnalysis(), filter);
} else {
tokenizer = new AnsjTokenizer(new BaseAnalysis(reader), filter);
}
break;
case index:
if (reader == null) {
tokenizer = new AnsjTokenizer(new IndexAnalysis(), filter);
Expand Down

0 comments on commit 8029385

Please sign in to comment.