词干提取不难,网上有很多波特词干算法的实现。
词形还原的话,自己在网上寻找了一下,发现Stanford的NLP库可用,具体链接:
http://nlp.stanford.edu/software/corenlp.shtml
这个是corenlp那个包的介绍网址,还有其他的很多包可以自行查看。
用法示例:
StringBuilder stringBuilder = new StringBuilder();
Annotation annotation = stanfordCoreNLP.process(phrase);
List<coremap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
for(CoreMap sentence: sentences) {
for (CoreLabel token: sentence.get(CoreAnnotations.TokensAnnotation.class)) {
//String word = token.get(CoreAnnotations.TextAnnotation.class);//original text(phrase)
String lemma = token.get(CoreAnnotations.LemmaAnnotation.class);//lemmatization
String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);//partofspeech