利用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文件,在官方的源码里面有,可以直接复制到自己的工程里。

官方网址:https://github.com/AlexPoint/OpenNlp

posted @   wzwyc  阅读(23)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
历史上的今天:
2017-09-12 通过NLayer和NAudio转换MP3成WAV
2017-09-12 使用NAudio实现Wav转Mp3
2017-09-12 SynchronizationContext笔记
点击右上角即可分享
微信分享提示