returns a list of chained pointing relations (e.g. coreference chains)
    found in the given document graph.

    Parameters
    ----------
    docgraph : DiscourseDocumentGraph
        a text with annotations, represented by a document graph
    layer : str or None
        If layer is specifid, this function will only return pointing relations
        belonging to that layer.

def get_pointing_chains(docgraph, layer=None):
    """
    returns a list of chained pointing relations (e.g. coreference chains)
    found in the given document graph.

    Parameters
    ----------
    docgraph : DiscourseDocumentGraph
        a text with annotations, represented by a document graph
    layer : str or None
        If layer is specifid, this function will only return pointing relations
        belonging to that layer.
    """
    pointing_relations = select_edges_by(docgraph, layer=layer,
                                         edge_type=EdgeTypes.pointing_relation)

    # a markable can point to more than one antecedent, cf. Issue #40
    rel_dict = defaultdict(set)
    for src_id, target_id in pointing_relations:
        rel_dict[src_id].add(target_id)

    all_chains = [__walk_chain(rel_dict, src_id)
                  for src_id in rel_dict.iterkeys()]

    # don't return partial chains, i.e. instead of returning [a,b], [b,c] and
    # [a,b,c,d], just return [a,b,c,d]
    unique_chains = []
    for i, src_id_chains in enumerate(all_chains):
        # there will be at least one chain in this list and
        # its first element is the from ID
        src_id = src_id_chains[0][0]

        # chain lists not starting with src_id
        other_chainlists = all_chains[:i] + all_chains[i+1:]
        if not any((src_id in chain
                    for chain_list in other_chainlists
                    for chain in chain_list)):
                        unique_chains.extend(src_id_chains)
    return unique_chains