فهرست منبع

Update example

luozhouyang 5 سال پیش
والد
کامیت
43057b2297
1فایلهای تغییر یافته به همراه17 افزوده شده و 7 حذف شده
  1. 17 7
      README.md

+ 17 - 7
README.md

@@ -144,15 +144,25 @@ It can also be used for keyboard typing auto-correction. Here the cost of substi
 
 
 ```python
 ```python
 from strsimpy.weighted_levenshtein import WeightedLevenshtein
 from strsimpy.weighted_levenshtein import WeightedLevenshtein
-from strsimpy.weighted_levenshtein import CharacterSubstitutionInterface
 
 
-class CharacterSubstitution(CharacterSubstitutionInterface):
-    def cost(self, c0, c1):
-        if c0=='t' and c1=='r':
-            return 0.5
-        return 1.0
 
 
-weighted_levenshtein = WeightedLevenshtein(CharacterSubstitution())
+def insertion_cost(char):
+    return 1.0
+
+
+def deletion_cost(char):
+    return 1.0
+
+
+def substitution_cost(char_a, char_b):
+    if char_a == 't' and char_b == 'r':
+        return 0.5
+    return 1.0
+
+weighted_levenshtein = WeightedLevenshtein(
+    substitution_cost_fn=substitution_cost,
+    insertion_cost_fn=insertion_cost,
+    deletion_cost_fn=deletion_cost)
 print(weighted_levenshtein.distance('String1', 'String2'))
 print(weighted_levenshtein.distance('String1', 'String2'))
 
 
 ```
 ```