- 浏览: 272318 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (161)
- 【**计划】 (2)
- 【**Core Java**】 (30)
- 【**JAVA EE】 (6)
- JDBC (3)
- Hibernate专题系列 (0)
- 【**OS】 (14)
- 【**架构设计/设计模式】 (11)
- 【Hadoop】 (3)
- 【**分布式】 (9)
- 模板 (1)
- C (2)
- 常用工具 (1)
- Oracle (2)
- 【Tips】 (3)
- 【数据库】 (2)
- 玩转Ubuntu (0)
- 【计算机网络/网络编程】 (7)
- 【**Search Engine】 (21)
- 【**专题**】 (6)
- 【**Python】 (10)
- XML (1)
- 【**Open Source Framework】 (1)
- 【高级主题】 (1)
- 【存储】 (3)
- 【笔试面试】 (2)
- 【**数据结构与算法设计】 (20)
- 【其他】 (3)
- 【编程练习】 (2)
- 【待完成】 (12)
- 【工作】 (6)
- 【软件研发】 (4)
- 【**多线程多进程编程】 (5)
- 【Web Service】 (1)
- 【表达式解析/JavaCC系列】 (5)
- 【缓存系统:Memcached】 (1)
- 【Java IO/NIO】 (5)
- 【JVM运行机制及内存管理】 (7)
最新评论
-
107x:
...
python list排序 -
yuzhu223:
...
【Python基础】Python的lambda函数与排序 -
Tonyguxu:
分析查询结果的打分小于11.query=1065800715* ...
lucene打分机制的研究 -
Tonyguxu:
query=139320661963.013709 = (MA ...
lucene打分机制的研究 -
Tonyguxu:
query=10658007150.6772446 = (MA ...
lucene打分机制的研究
如何比较两个字符串之间的相似程度(或者差异)?
想要比较两个字符串之间的相似程度,可以看其中一个字符串通过几步操作可以转换为另一个字符串,通过度量转换操作的步数可以来衡量两个串的相似程度,如果转换步数越少,则两者越匹配。这里转换操作的度量就称为:
edit distance。该值越小,则两个字符串越匹配。
但是对edit distance有不同的definition
http://en.wikipedia.org/wiki/Edit_distance写道
edit distance between two strings of characters generally refers to the Levenshtein distance.
However,The term ‘edit distance’ is sometimes used to refer to the distance in which insertions and deletions have equal cost and replacements have twice the cost of an insertion”
There are several different ways to define an edit distance, depending on which edit operations are allowed: replace, delete, insert, transpose, and so on.
However,The term ‘edit distance’ is sometimes used to refer to the distance in which insertions and deletions have equal cost and replacements have twice the cost of an insertion”
There are several different ways to define an edit distance, depending on which edit operations are allowed: replace, delete, insert, transpose, and so on.
相应的也有不同的算法来计算这个值,常见的有Levenshtein distance
Levenshtein distance
http://en.wikipedia.org/wiki/Levenshtein_distance 写道
The Levenshtein distance between two strings is defined as the minimum number of edits needed to transform one string into the other, with the allowable edit operations being insertion, deletion, or substitution of a single character.
算法基本步骤
1 | Set n to be the length of s. Set m to be the length of t. If n = 0, return m and exit. If m = 0, return n and exit. Construct a matrix containing 0..m rows and 0..n columns. |
2 | Initialize the first row to 0..n. Initialize the first column to 0..m. |
3 | Examine each character of s (i from 1 to n). |
4 | Examine each character of t (j from 1 to m). |
5 |
If s[i] equals t[j], the cost is 0. If s[i] doesn't equal t[j], the cost is 1. |
6 | Set cell d[i,j] of the matrix equal to the minimum of: a. The cell immediately above plus 1: d[i-1,j] + 1. b. The cell immediately to the left plus 1: d[i,j-1] + 1. c. The cell diagonally above and to the left plus the cost: d[i-1,j-1] + cost. |
7 | After the iteration steps (3, 4, 5, 6) are complete, the distance is found in cell d[n,m]. |
比较"GUMBO"和"GAMBOL"的相似程度,计算两者的edit distance
参考
1.Levenshtein_distance
http://www.merriampark.com/ld.htm
http://en.wikipedia.org/wiki/Levenshtein_distance
2.Edit_distance
http://en.wikipedia.org/wiki/Edit_distance
发表评论
-
LRU算法介绍
2012-06-05 22:30 3711问题背景 在操作系统的内存管理里,如何节省有限的内存并为尽可 ... -
数据结构之位图bitmap
2012-05-10 23:12 0http://dongxicheng.org/structur ... -
常见数据结构与算法汇总
2012-05-10 23:01 10761、常见数据结构 线性:数组,链表,队列, ... -
数据结构之位图
2012-05-10 18:34 5615介绍 (20120511)位图就是通过将数组下标与应用中 ... -
CRC循环校验
2012-05-10 15:11 1326http://www.360doc.com/content/1 ... -
map3搜索与存储的一道面试题
2012-05-10 15:10 887假设一个mp3搜索引擎收录了2^24首歌曲,并记录了可收听这些 ... -
排序算法
2012-04-21 23:06 641插入排序 shell排序 ... -
【编程珠矶】开篇 千万号码的排序问题
2012-04-21 12:52 911注:学习了《编程珠矶》第一章,将涉及的一些知识点整理如下 ... -
WXXR LRUList的实现
2012-03-01 16:01 753LRUList -
【专题】分治递归+排序算法
2012-03-01 11:47 658123 -
【排序】merge排序
2012-02-28 09:59 840前言 主要学习 http://en.wikipedia.or ... -
【排序】快速排序
2012-02-27 18:40 911前言 快速排序(Quick Sort)算法是 “递归+分治” ... -
算法类博客推荐
2012-02-24 18:17 5901. http://blog.csdn.net/v_J ... -
递归与分治
2012-02-24 18:16 988分治与递归基本思想 分治:分治强调“分 ... -
Apache LRUMap实现
2012-02-23 13:10 1065源码是 org.apache.commons.collect ... -
WXXR LRUMap的实现
2012-02-22 18:33 1860前言 实现LRU算法,注意观察者模式、并发(读写锁、线程池) ... -
【专题】LRU
2012-02-22 16:21 1500包含如下内容: 一. LRU算法 ht ... -
LRU理论
2012-02-21 18:46 10001.LRU算法介绍 LRU是Least Rec ... -
【排序算法】冒泡排序(bubble sort)
2012-02-19 12:16 0问题描述 将一组乱序的整形按照由小到大排序 算法思路 经 ... -
【Core Java】并发集合
2012-02-02 17:05 1118并发容器与同步容器 ...
相关推荐
比KMP更快的字符串匹配算法——BM算法,排序算法数据结构 最快的排序算法
字符串的模式匹配算法——KMP的C++实现。
带通配符的字符串匹配算法,带通配符的字符串匹配算法
串匹配(String Matching)问题是计算机科学中的一个基本问题,也是复杂性理论中研究的...本章中分别介绍改进的KMP串匹配算法,采用散列技术的随机串匹配算法,基于过滤算法的近似串匹配算法,以及它们的MPI编程实现。
字符串匹配算法之Horspool算法(英文原版)
KMP字符串匹配算法,一种快速模式匹配算法
改进的多模式字符串匹配算法,改进的多模式字符串匹配算法
常见的字符串匹配算法及实现
一般而言文本就是要编辑的文档,而模式字符串往往由用户来指定,高效的字符串匹配 算法可以提高程序的响应性能,当然字符串匹配算法的应用远远不止于此,例如在生物计算科学中查找特定的DNA序列,也是字符串匹配算法...
包括以下几种字符串匹配算法的C代码实现,谨供参考: 平凡算法(SimpleSM); KMP算法(KMPSM); BM算法(bmSM); RK算法(rkSM);
首先对三种基本字符串匹配算法进行了详细分析和说明,再编程实现。创新拓展研究了Boyer-Moore算法,进行了分析和编程实现。让四种算法对数据量极大的文本,进行子串的查询处理,并分析算法运行时间效率,并对所有...
较为全面的字符串匹配算法,一共35中算法 全英文
KMP算法(Knuth-Morris-Pratt算法)是一种高效的字符串匹配算法,由Donald Knuth、Vaughan Pratt和James H. Morris共同发明。KMP算法通过使用一个称为“部分匹配表”或“next数组”的数组来减少字符串匹配过程中的...
字符串比对的几大算法,包括KMP,BM,Sunday等
KMP算法(Knuth-Morris-Pratt算法)是一种高效的字符串匹配算法,由Donald Knuth、Vaughan Pratt和James H. Morris共同发明。KMP算法通过使用一个称为“部分匹配表”或“next数组”的数组来减少字符串匹配过程中的...
字符串匹配算法的演示程序,包括了平凡算法、KMP、RK、BM四种,有界面,统计展示移动和比较次数等信息。
KMP算法是一种改进的字符串匹配算法,由D.E.Knuth,J.H.Morris和V.R.Pratt同时发现,因此人们称它为克努特——莫里斯——普拉特操作(简称KMP算法)。KMP算法的关键是利用匹配失败后的信息,尽量减少模式串与主串的...
多种字符串匹配算法介绍与性能分析,包括kmp、ac自动机等算法。