英文分词算法(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)分词中的 ...
随机推荐
- Using LINQ to SharePoint
LINQ and LINQ Providers LINQ is a feature of the programming languages C# and Microsoft Visual Bas ...
- android与网络的交互
有三种方式: 数据下载,数据上传,数据浏览 URL中一些符号 ?分隔URL和参数 &URL中参数之间的分隔符 =URL中参数对应的值
- javascript 方法实例
输出对象的属性名称与值 : boj(o){ for(var p in o){ console.log(p + ":" + o[p] + "\n"); } } 构 ...
- nodeJS+bootstarp+mongodb整一个TODO小例子
又是一个简单的小玩意儿, 不过有个大玩意儿,就是nosql的mongodb(文件大小:130M), 你要下载一个mongdodb, 去官方网站下载 安装以后在mongodb的命令行目录下执行 mon ...
- Android Studio开发调试使用
Android Studio调试其实也非常方便,一般问题直接通过AS的DDMS的Logcat就可以搞定.AS支持类似Eclipse的DDMS的所有功能.这里要说的是疑难问题的调试方式,即断点调试. 首 ...
- Http 和TCP的关系,TCP长连接和短连接有什么区别?
HTTP 协议即超文本传送协议(Hypertext Transfer Protocol ),是Web联网的基础,也是手机联网常用的协议之一,HTTP协议是建立在TCP协议之上的一种应用.由于HTTP在 ...
- 【POJ 2480】Longge's problem(欧拉函数)
题意 求$ \sum_{i=1}^n gcd(i,n) $ 给定 $n(1\le n\le 2^{32}) $. 链接 题解 欧拉函数 $φ(x)$ :1到x-1有几个和x互质的数. gcd(i,n) ...
- C++强制类型转换操作符 dynamic_cast
dynamic_cast是四个强制类型转换操作符中最特殊的一个,它支持运行时识别指针或引用. >>>>>>>>>>>编译器的RTTI设 ...
- [学习笔记]四边形不等式优化DP
形如$f[i][j]=min{f[i][k]+f[k+1][j]}+w[i][j]$的方程中, $w[\;][\;]$如果同时满足: ①四边形不等式:$w[a][c]+w[b][d]\;\leq\;w ...
- js-JavaScript高级程序设计学习笔记6
第八章 BOM 1.BOM的核心对象是window,他表示浏览器的一个实例.在浏览器中,window对象有双重角色,它既是通过JS访问浏览器窗口的一个接口,又是ES规定的Global对象. 2.定义全 ...