How to use the konlpy.utils.partition function in konlpy

To help you get started, we’ve selected a few konlpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github konlpy / konlpy / konlpy / tag / _hannanum.py View on Github external
def parse(result, flatten=False, join=False):
    def parse_opt(opt, join=False):
        if join:
            return [u for u in re.findall(tag_re, opt.strip())]
        else:
            return [tuple(u.rsplit('/', 1)) for u in re.findall(tag_re, opt.strip())]

    if not result:
        return []

    elems = result.strip().splitlines()
    index = [i for i, e in enumerate(elems) if not e]
    parts = utils.partition(elems, index)

    if flatten:
        return sum([parse_opt(opt, join=join) for part in parts
                    for opt in list(filter(None, part))[1:]], [])
    else:
        return [[parse_opt(opt, join=join) for opt in list(filter(None, part))[1:]]
                for part in parts]