import string


def build_link_exp_decay(adj, weight, words_map, words, from_index, to_index, max_dist, stopwords, links_to_stopwords=True, self_links=False):
    """
    Builds a link from a given word in the graph to another word at a defined index.
    The farther the other word, the smaller the edge between them.
    In this variant, the weight of the edges decays exponentially with the distance
    """
    words_len = len(words)
    links_made = 0
    while to_index < words_len and (words[to_index] in string.punctuation or (not links_to_stopwords and words[to_index] in stopwords) or (not self_links and words[to_index] == words[from_index])):
        to_index += 1
        weight /= 2

    if (to_index - from_index) <= max_dist and to_index < len(words):
        links_made = 1
        adj[words_map[words[from_index]], words_map[words[to_index]]] = adj[words_map[words[from_index]], words_map[words[to_index]]] + weight
    weight /= 2
    return weight, to_index + 1, links_made