求将英文文章拆分成句子的算法

setimouse 2008-11-02 11:41:28
RT.
大德们,哪位有这种算法,请共享一下。或者我们一起讨论一下也可以。

就是将一篇英文文章以句为单位切分。
例如:
For the third year in a row, Drupal has been nominated for a Packt Publishing Open Source CMS award. Packt Publishing is announcing winners all week. Today they announced the 2008 best PHP open source CMS.

可以拆分为:
For the third year in a row, Drupal has been nominated for a Packt Publishing Open Source CMS award.
Packt Publishing is announcing winners all week.
Today they announced the 2008 best PHP open source CMS.


谢谢!
...全文
387 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yunfeifan 2008-11-03
  • 打赏
  • 举报
回复
$t = "For the third year in a row, Drupal has been nominated for a Packt Publishing Open Source CMS award. Packt Publishing is announcing winners all week. Today they announced the 2008 best PHP open source CMS.";
$list = explode(". ", $t);
print_r($list);
setimouse 2008-11-03
  • 打赏
  • 举报
回复
感谢7楼,这个架构应该靠谱。
cayleung 2008-11-03
  • 打赏
  • 举报
回复
解决特殊问题,用特殊办法。
如果还要忽略特殊的字符,就用special_replace来过滤掉

$s ="PopPhoto.com and Think Tank Photo are offering one lucky reader the chance to win an amazingly versatile set of camera bags that should have you ready PopPhoto.com for just about any photo adventure you've got planned. All you've got to do is sign up for our weekly newsletter and you're automatically entered for a chance to win the prize package worth $1,146.00!Welcome to www.new1day.cn.";

$special[0] = array();
$special[1] = array();
//替换特殊的
$s = special_replace("/www\.[\w]+\.(com|cn|org)/i",$s);
$s = special_replace("/\.(com|cn|org)/i",$s);
$s = special_replace("/[0-9]\.[0-9]/",$s);
//分句
$temp =preg_split("/[\?\.\!]\s?/",trim($s));
array_pop(&$temp);
//还原每句
foreach($temp as $k => $v)
$temp[$k] = special_revert($v);
print_r($temp);

function special_replace($pattern, $str){
global $special;
preg_match_all($pattern, $str, $temp);
if(is_array($temp))
foreach($temp[0] as $k => $v){
$special[0][] = $v;
$special[1][] = $temp2 = "|".md5($v)."|";
$str = str_replace($v, $temp2, $str);
}
return $str;
}

function special_revert($str){
global $special;
return str_replace($special[1],$special[0],$str);
}

setimouse 2008-11-03
  • 打赏
  • 举报
回复
那样就必须要求书写规范,这样会降低用户体验。
yunfeifan 2008-11-03
  • 打赏
  • 举报
回复
你该明白英文的写法,因为的标点后应该有一个空格的。例如
For the third year in a row, Drupal has been nominated for a Packt Publishing Open Source CMS award. Packt Publishing is announcing winners all week. Today they announced the 2008 best PHP open source CMS.
cayleung 2008-11-03
  • 打赏
  • 举报
回复

<?php
$s ="For the third year in a row, Drupal has been nominated for a Packt Publishing Open Source CMS award. Packt Publishing is announcing winners all week. Today they announced the 2008 best PHP open source CMS. ";
$temp =preg_split("/[\?\.\!]\s?/",trim($s));
array_pop(&$temp);
var_export($temp);
?>
setimouse 2008-11-03
  • 打赏
  • 举报
回复
PopPhoto.com and Think Tank Photo are offering one lucky reader the chance to win an amazingly versatile set of camera bags that should have you ready for just about any photo adventure you've got planned. All you've got to do is sign up for our weekly newsletter and you're automatically entered for a chance to win the prize package worth $1,146.00!
setimouse 2008-11-03
  • 打赏
  • 举报
回复
如果句子中有网址或者小数会产生干扰。

PopPhoto.com and Think Tank Photo are offering one lucky reader the chance to win an amazingly versatile set of camera bags that should have you ready for just about any photo adventure you've got planned. All you've got to do is sign up for our weekly newsletter and you're automatically entered for a chance to win the prize package worth $1,146.00!
此为学习版,请勿用于商业用途或扩散。 以下描述转至互联网。 ============== 一、CSW中分词组件简介 CSW中文分词组件,是一套可自动将一段文本按常规汉语词组进行拆分,并以指定方式进行分隔的COM组件。本组件采用独有的高效的分词引擎及拆分算法,具有准确、高速、资源占用率小等特点。为了满足客户对文本语义进行研究分析的需要,本组件同时提供词性及词频标注功能,可根据用户要,对其拆分后的词组进行词性标注或词频标注。互联网信息检索、数据库信息查询、智能聊天机器人、文本校对、自动翻译、 自动摘要、自动分类及信息加工处理等各个领域。 二、本组件特点: 1.适应性强 本组全部件采用ANSI标准C++开发,可广泛应用于当今的操作系统平台上,如:MS Windows、Linux及其它各公司出品的Unix操作系统。 2. 支持范围广 在MS Windows平台下,本组件以COM接口的DLL格式进行封装,可支持所有支持COM接口调用的编程语言及脚本语言。如:PHP、JSP、ASP、ASP.net、C/C++ 、VC6.0 、VC.net、BC、C#、VB6.0 、VB.net、Delphi、Java等。 3. 响应速度快 由于本组件采用高效特殊的算法引擎结构,每秒钟拆分可达数万字汉语文本,在对搜索关键词进行拆分情况下,其响应时间均在数毫秒之内,为搜索提供强劲动力。 4. 词组识别准确率高 采用特殊的词组拆分识别算法,可有效消除汉语词组中汉语歧义,并可识别各个行业内的特殊用语、专用词汇、公司名、地名等,并具有汉语语、汉语短语识别功能。如:'醉翁之意不在酒'。经长期使用及大量文本测试其准确率可达到92%以上。 5. 拆分覆盖面广 含盖了IT、化工、金融、贸易、纺织、电子、制造、冶金等各行各业以及日常生活用语中的汉语词组。 6. 提供词组自定义功能 可根据用户需要自行添加汉语词组,并提单个汉字添加或从文件批量添加功能。 7.特殊字符过滤功能 可根据用户需要自行定义影响检索结果的不必要的字符。如:! % *等。 9. 具有英文分词识别功能。 本组件同时具有英文单词的分词识别功能。 10. 词性标注功能。(限企业A版) 词性:即词组在汉语语言中所表述的性质。如:计算机 /名词; 中国 / 名词,方位词 此功能可对拆分出的汉语词组进行词性标注,辅以开发人员理解分析文本序列中所包含的语义或意图。其广泛应用于互联网信息搜索以提高搜索精度、智能聊天机器人理解对方话语的含义等领域。整个分词标注以北京大学词性标注集为标准。(详细可参见词性标注表) 11. 词频标注功能。(限企业B版) 词频:即词组在广域的所有汉语词组中出现的相对频率值。 此功能可对拆分出的汉语词组进行词频标识。为开发人员在对搜索关键词的理解分析上提供有效的参考,以提高检索精度。整个词频标识是以各大报刊媒体文章为基础,经过精心的统计分析制作而,具有相当的参考价值。 三、在线演示/免费下载 在线演示:http://61.129.81.124/csw/csw50.asp 四、各语言调用示例代码 参数一:InputString[string类型] 需进行分词的原始文本 参数二:OutputType[int整型] 输出类型 (0 标准分词输出, 1 附带词性输出, 2 附带词频输出) 参数三:DllPath[string类型] 本组件在系统中的完整路径 返回:OutputString[string类型] 输出分词后的文本序列 1. C#调用示例代码 首先运行本组件包中的install.bat文件,在系统中注册本组件。 然后在开发工具中引用CSW.dll组件 //以下为C#控制台应用程序中调用本组件示例代码. CSWLib.SplitWordClass csw = new CSWLib.SplitWordClass(); string text = csw.Split('待拆分原始文本',0,@'c:winntsystem'); Console.WriteLine(text); Console.ReadLine(); //暂停,查看输出 访问官方网站获得更多代码示例。

20,359

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧