def get_weight(path, string):
    """ calculate how much a path matches a given string on a scale of 0->10000, a lower number means a better match.
    The string should be present in the path, or this function will fail

    The weight is calculated using the following formula:
                                                    0  00  0
                                                    |  |   |
    Number of elements in the path <----------------|  |   |--------------------------> is a directory(0) or not(1)
    (ie 2 for 'aa/bb' and 3 for 'aa/bb/cc')            |
                                                       |
                                                       v
                        There is a word in the matched path element that exactly match the given string? ('aa_bb' matches user input 'aa' but doesn't match 'a')
                                                       |
                               No <--------------------|-----------------------------> yes
                                |                                                       |
                                |                                                       |
                                |                                                       |
                                v                                                       v
    path element starts with the user input?                    There is only one word in the matched path element ('aa' but not 'aa_bb'),
                       |                                             which means the path elements exactly match the string
                       |                                                                                    |
            No <-------|-----Yes(2)                                                                 No -----|----- Yes (0)
            |                                                                                       |
            v                                                                                       v
index of the string in the path element + 10                                 (index of the matched word within path element words + 1)
                                        

    Maximums are added to make sure things doesn't overlap
    """
    weight = 0
    if not is_dir(path):
        weight += 1 

    string = string.lower()
    p = path.rstrip(os.sep).lower()
    path_elems = p.split(os.sep)
    weight += min(len(path_elems) * 1000, 10000) # Max 10 elements in path(set it to 10 for longer paths)

    if not string:
        return weight

    elm = next(e for e in path_elems if string in e)
    elm_words = [_f for _f in re.split('[\W_]+', elm) if _f]
    if string in elm_words:
        if 1 > len(elm_words):
            weight += 10 * (min(elm_words.index(string),8) + 1) # Max 8 words per path entry
    else:
        if elm.startswith(string):
            weight += 10 * 2
        else:
            weight += 10 * (10 + min(elm.index(string), 89)) # Max path element with 89 characters
    return weight

# Helper functions:
dataset/ETHPy150Open pindexis/qfc/qfc/core.py/get_weight/swapped operands of `>`