首页 > 解决方案 > 字符串与斯坦福 NLP Word 之间的转换

问题描述

我正在尝试使用斯坦福核心 NLP 的 Stemmer 类(https://github.com/stanfordnlp/CoreNLP/blob/master/src/edu/stanford/nlp/process/Stemmer.java)进行词干提取。

我正在尝试从另一个类中调用词干分析器方法(我对其进行了一些编辑),如下所示,请注意这term是一个字符串:

String stemmedterm=CoreNLPKeyPhraseStemmer.keystemming(term);  

CoreNLPKeyPhraseStemmer 的keystemming方法中词干提取的主要工作是通过以下行完成的:

String s1= s.stem(token.word());

但是,我的问题是类型token必须是Wordieedu.stanford.nlp.ling.Word (https://nlp.stanford.edu/nlp/javadoc/javanlp/index.html?edu/stanford/nlp/ling/Word .html),而我在keystemming从其他类调用时提供字符串。有没有办法将提供的字符串转换为Word

标签: stanford-nlpstemming

解决方案


阅读Word类的代码,它似乎支持String它的构造函数,所以我相信你只需要做

Word(token.stem())

获取词干标记的单词对象。


推荐阅读