我该如何在Java类中使用Stanford解析器对字符串进行分词?
我只能找到一些使用DocumentProcessor和PTBTokenizer从外部文件获取文本的示例。
感谢您的选择。
我只能找到一些使用DocumentProcessor和PTBTokenizer从外部文件获取文本的示例。
DocumentPreprocessor dp = new DocumentPreprocessor("hello.txt");
for (List sentence : dp) {
System.out.println(sentence);
}
// option #2: By token
PTBTokenizer ptbt = new PTBTokenizer(new FileReader("hello.txt"),
new CoreLabelTokenFactory(), "");
for (CoreLabel label; ptbt.hasNext(); ) {
label = (CoreLabel) ptbt.next();
System.out.println(label);
}
感谢您的选择。