コード例 #1
0
def split_explicit_groups(string):
    """return the string split into explicit groups, that is, those either
    between parenthese, square brackets or curly braces, and those separated
    by a dash."""
    result = find_first_level_groups(string, "()")
    result = reduce(lambda l, x: l + find_first_level_groups(x, "[]"), result, [])
    result = reduce(lambda l, x: l + find_first_level_groups(x, "{}"), result, [])
    # do not do this at this moment, it is not strong enough and can break other
    # patterns, such as dates, etc...
    # result = reduce(lambda l, x: l + x.split('-'), result, [])

    return result
コード例 #2
0
def process(mtree):
    """return the string split into explicit groups, that is, those either
    between parenthese, square brackets or curly braces, and those separated
    by a dash."""
    for c in mtree.children:
        groups = find_first_level_groups(c.value, group_delimiters[0])
        for delimiters in group_delimiters:
            flatten = lambda l, x: l + find_first_level_groups(x, delimiters)
            groups = functools.reduce(flatten, groups, [])

        # do not do this at this moment, it is not strong enough and can break other
        # patterns, such as dates, etc...
        #groups = functools.reduce(lambda l, x: l + x.split('-'), groups, [])

        c.split_on_components(groups)
コード例 #3
0
    def process(self, mtree, options=None):
        """split each of those into explicit groups (separated by parentheses or square brackets)

        :return: return the string split into explicit groups, that is, those either
        between parenthese, square brackets or curly braces, and those separated
        by a dash."""
        for c in mtree.unidentified_leaves():
            groups = find_first_level_groups(c.value, group_delimiters[0])
            for delimiters in group_delimiters:
                flatten = lambda l, x: l + find_first_level_groups(x, delimiters)
                groups = reduce(flatten, groups, [])

            # do not do this at this moment, it is not strong enough and can break other
            # patterns, such as dates, etc...
            # groups = functools.reduce(lambda l, x: l + x.split('-'), groups, [])

            c.split_on_components(groups, category='explicit')
コード例 #4
0
    def process(self, mtree, options=None):
        """split each of those into explicit groups (separated by parentheses or square brackets)

        :return: return the string split into explicit groups, that is, those either
        between parenthese, square brackets or curly braces, and those separated
        by a dash."""
        for c in mtree.unidentified_leaves():
            groups = find_first_level_groups(c.value, group_delimiters[0])
            for delimiters in group_delimiters:
                flatten = lambda l, x: l + find_first_level_groups(
                    x, delimiters)
                groups = reduce(flatten, groups, [])

            # do not do this at this moment, it is not strong enough and can break other
            # patterns, such as dates, etc...
            # groups = functools.reduce(lambda l, x: l + x.split('-'), groups, [])

            c.split_on_components(groups, category='explicit')