自用Excel VBA函数整理 part3
2010-10-16 16:16
113 查看
'http://en.wikipedia.org/wiki/Levenshtein_distance Public Function EditDistance(s, t, Optional costIns As Integer = 1, Optional costDel As Integer = 1, Optional costSub As Integer = 1) As Integer 'declaration, d(i,j) will hold the Levenshtein distance between 'the first i chars of s and the first j chars ot t Static d(0 To EDIT_DISTANCE_CACHE, 0 To EDIT_DISTANCE_CACHE) As Integer 'initialization, note that (m+1)*(n+1) distances is used m = Len(s): n = Len(t) For x = 0 To m For y = 0 To n d(x, y) = 0 Next y Next x 'source prefixes can be transformed into empty string by dropping all chars For i = 1 To m d(i, 0) = i * costDel Next i 'target prefixes can be reached from empty source prefix by inserting every chars For j = 1 To n d(0, j) = j * costIns Next j For j = 1 To n For i = 1 To m If Mid(s, i, 1) = Mid(t, j, 1) Then d(i, j) = d(i - 1, j - 1) Else d(i, j) = WorksheetFunction.Min( _ d(i - 1, j) + costDel, _ d(i, j - 1) + costIns, _ d(i - 1, j - 1) + costSub) End If Next i Next j EditDistance = d(m, n) End Function
EditDistance
Example of workbook already enabled:
1. JSON
2. XmlHttp (via usage of API for Geocoding)
3. Geo Distance Calculation From Lng & Lat
[Download Here]
相关文章推荐
- 自用Excel VBA函数整理 part1
- [整理自用]c++错题(长期更新)
- Python的一些内容整理, part 2
- 【整理自用】凸包问题
- C++知识碎片整理(11)——自用数学函数
- 自编自用的歌曲整理程序 js+html+hta
- LeetCode Array算法题(Easy级别)整理 Part 2
- JavaScript高级程序设计——知识点整理(Part 2)
- Android实现即时音效和背景音乐(整理自用)
- UI整理-----part9--标签控制器(tabBarController)
- springMVC 知识点整理PART 1(基本概念)
- 整理(自用):修改 Tomcat使用的 JDK
- 【整理自用】计算机运算符
- DB2 V9 常用SQL整理 - Part 1
- springMVC 知识点整理PART 2(控制器与视图之间数据的)
- 自用整理的
- 【整理自用】统计学习、机器学习常见算法(整理更新)
- sql Server与ORACLE的语法区别 自用整理!
- sparksql2.0整理-自用
- 夏令营讲课内容整理 Day 6 Part 1.