Last active
May 5, 2021 14:22
-
-
Save gandroz/c9811238fbf05b904dc54bf2f8ce2f29 to your computer and use it in GitHub Desktop.
test function to call c methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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