aboutsummaryrefslogtreecommitdiffstats
path: root/lcs.py
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2013-08-04 12:53:15 +0200
committerThibaut Horel <thibaut.horel@gmail.com>2013-08-04 12:53:15 +0200
commit8431ad45020540c771fbb1a80a63aca07fcf586a (patch)
treedae6102982348e31c385c58d145af54465e6aeec /lcs.py
parent331499d08be1ef32e5bb6200963ebc63500eb826 (diff)
downloadocr-layer-curation-8431ad45020540c771fbb1a80a63aca07fcf586a.tar.gz
Add some string utils functions
Levenshtein distance and word hyphenation
Diffstat (limited to 'lcs.py')
-rw-r--r--lcs.py24
1 files changed, 0 insertions, 24 deletions
diff --git a/lcs.py b/lcs.py
deleted file mode 100644
index c180241..0000000
--- a/lcs.py
+++ /dev/null
@@ -1,24 +0,0 @@
-def LCS(X, Y):
- m = len(X)
- n = len(Y)
- # An (m+1) times (n+1) matrix
- C = [[0] * (n+1) for i in range(m+1)]
- for i in range(1, m+1):
- for j in range(1, n+1):
- if X[i-1] == Y[j-1]:
- C[i][j] = C[i-1][j-1] + 1
- else:
- C[i][j] = max(C[i][j-1], C[i-1][j])
- return C
-
-def printDiff(C, X, Y, i, j):
- if i > 0 and j > 0 and X[i-1] == Y[j-1]:
- printDiff(C, X, Y, i-1, j-1)
- print " " + X[i-1]
- else:
- if j > 0 and (i == 0 or C[i][j-1] >= C[i-1][j]):
- printDiff(C, X, Y, i, j-1)
- print "+ " + Y[j-1]
- elif i > 0 and (j == 0 or C[i][j-1] < C[i-1][j]):
- printDiff(C, X, Y, i-1, j)
- print "- " + X[i-1]