def replace_by_dict(mapping, node_str):
    """
    This function replaces the string by the given replacement rule dict.
    :param mapping: The replacement rule dictionary we have built.
    :param node_str: The target node string to be replaced
    :return: The replaced string
    """

    return ' '.join([(mapping[i] if i in mapping else i)
                     for i in node_str.split(' ')])