def gen_bracketed_output(docgraph, layer='mmax'):
    '''

    TODO: the order of the opening brackets should be determined (e.g. if
    a token marks the beginning of two markables, we could check if the
    first markable subsumes the second markable or vice versa.)

    Example
    -------
    Die Diskussion , wie teuer [die neue [Wittstocker]_{markable_22}
    Stadthalle]_{markable_21} für Vereine und Veranstalter wird , hat
    einige Zeit in Anspruch genommen .
    Die Betriebskosten [für den schmucken Veranstaltungsort]_{markable_21}
    sind hoch . Jetzt wird es darum gehen , [die Halle]_{markable_21} so oft
    wie möglich zu füllen .
    Und [in der Region]_{markable_22} gibt es Konkurrenz .

    Parameters
    ----------
    layer : str or None
        The layer from which the pointing chains/relations
        (i.e. coreference relations) should be extracted.
        If no layer is selected, all pointing relations will be considered.
        (This might lead to errors, e.g. when the document contains Tiger
        syntax trees with secondary edges.)
    '''
    opening, closing, markable2chain = gen_bracket_mappings(docgraph, layer=layer)

    ret_str = u''
    stack = []
    for token_id in docgraph.tokens:
        token_str = docgraph.get_token(token_id)
        if token_id in opening:
            num_of_opening_brackets = len(opening[token_id])
            stack.extend(opening[token_id])
            opening_str = u'[' * num_of_opening_brackets

            if token_id in closing:
                # token is both the first and last element of 1+ markables
                closing_str = gen_closing_string(closing, markable2chain,
                                                 token_id, stack)
                ret_str += u'{0}{1}{2} '.format(opening_str, token_str,
                                                closing_str)
            else: # token is the first element of 1+ markables
                ret_str += u'{0}{1} '.format(opening_str, token_str)
        elif token_id in closing:
            closing_str = gen_closing_string(closing, markable2chain,
                                             token_id, stack)
            ret_str += u'{0}{1} '.format(token_str, closing_str)
        else:
            ret_str += u'{} '.format(token_str)
    return ret_str
def gen_bracketed_output ( docgraph , layer = 'mmax' ) : opening , closing , markable2chain = gen_bracket_mappings ( docgraph , layer = layer ) ret_str = u'' stack = [ ] for token_id in docgraph . tokens : token_str = docgraph . get_token ( token_id ) if token_id in opening : num_of_opening_brackets = len ( opening [ token_id ] ) stack . extend ( opening [ token_id ] ) opening_str = u'[' * num_of_opening_brackets if token_id in closing : closing_str = gen_closing_string ( closing , markable2chain , token_id , stack ) ret_str += u'{0}{1}{2} ' . format ( opening_str , token_str , closing_str ) else : ret_str += u'{0}{1} ' . format ( opening_str , token_str ) elif token_id in closing : closing_str = gen_closing_string ( closing , markable2chain , token_id , stack ) ret_str += u'{0}{1} ' . format ( token_str , closing_str ) else : ret_str += u'{} ' . format ( token_str ) return ret_str
TODO: the order of the opening brackets should be determined (e.g. if
    a token marks the beginning of two markables, we could check if the
    first markable subsumes the second markable or vice versa.)

    Example
    -------
    Die Diskussion , wie teuer [die neue [Wittstocker]_{markable_22}
    Stadthalle]_{markable_21} für Vereine und Veranstalter wird , hat
    einige Zeit in Anspruch genommen .
    Die Betriebskosten [für den schmucken Veranstaltungsort]_{markable_21}
    sind hoch . Jetzt wird es darum gehen , [die Halle]_{markable_21} so oft
    wie möglich zu füllen .
    Und [in der Region]_{markable_22} gibt es Konkurrenz .

    Parameters
    ----------
    layer : str or None
        The layer from which the pointing chains/relations
        (i.e. coreference relations) should be extracted.
        If no layer is selected, all pointing relations will be considered.
        (This might lead to errors, e.g. when the document contains Tiger
        syntax trees with secondary edges.)