英文分词算法(Porter stemmer)
http://blog.csdn.net/whuslei/article/details/7398443
最近需要对英文进行分词处理,希望能够实现还原英文单词原型,比如 boys 变为 boy 等。
简介
发现一个不错的工具Porter stemmer,主页是http://tartarus.org/~martin/PorterStemmer/。它被实现为N多版本,C、Java、Perl等。
下面是它的简单介绍:
Stemming, in the parlance of searching and information retrieval, is the
operation of stripping the suffices from a word, leaving its stem.
Google, for instance, uses stemming to search for web pages containing
the words connected, connecting, connection and connections when
you ask for a web page that contains the word connect.
There are basically two ways to implement stemming. The first approach
is to create a big dictionary that maps words to their stems. The
advantage of this approach is that it works perfectly (insofar as the
stem of a word can be defined perfectly); the disadvantages
are the space required by the dictionary and the investment required to
maintain the dictionary as new words appear. The second approach is to
use a set of rules that extract stems from words. The advantages of this
approach are that the code is typically
small, and it can gracefully handle new words; the disadvantage is that
it occasionally makes mistakes. But, since stemming is imperfectly
defined, anyway, occasional mistakes are tolerable, and the rule-based
approach is the one that is generally chosen.
In 1979, Martin Porter developed a stemming algorithm that, with minor
modifications, is still in use today; it uses a set of rules to extract
stems from words, and though it makes some mistakes, most common words
seem to work out right. Porter describes his
algorithm and provides a reference implementation in C at http://tartarus.org/~martin/PorterStemmer/index.html;
以前也曾经尝试过这个算法,但是因为下面的原因就放弃了!
比如输入 "create" 和 "created" ,得到的结果是 "creat" 。这点让我大失所望!这根本就没有把单词还原为原来的样子啊?
这次没办法,还是需要实现这样的功能,Google了半天,就发现Lucene里面有英文分词模块,可惜太复杂了,不适合我的这种简单应用。后来才知道,其实lucene里用的也就是这种方法。
于是乎,硬着头皮看了下他的主页,在FQA里发现了下面这句话!恍然大悟。
并不是要把单词变为规范的那种原来的样子,它只是把很多基于这个单词的变种变为某一种形式!换句话说,它不能保证还原到单词的原本,也就
是"created"不一定能还原到"create",但却可以使"create" 和 "created" ,都得到"creat" !
实例
比如我输入 "create" 和 "created" ,它解析得到 "creat"
那么,只需要在查询时也做同样的处理即可!比如查询 "create created",在数据库里查的时候,都只需要检索"creat"即可!
附录
简单词汇处理前后的对比:http://snowball.tartarus.org/algorithms/porter/diffs.txt
主程序(相当精悍啊):http://tartarus.org/martin/PorterStemmer/java.txt
英文分词算法(Porter stemmer)的更多相关文章
- python 安装nltk,使用(英文分词处理,词干化等)(Green VPN)
安装pip命令之后: sudo pip install -U pyyaml nltk import nltk nltk.download() 等待ing 目前访问不了,故使用Green VPN htt ...
- C#分词算法
本文用到的库下载:点此下载 词库下载:点此下载 将词库直接放到项目根目录 词库设置如下: 类库说明 词库查看程序:点此下载 可以在上面的程序中添加常用行业词库 还可以通过下面的类在程序中实现 完整的盘 ...
- java的英文词频算法
java实现的英文词频算法,通常是采用单词树来实现的.使用java实现词频统计,为了统计词汇出现频率,最简单的做法是再建立一个map,其中,key是单词,value代表次数.将文章从头读到尾,读到一个 ...
- IK分词算法设计总结
IK分词算法设计思考 加载词典 IK分词算法初始化时加载了“敏感词”.“主词典”.“停词”.“量词”,如果这些词语的数量很多,怎么保证加载的时候内存不溢出 分词缓冲区 在分词缓冲区中进行分词操作,怎么 ...
- LTP 分词算法实践
参考链接: https://github.com/HIT-SCIR/ltp/blob/master/doc/install.rst http://www.xfyun.cn/index.php/serv ...
- 中文分词算法之最大正向匹配算法(Python版)
最大匹配算法是自然语言处理中的中文匹配算法中最基础的算法,分为正向和逆向,原理都是一样的. 正向最大匹配算法,故名思意,从左向右扫描寻找词的最大匹配. 首先我们可以规定一个词的最大长度,每次扫描的时候 ...
- 浅谈分词算法(5)基于字的分词方法(bi-LSTM)
目录 前言 目录 循环神经网络 基于LSTM的分词 Embedding 数据预处理 模型 如何添加用户词典 前言 很早便规划的浅谈分词算法,总共分为了五个部分,想聊聊自己在各种场景中使用到的分词方法做 ...
- 浅谈分词算法(4)基于字的分词方法(CRF)
目录 前言 目录 条件随机场(conditional random field CRF) 核心点 线性链条件随机场 简化形式 CRF分词 CRF VS HMM 代码实现 训练代码 实验结果 参考文献 ...
- 浅谈分词算法(3)基于字的分词方法(HMM)
目录 前言 目录 隐马尔可夫模型(Hidden Markov Model,HMM) HMM分词 两个假设 Viterbi算法 代码实现 实现效果 完整代码 参考文献 前言 在浅谈分词算法(1)分词中的 ...
随机推荐
- [转]使用Sencha Ext JS 6打造通用应用程序
原文地址:http://www.uedsc.com/using-sencha-ext-js-6-to-build-universal-apps.html 在Sencha和整个Ext JS团队的支持下, ...
- Android Studio-目录结构
新建工程项目后AS的Product目录结构如下所示: .idea://AS生成的工程配置文件,类似Eclipse的project.properties. app://AS创建工程中的一个Module. ...
- svn服务器无法访问时检查几个文件:
出现该问题基本都是三个配置文件的问题,下面把这个文件列出来. svnserve.conf:[general]anon-access = readauth-access = writepassword- ...
- High购电商系统开发注意点
1.引入第三方框架AFnetworking时,记得在xcode项目添加安全属性(自认为). 2.异步加载数据时,如果用数组来装模型,记得对数组进行初始化.对控件的赋值一般在获取数据之后.如果用到Tab ...
- 关于使用 pushViewController: animated: 方法在下一个控制器中拿不到值的解决方法
如下代码: // 加载一个tabbar控制器 houseMessageTabbarController *houseTabbar = [[houseMessageTabbarController al ...
- HP新学知识
Oracle的框架中有webservice和portlet....但不是平时所知道的那种webservice
- BZOJ 3173: [Tjoi2013]最长上升子序列
3173: [Tjoi2013]最长上升子序列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1524 Solved: 797[Submit][St ...
- 【poj1061】 青蛙的约会
http://poj.org/problem?id=1061 (题目链接) 题意 两只青蛙在周长为L的球上沿一条直线向一个方向跳,每只每次分别跳m,n米,它们一开始分别在X,Y处,问跳几次两青蛙可以在 ...
- NAT功能的研究
通俗的话:现在大部分的家用路由器都是这个功能,一个公网IP的拨号网络,然后地下全部电脑都可以用这个IP上网,进行数据转发,这就是NAT. 参考:http://baike.baidu.com/link? ...
- Linux使用网盘客户端
1. 百度网盘 - bypy https://github.com/houtianze/bypy 这是一个基于Python的命令行客户端. 安装参考上面链接的说明,或者这篇文章(推荐,有告诉你如何安装 ...