Code Duplication    Length = 32-32 lines in 2 locations

abydos/distance.py 2 locations

@@ 2516-2547 (lines=32) @@
2513
    return 1 - sim_prefix(src, tar)
2514
2515
2516
def sim_suffix(src, tar):
2517
    """Return the suffix similarity of two strings.
2518
2519
    Suffix similarity
2520
2521
    Suffix similarity is the ratio of the length of the shorter term that
2522
    exactly matches the longer term to the length of the shorter term,
2523
    beginning at the end of both terms.
2524
2525
    :param str src, tar: two strings to be compared
2526
    :returns: suffix similarity
2527
    :rtype: float
2528
2529
    >>> sim_suffix('cat', 'hat')
2530
    0.6666666666666666
2531
    >>> sim_suffix('Niall', 'Neil')
2532
    0.25
2533
    >>> sim_suffix('aluminum', 'Catalan')
2534
    0.0
2535
    >>> sim_suffix('ATCG', 'TAGC')
2536
    0.0
2537
    """
2538
    if src == tar:
2539
        return 1.0
2540
    if not src or not tar:
2541
        return 0.0
2542
    min_word, max_word = (src, tar) if len(src) < len(tar) else (tar, src)
2543
    min_len = len(min_word)
2544
    for i in range(min_len, 0, -1):
2545
        if min_word[-i:] == max_word[-i:]:
2546
            return i/min_len
2547
    return 0.0
2548
2549
2550
def dist_suffix(src, tar):
@@ 2458-2489 (lines=32) @@
2455
    return 1 - sim_length(src, tar)
2456
2457
2458
def sim_prefix(src, tar):
2459
    """Return the prefix similarty of two strings.
2460
2461
    Prefix similarity
2462
2463
    Prefix similarity is the ratio of the length of the shorter term that
2464
    exactly matches the longer term to the length of the shorter term,
2465
    beginning at the start of both terms.
2466
2467
    :param str src, tar: two strings to be compared
2468
    :returns: prefix similarity
2469
    :rtype: float
2470
2471
    >>> sim_prefix('cat', 'hat')
2472
    0.0
2473
    >>> sim_prefix('Niall', 'Neil')
2474
    0.25
2475
    >>> sim_prefix('aluminum', 'Catalan')
2476
    0.0
2477
    >>> sim_prefix('ATCG', 'TAGC')
2478
    0.0
2479
    """
2480
    if src == tar:
2481
        return 1.0
2482
    if not src or not tar:
2483
        return 0.0
2484
    min_word, max_word = (src, tar) if len(src) < len(tar) else (tar, src)
2485
    min_len = len(min_word)
2486
    for i in range(min_len, 0, -1):
2487
        if min_word[:i] == max_word[:i]:
2488
            return i/min_len
2489
    return 0.0
2490
2491
2492
def dist_prefix(src, tar):