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 connectedconnectingconnection 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里发现了下面这句话!恍然大悟。

The purpose of stemming is to bring variant forms of a word together, not to map a word onto its ‘paradigm’ form.
Porter stemmer
并不是要把单词变为规范的那种原来的样子,它只是把很多基于这个单词的变种变为某一种形式!换句话说,它不能保证还原到单词的原本,也就
是"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)的更多相关文章

  1. python 安装nltk,使用(英文分词处理,词干化等)(Green VPN)

    安装pip命令之后: sudo pip install -U pyyaml nltk import nltk nltk.download() 等待ing 目前访问不了,故使用Green VPN htt ...

  2. C#分词算法

    本文用到的库下载:点此下载 词库下载:点此下载 将词库直接放到项目根目录 词库设置如下: 类库说明 词库查看程序:点此下载 可以在上面的程序中添加常用行业词库 还可以通过下面的类在程序中实现 完整的盘 ...

  3. java的英文词频算法

    java实现的英文词频算法,通常是采用单词树来实现的.使用java实现词频统计,为了统计词汇出现频率,最简单的做法是再建立一个map,其中,key是单词,value代表次数.将文章从头读到尾,读到一个 ...

  4. IK分词算法设计总结

    IK分词算法设计思考 加载词典 IK分词算法初始化时加载了“敏感词”.“主词典”.“停词”.“量词”,如果这些词语的数量很多,怎么保证加载的时候内存不溢出 分词缓冲区 在分词缓冲区中进行分词操作,怎么 ...

  5. LTP 分词算法实践

    参考链接: https://github.com/HIT-SCIR/ltp/blob/master/doc/install.rst http://www.xfyun.cn/index.php/serv ...

  6. 中文分词算法之最大正向匹配算法(Python版)

    最大匹配算法是自然语言处理中的中文匹配算法中最基础的算法,分为正向和逆向,原理都是一样的. 正向最大匹配算法,故名思意,从左向右扫描寻找词的最大匹配. 首先我们可以规定一个词的最大长度,每次扫描的时候 ...

  7. 浅谈分词算法(5)基于字的分词方法(bi-LSTM)

    目录 前言 目录 循环神经网络 基于LSTM的分词 Embedding 数据预处理 模型 如何添加用户词典 前言 很早便规划的浅谈分词算法,总共分为了五个部分,想聊聊自己在各种场景中使用到的分词方法做 ...

  8. 浅谈分词算法(4)基于字的分词方法(CRF)

    目录 前言 目录 条件随机场(conditional random field CRF) 核心点 线性链条件随机场 简化形式 CRF分词 CRF VS HMM 代码实现 训练代码 实验结果 参考文献 ...

  9. 浅谈分词算法(3)基于字的分词方法(HMM)

    目录 前言 目录 隐马尔可夫模型(Hidden Markov Model,HMM) HMM分词 两个假设 Viterbi算法 代码实现 实现效果 完整代码 参考文献 前言 在浅谈分词算法(1)分词中的 ...

随机推荐

  1. 一次神奇的WCF的404错误解决

    现象:浏览器中可以访问元数据,但是运行的时候却报404的异常,说目标地址找不到. 折腾了一下午. 引用服务后config中的client的address是这样的http://host/aspx/Ser ...

  2. 【瞎想】TDD与汉字;FDD与英语字母

    我觉得TDD与汉字;FDD与英语字母他们之间有相似性. FDD的上行和下行用频率的不同来区分,TDD的上行和下行用相同的频率然后在同一时刻相差半个波长(对称频率).如果用维度数描述,FDD是1维的话, ...

  3. dblink连接的目标端 session不断的问题。

    来源于:http://blog.itpub.net/22782896/viewspace-676842/ 1.在使用了dblink的存储过程中,可以显示的手动关闭dblink连接,具体写法如下(测试存 ...

  4. nginx安装(1) – ttlsa教程系列之nginx

    1.必要软件准备 安装pcre 为了支持rewrite功能,我们需要安装pcre   1 # yum install pcre* //如过你已经装了,请跳过这一步 安装openssl 需要ssl的支持 ...

  5. [转]java.lang.OutOfMemoryError: PermGen space及其解决方法

    原文地址:http://peak.iteye.com/blog/52606 这个问题是我的工程中加入了Birt报表在Linux环境下运行出现的问题,从网上搜索了一下看到这文章发现并不是由于Birt的原 ...

  6. 远程登录服务器执行cmd的Python脚本

    import paramiko,os,sys ip = raw_input("input ip address :>>>") password = raw_inp ...

  7. java环境变量设置

    java环境变量设置 1.打开我的电脑--属性--高级--环境变量 2.新建系统变量JAVA_HOME 和CLASSPATH 变量名:JAVA_HOME 变量值:C:\Program Files\Ja ...

  8. poi-处理excel的单元格日期数据

    poi处理excel时,当excel没有明确指明是哪个类型的数据时,poi很可能处理单元格的日期数据时就有可能是一串数字.而使用java程序基本无法转换 以下为对poi处理日期情况一些方面的处理(不是 ...

  9. 【CodeForces 589F】Gourmet and Banquet(二分+贪心或网络流)

    F. Gourmet and Banquet time limit per test 2 seconds memory limit per test 512 megabytes input stand ...

  10. skiing

    package noj_skiing; import java.util.*; import java.math.*; public class Main { public static void m ...