1.在pom.xml中導(dǎo)入依賴
<dependency>
<groupId>org.apdplat</groupId>
<artifactId>word</artifactId>
<version>1.1</version>
</dependency>
2.在代碼中使用
package com.vortex.commonAPI.controller;
import javax.servlet.http.HttpServletRequest;
import org.apdplat.word.WordSegmenter;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(value = "wordSegmenter")
public class WordSegmenterController {
@RequestMapping(value = "/spliceString", method = RequestMethod.GET)
public Object spliceString(HttpServletRequest request) {
String words = request.getParameter("words");
// 移除停用詞進(jìn)行分詞
// List<Word> list = WordSegmenter.seg(words);
// 保留停用詞
return WordSegmenter.segWithStopWords(words);
}
}
3.實(shí)例