def __build_markable_token_mapper(self, coreference_layer=None,
                                      markable_layer=None):
        """
        Creates mappings from tokens to the markable spans they belong to
        and the coreference chains these markables are part of.

        Returns
        -------
        tok2markables : dict (str -> set of str)
            Maps from a token (node ID) to all the markables (node IDs)
            it is part of.
        markable2toks : dict (str -> list of str)
            Maps from a markable (node ID) to all the tokens (node IDs)
            that belong to it.
        markable2chains : dict (str -> list of int)
            Maps from a markable (node ID) to all the chains (chain ID) it
            belongs to.
        """
        tok2markables = defaultdict(set)
        markable2toks = defaultdict(list)
        markable2chains = defaultdict(list)

        coreference_chains = get_pointing_chains(self.docgraph,
                                                 layer=coreference_layer)
        for chain_id, chain in enumerate(coreference_chains):
            for markable_node_id in chain:
                markable2chains[markable_node_id].append(chain_id)

        # ID of the first singleton (if there are any)
        singleton_id = len(coreference_chains)

        # markable2toks/tok2markables shall contains all markables, not only
        # those which are part of a coreference chain
        for markable_node_id in select_nodes_by_layer(self.docgraph,
                                                      markable_layer):
            span = get_span(self.docgraph, markable_node_id)
            markable2toks[markable_node_id] = span
            for token_node_id in span:
                tok2markables[token_node_id].add(markable_node_id)

            # singletons each represent their own chain (with only one element)
            if markable_node_id not in markable2chains:
                markable2chains[markable_node_id] = [singleton_id]
                singleton_id += 1

        return tok2markables, markable2toks, markable2chains
def __build_markable_token_mapper ( self , coreference_layer = None , markable_layer = None ) : tok2markables = defaultdict ( set ) markable2toks = defaultdict ( list ) markable2chains = defaultdict ( list ) coreference_chains = get_pointing_chains ( self . docgraph , layer = coreference_layer ) for chain_id , chain in enumerate ( coreference_chains ) : for markable_node_id in chain : markable2chains [ markable_node_id ] . append ( chain_id ) singleton_id = len ( coreference_chains ) for markable_node_id in select_nodes_by_layer ( self . docgraph , markable_layer ) : span = get_span ( self . docgraph , markable_node_id ) markable2toks [ markable_node_id ] = span for token_node_id in span : tok2markables [ token_node_id ] . add ( markable_node_id ) if markable_node_id not in markable2chains : markable2chains [ markable_node_id ] = [ singleton_id ] singleton_id += 1 return tok2markables , markable2toks , markable2chains
Creates mappings from tokens to the markable spans they belong to
        and the coreference chains these markables are part of.

        Returns
        -------
        tok2markables : dict (str -> set of str)
            Maps from a token (node ID) to all the markables (node IDs)
            it is part of.
        markable2toks : dict (str -> list of str)
            Maps from a markable (node ID) to all the tokens (node IDs)
            that belong to it.
        markable2chains : dict (str -> list of int)
            Maps from a markable (node ID) to all the chains (chain ID) it
            belongs to.