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
144
144
145
145
``` python
146
146
from strsimpy.weighted_levenshtein import WeightedLevenshtein
147
- from strsimpy.weighted_levenshtein import CharacterSubstitutionInterface
148
147
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
154
148
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)
156
166
print (weighted_levenshtein.distance(' String1' , ' String2' ))
157
167
158
168
```
You can’t perform that action at this time.
0 commit comments