pom.xml添加maven依赖
<!-- 分词库 -->
<dependency>
<groupId>org.apdplat</groupId>
<artifactId>word</artifactId>
<version>1.2</version>
</dependency>
WordFilter.java 测试类
package com.policymatch;
import java.util.List;
import org.apdplat.word.WordSegmenter;
import org.apdplat.word.segmentation.Word;
import com.alibaba.fastjson.JSON;
public class WordFilter {
public static void automaticSelection(String title) {
//移除停用词进行分词
List<Word> list = WordSegmenter.seg(title);
//遍历结果
for(int i=0; i<list.size();i++) {
System.out.println(list.get(i));
}
System.out.println(list);
//转为json格式
String a = JSON.toJSONString(list);
System.out.println(a);
//保留停用词
List<Word> lists = WordSegmenter.segWithStopWords(title);
//转为json格式
String b = JSON.toJSONString(lists);
//结果
System.out.println(b);
}
public static void main(String[] args) {
WordFilter.automaticSelection("我还是从前那个少年没有一丝丝改变");
}
}