Skip to content

Commit ff4e41f

Browse files
authored
Merge pull request #20 from lanzkron/patch-2
use specified costs when one of the strings is empty
2 parents a45c796 + 106489c commit ff4e41f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

strsimpy/weighted_levenshtein.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
# SOFTWARE.
2020

21+
from functools import reduce
2122
from .string_distance import StringDistance
2223

2324

@@ -52,9 +53,9 @@ def distance(self, s0, s1):
5253
if s0 == s1:
5354
return 0.0
5455
if len(s0) == 0:
55-
return len(s1)
56+
return reduce(lambda cost, char: cost + self.insertion_cost_fn(char), s1, 0)
5657
if len(s1) == 0:
57-
return len(s0)
58+
return reduce(lambda cost, char: cost + self.deletion_cost_fn(char), s0, 0)
5859

5960
v0, v1 = [0.0] * (len(s1) + 1), [0.0] * (len(s1) + 1)
6061

0 commit comments

Comments
 (0)