def gloss(alignments, prefixes=None, postfixes=None, width=None, toksep='<STR_LIT:U+0020>', linesep='<STR_LIT:\n>', groupsep='<STR_LIT:\n>'):
if width is None:<EOL><INDENT>width = terminal.width()<EOL><DEDENT>toksep_len = len(toksep)<EOL>groups = []<EOL>def flush_buffer(line_buffer):<EOL><INDENT>if len(line_buffer) > <NUM_LIT:0>:<EOL><INDENT>lines = [toksep.join(tokens) for tokens in line_buffer]<EOL>if prefixes:<EOL><INDENT>lines = [prefix + line for prefix, line in zip(prefixes, lines)]<EOL><DEDENT>if postfixes:<EOL><INDENT>lines = [line + postfix for postfix, line in zip(postfixes, lines)]<EOL><DEDENT>groups.append(linesep.join(lines))<EOL><DEDENT>return [[] for _ in alignments[<NUM_LIT:0>]]<EOL><DEDENT>line_buffer = flush_buffer([])<EOL>line_buffer_width = <NUM_LIT:0><EOL>for aligned in alignments:<EOL><INDENT>aligned = map(unicode, aligned)<EOL>length = max(map(len, aligned))<EOL>line_buffer_width += toksep_len + length<EOL>if line_buffer_width >= width:<EOL><INDENT>line_buffer = flush_buffer(line_buffer)<EOL>line_buffer_width = length<EOL><DEDENT>for i, token in enumerate(aligned):<EOL><INDENT>line_buffer[i].append(token.ljust(length))<EOL><DEDENT><DEDENT>flush_buffer(line_buffer)<EOL>return groupsep.join(groups)<EOL>
Creates an interlinear gloss (for pairs of tokens/types, POS-tags, labels, etc.)

Take a list of [('a', 'DET'), ('beluga', 'N')] and return a string covering multiples lines, like:
    a   beluga
    DET N
each item in `alignments` should have the same length, N
`prefixes`, if provided, should be N-long
`postfixes`, if provided, should be N-long