File tree Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -144,15 +144,25 @@ It can also be used for keyboard typing auto-correction. Here the cost of substi
144144
145145``` python
146146from strsimpy.weighted_levenshtein import WeightedLevenshtein
147- from strsimpy.weighted_levenshtein import CharacterSubstitutionInterface
148147
149- class CharacterSubstitution (CharacterSubstitutionInterface ):
150- def cost (self , c0 , c1 ):
151- if c0== ' t' and c1== ' r' :
152- return 0.5
153- return 1.0
154148
155- weighted_levenshtein = WeightedLevenshtein(CharacterSubstitution())
149+ def insertion_cost (char ):
150+ return 1.0
151+
152+
153+ def deletion_cost (char ):
154+ return 1.0
155+
156+
157+ def substitution_cost (char_a , char_b ):
158+ if char_a == ' t' and char_b == ' r' :
159+ return 0.5
160+ return 1.0
161+
162+ weighted_levenshtein = WeightedLevenshtein(
163+ substitution_cost_fn = substitution_cost,
164+ insertion_cost_fn = insertion_cost,
165+ deletion_cost_fn = deletion_cost)
156166print (weighted_levenshtein.distance(' String1' , ' String2' ))
157167
158168```
You can’t perform that action at this time.
0 commit comments