Skip to content

Commit

Permalink
Merge pull request #316 from stephenhky/readthedocs
Browse files Browse the repository at this point in the history
Documentation for Demarau-Levenshtein distance and longest common prefix
  • Loading branch information
stephenhky authored Dec 14, 2024
2 parents 151fe01 + 0bebda7 commit b21630a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion shorttext/metrics/dynprog/dldist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@


@nb.njit
def damerau_levenshtein(word1, word2):
def damerau_levenshtein(word1: str, word2: str) -> int:
""" Calculate the Demarau-Levenshtein (DL) distance between two words.
:param word1: first word
:param word2: seccond word
:return: Damerau-Levenshtein (DL) distance
:type word1: str
:type word2: str
:rtype: int
"""
len1 = len(word1)
len2 = len(word2)
matrix = np.zeros((len1+1, len2+1), dtype=np.int8)
Expand Down
9 changes: 9 additions & 0 deletions shorttext/metrics/dynprog/lcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

@nb.njit
def longest_common_prefix(word1: str, word2: str) -> int:
""" Calculate the longest common prefix (LCP) between two words.
:param word1: first word
:param word2: seccond word
:return: longest common prefix (LCP)
:type word1: str
:type word2: str
:rtype: int
"""
lcp = 0
for i in range(min(len(word1), len(word2))):
if word1[i] == word2[i]:
Expand Down

0 comments on commit b21630a

Please sign in to comment.