def expected(input_string, context): """ Expected property functional pattern. :param input_string: :type input_string: :param context: :type context: :return: :rtype: """ ret = [] for search in context.get(context_key): if search.startswith('re:'): search = search[3:] search = search.replace(' ', '-') matches = Rebulk().regex(search, abbreviations=[dash], flags=re.IGNORECASE) \ .matches(input_string, context) for match in matches: ret.append(match.span) else: value = search for sep in seps: input_string = input_string.replace(sep, ' ') search = search.replace(sep, ' ') for start in find_all(input_string, search, ignore_case=True): ret.append({'start': start, 'end': start + len(search), 'value': value}) return ret
def expected_title(input_string, context): """ Expected title functional pattern. :param input_string: :type input_string: :param context: :type context: :return: :rtype: """ ret = [] for search in context.get('expected_title'): if search.startswith('re:'): search = search[3:] search = search.replace(' ', '-') matches = RePattern(search, abbreviations=[dash], flags=re.IGNORECASE).matches( input_string, context) for match in matches: ret.append(match.span) else: for start in find_all(input_string, search, ignore_case=True): ret.append((start, start + len(search))) return ret
def mark_path(input_string, context): """ Functional pattern to mark path elements. :param input_string: :return: """ ret = [] if context.get('name_only', False): ret.append((0, len(input_string))) else: indices = list(find_all(input_string, '/')) indices += list(find_all(input_string, '\\')) indices += [-1, len(input_string)] indices.sort() for i in range(0, len(indices) - 1): ret.append((indices[i] + 1, indices[i + 1])) return ret
def expected_title(input_string, context): """ Expected title functional pattern. :param input_string: :type input_string: :param context: :type context: :return: :rtype: """ ret = [] for search in context.get('expected_title'): if search.startswith('re:'): search = search[3:] search = search.replace(' ', '-') matches = RePattern(search, abbreviations=[dash], flags=re.IGNORECASE).matches(input_string, context) for match in matches: ret.append(match.span) else: for start in find_all(input_string, search, ignore_case=True): ret.append((start, start+len(search))) return ret