利用OpenNLP进行英文段落的分句
安装
Install-Package OpenNLP
Install-Package System.Runtime.Caching
示例代码
using OpenNLP.Tools.SentenceDetect;
var paragraph = @"To test easily the various NLP tools, run the ToolsExample winform project. You'll find below a more detailed description of the tools and how code snippets to use them directly in your code. All NLP tools based on the maxent algorithm need model files to run. You'll find those files for English in Resources/Models. If you want to train your own models (to improve precision on English or to use those tools on other languages), please refer to the last section.";
var modelPath = "EnglishSD.nbin";
var sentenceDetector = new EnglishMaximumEntropySentenceDetector(modelPath);
var sentences = sentenceDetector.SentenceDetect(paragraph);
if (sentences?.Length > 0)
{
foreach (var sentence in sentences)
{
Console.WriteLine(sentence);
}
}
Console.ReadKey();
注:上面代码中用到的EnglishSD.nbin文件,在官方的源码里面有,可以直接复制到自己的工程里。

浙公网安备 33010602011771号