def _follow_word_from_node(node, word):
    """Follows the link with given word label from given node.

    If there is a link from ``node`` with the label ``word``, returns the end
    node and the log probabilities and transition IDs of the link. If there are
    null links in between, returns the sum of the log probabilities and the
    concatenation of the transition IDs.

    :type node: Lattice.Node
    :param node: node where to start searching

    :type word: str
    :param word: word to search for

    :rtype: tuple of (Lattice.Node, float, float, str)
    :returns: the end node of the link with the word label (or ``None`` if the
              word is not found), and the total acoustic log probability, LM log
              probability, and transition IDs of the path to the word
    """

    if word not in node.word_to_link:
        return (None, None, None, None)

    link = node.word_to_link[word]
    if link.word is not None:
        return (link.end_node,
                link.ac_logprob if link.ac_logprob is not None else 0.0,
                link.lm_logprob if link.lm_logprob is not None else 0.0,
                link.transitions if link.transitions is not None else "")

    end_node, ac_logprob, lm_logprob, transitions = \
        _follow_word_from_node(link.end_node, word)
    if end_node is None:
        return (None, None, None, None)
    else:
        if link.ac_logprob is not None:
            ac_logprob += link.ac_logprob
        if link.lm_logprob is not None:
            lm_logprob += link.lm_logprob
        if link.transitions is not None:
            transitions += link.transitions
        return (end_node, ac_logprob, lm_logprob, transitions)