Ejemplo n.º 1
0
        def simpleKeyListGetting():
            def findInRange(start_index, end_index, step):
                local_found=[]
                for i in range(start_index, end_index, step):
                    dict_item = dict_keys[i]
                    is_found = isKeyListTextValid(dict_item)
                    if is_found:
                        local_found.append(dict_item)
                    else:
                        dict_part = binSearchFunction(dict_item)
                        is_match = (dict_part == k_part)
                        if not is_match:
                            break
                        else:
                            continue
                return local_found

            found_list=[]
            dict_keys = self.local_keys
            index = cm.binarySearch(dict_keys, k, key=binSearchFunction)
            is_found = (index >= 0)
            if not is_found:
                return found_list

            before_items = dict_keys[index-10: index]
            after_items = dict_keys[index: index+10]
            test_item = dict_keys[index]
            dict_key_len = len(dict_keys)

            start_stop_at=None
            found_before = findInRange(index, 0, -1)
            found_after = findInRange(index+1, dict_key_len, 1)
            found_list.extend(found_before)
            found_list.extend(found_after)
            return found_list
Ejemplo n.º 2
0
        def findListOfCandidates():
            subset = []
            index = cm.binarySearch(key_list, k, key=getItemPart)
            is_found = (index >= 0)
            if not is_found:
                return subset

            found_list = []
            ss = index
            ee = index
            # dd(f'simpleFuzzyTranslate(): start index: [{index}]')
            for i in range(index-1, 0, -1):
                item = key_list[i]
                cond, found_item = validate(item)
                is_break = (cond == -1)
                if is_break:
                    # dd(f'simpleFuzzyTranslate(): traverse backward, stopped at: [{i}], item:[{item}]')
                    break
                is_accepted = (cond == 1)
                if is_accepted:
                    found_list.append(item)
            ss = i
            # dd(f'simpleFuzzyTranslate(): backward to index: [{i}]')
            for i in range(index, len(key_list)):
                item = key_list[i]
                cond, found_item = validate(item)
                is_break = (cond == -1)
                if is_break:
                    # dd(f'simpleFuzzyTranslate(): traverse forward, stopped at: [{i}], item:[{item}]')
                    break
                is_accepted = (cond == 1)
                if is_accepted:
                    found_list.append(item)
            ee = i
            found_list.sort(key=lambda x: len(x), reverse=True)

            for found_item in found_list:
                ratio = fuzz.ratio(found_item, k)
                is_found = (ratio >= df.FUZZY_LOW_ACCEPTABLE_RATIO)
                if not is_found:
                    continue

                entry = (ratio, found_item)
                subset.append(entry)

            subset.sort(reverse=True)
            return subset