Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,52 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary
|
||||
|
||||
n = 0
|
||||
w = ''
|
||||
n = n + 1; w[0] = n; w[n] = "kitten sitting"
|
||||
n = n + 1; w[0] = n; w[n] = "rosettacode raisethysword"
|
||||
|
||||
loop n = 1 to w[0]
|
||||
say w[n].word(1) "->" w[n].word(2)":" levenshteinDistance(w[n].word(1), w[n].word(2))
|
||||
end n
|
||||
return
|
||||
|
||||
method levenshteinDistance(s, t) private static
|
||||
s = s.lower
|
||||
t = t.lower
|
||||
|
||||
m = s.length
|
||||
n = t.length
|
||||
|
||||
-- for all i and j, d[i,j] will hold the Levenshtein distance between
|
||||
-- the first i characters of s and the first j characters of t;
|
||||
-- note that d has (m+1)x(n+1) values
|
||||
d = 0
|
||||
|
||||
-- source prefixes can be transformed into empty string by
|
||||
-- dropping all characters (Note, ooRexx arrays are 1-based)
|
||||
loop i = 2 to m + 1
|
||||
d[i, 1] = 1
|
||||
end i
|
||||
|
||||
-- target prefixes can be reached from empty source prefix
|
||||
-- by inserting every characters
|
||||
loop j = 2 to n + 1
|
||||
d[1, j] = 1
|
||||
end j
|
||||
|
||||
loop j = 2 to n + 1
|
||||
loop i = 2 to m + 1
|
||||
if s.substr(i - 1, 1) == t.substr(j - 1, 1) then do
|
||||
d[i, j] = d[i - 1, j - 1] -- no operation required
|
||||
end
|
||||
else do
|
||||
d[i, j] = -
|
||||
(d[i - 1, j] + 1).min( - -- a deletion
|
||||
(d[i, j - 1] + 1)).min( - -- an insertion
|
||||
(d[i - 1, j - 1] + 1)) -- a substitution
|
||||
end
|
||||
end i
|
||||
end j
|
||||
|
||||
return d[m + 1, n + 1]
|
||||
Loading…
Add table
Add a link
Reference in a new issue