def apply_rule(t_deps, dep_h, rel_rels, overlap_func):
    """
    Checks whether the relations match and the words match according to the specified overlap path.

    :param t_deps: a list of all dependency triples (tuples) in the text
    :parm dep_h: the current (i.e. to be checked) dependency triple (tuple) in the hypothesis
    :param rel_rels: order independent list of two lists containing related relations
                    (e.g. [['nmod'], ['obj', 'nsubj']])
    :param overlap_func: func of the corresponding overlap pattern
    :return: True if a match is found, False otherwise
    """
    # one direction, e.g. H(Y, 'nmod', X) and and T(X, 'obj', Y)
    if dep_h[1] in rel_rels[0]:
        for dep_t in t_deps:
            if dep_t[1] in rel_rels[1] and overlap_func(dep_t, dep_h):
                return True

    # opposite direction, e.g. H(X, 'obj', Y) and and T(Y, 'nmod', X)
    elif dep_h[1] in rel_rels[1]:
        for dep_t in t_deps:
            if dep_t[1] in rel_rels[0] and overlap_func(dep_t, dep_h):
                return True

    else:
        return False