Skip to content

Commit b21630a

Browse files
authored
Merge pull request #316 from stephenhky/readthedocs
Documentation for Demarau-Levenshtein distance and longest common prefix
2 parents 151fe01 + 0bebda7 commit b21630a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

shorttext/metrics/dynprog/dldist.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44

55

66
@nb.njit
7-
def damerau_levenshtein(word1, word2):
7+
def damerau_levenshtein(word1: str, word2: str) -> int:
8+
""" Calculate the Demarau-Levenshtein (DL) distance between two words.
9+
10+
:param word1: first word
11+
:param word2: seccond word
12+
:return: Damerau-Levenshtein (DL) distance
13+
:type word1: str
14+
:type word2: str
15+
:rtype: int
16+
"""
817
len1 = len(word1)
918
len2 = len(word2)
1019
matrix = np.zeros((len1+1, len2+1), dtype=np.int8)

shorttext/metrics/dynprog/lcp.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
@nb.njit
66
def longest_common_prefix(word1: str, word2: str) -> int:
7+
""" Calculate the longest common prefix (LCP) between two words.
8+
9+
:param word1: first word
10+
:param word2: seccond word
11+
:return: longest common prefix (LCP)
12+
:type word1: str
13+
:type word2: str
14+
:rtype: int
15+
"""
716
lcp = 0
817
for i in range(min(len(word1), len(word2))):
918
if word1[i] == word2[i]:

0 commit comments

Comments
 (0)