Skip to content

Instantly share code, notes, and snippets.

@gandroz
Last active May 5, 2021 14:22
Show Gist options
  • Save gandroz/c9811238fbf05b904dc54bf2f8ce2f29 to your computer and use it in GitHub Desktop.
Save gandroz/c9811238fbf05b904dc54bf2f8ce2f29 to your computer and use it in GitHub Desktop.
test function to call c methods
# load c library
cmodule = load_module()
# define source and target strings
source = "levenshtein"
target = "levenstein"
# define edition costs
insert_cost = 1
delete_cost = 1
replace_cost = 2
# call c function
res = cmodule.levenshtein(source.encode('utf-8'), # encode the string into binary representation
target.encode('utf-8'),
np.int32(insert_cost), #explicitly tells that we need a 32bits integer
np.int32(delete_cost),
np.int32(replace_cost))
print(f"Levenshtein distance between '{source}' and '{target}': {res}")
# prints "Levenshtein distance between 'levenshtein' and 'levenstein': 1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment