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. window php redis扩展下载地址

    redis扩展下载 http://windows.php.net/downloads/pecl/snaps/redis/

  2. Beta版本冲刺———第六天

    会议照片: 项目燃尽图: 1.项目进展: 该项目的Beta版本冲刺到今天就大体结束,但是小组依然困在"如何保存每次游戏的分数,并将其排序列在排行榜中"的问题上,小组四个人都在一起解 ...

  3. extJs学习基础 容器的介绍

    Viewport: 一个专门的容器用于可视应用领域(浏览器窗口). Viewport渲染自身到网页的documet body区域, 并自动将自己调整到适合浏览器窗口的大小,在窗口大小发生改变时自动适应 ...

  4. oracle-day1

    今天的学习内容是oracle产品的三种安装方式,还有使用dbca静默建库 oracle产品的三种安装方式分别为: 1.图形化(Java向导)安装引导 2.使用应答文件静默安装 3.直接将装好的orac ...

  5. java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 错误

    你的ArrayList 是一个没有值的对象(不是null),也就是里面什么对象也没有存(即:arrayList.size()==0).但是,你有取它下标为0值的操作.所以,数组越界了!!比如array ...

  6. Shell命令_正则表达式

    正则表达式是包含匹配,通配符是完全匹配 基础正则表达式 test.txt示例文件 1 2 3 4 5 6 7 8 9 10 11 12 Mr. James said: he was the hones ...

  7. Kernel Methods (5) Kernel PCA

    先看一眼PCA与KPCA的可视化区别: 在PCA算法是怎么跟协方差矩阵/特征值/特征向量勾搭起来的?里已经推导过PCA算法的小半部分原理. 本文假设你已经知道了PCA算法的基本原理和步骤. 从原始输入 ...

  8. Spring 在web 容器中的启动过程

    1.对于一个web 应用,其部署在web 容器中,web 容器提供其一个全局的上下文环境,这个上下文就是 ServletContext ,其后面的spring IoC 容器提供宿主环境 2.在web. ...

  9. java-二维码编写zxing

    zxing 这个是google的 下载地址 http://code.google.com/p/zxing/downloads/list 二维码源码案例 package com.utils; impor ...

  10. cygwin-介绍-安装

    初学linux时,最头疼的是,因为windows和linux各有优点,各有用途,所以只能麻烦的在两者之间切换,不断的重启.开机时也麻烦,因为初学者大多数使用windows,装了linux后,开机会自动 ...