import re


def get_grammatical_function(attributes):
    """ Compute the grammatical function of a mention in its sentence.

    Args:
        attributes (dict(str, object)): Attributes of the mention, must contain
            a value for "parse_tree".

    Returns:
        str: The grammatical function of the mention in its sentence, one of
        SUBJECT, OBJECT and OTHER.
    """
    tree = attributes["parse_tree"]
    parent = tree.parent()

    if parent is None:
        return "OTHER"
    else:
        parent_label = parent.label()

        if re.match(r"^(S|FRAG)", parent_label):
            return "SUBJECT"
        elif re.match(r"VP", parent_label):
            return "OBJECT"
        else:
            return "OTHER"