import re


def get_fine_type(attributes):
    """ Compute fine-grained mention type.

    Args:
        attributes (dict(str, object)): Attributes of the mention, must contain
            values for "type", "tokens" and "pos".

    Returns:
        str: The fine-grained mention type, one of

            - DEF (definite noun phrase),
            - INDEF (indefinite noun phrase),
            - PERS_NOM (personal pronoun, nominative case),
            - PERS_ACC (personal pronoun, accusative),
            - REFL (reflexive pronoun),
            - POSS (possessive pronoun),
            - POSS_ADJ (possessive adjective) or
            - None.
    """
    coarse_type = attributes["type"]
    start_token = attributes["tokens"][0]
    start_pos = attributes["pos"][0]

    if coarse_type == "NOM":
        if re.match("^(the|this|that|these|those|my|your|his|her|its|our|" +
                    "their)$", start_token.lower()):
            return "DEF"
        elif re.match("^NNP$", start_pos):  # also matches NNPS!
            return "DEF"
        else:
            return "INDEF"
    elif coarse_type == "PRO":
        if re.match("^(i|you|he|she|it|we|they)$", start_token.lower()):
            return "PERS_NOM"
        elif re.match("^(me|you|him|her|it|us|you|them)$",
                      start_token.lower()):
            return "PERS_ACC"
        elif re.match("^(myself|yourself|yourselves|himself|herself|itself|" +
                      "ourselves|themselves)$", start_token.lower()):
            return "REFL"
        elif start_pos == "PRP" and re.match("^(mine|yours|his|hers|its|" +
                                             "ours|theirs|)$",
                                             start_token.lower()):
            return "POSS"
        elif start_pos == "PRP$" and re.match("^(my|your|his|her|its|our|" +
                                              "their)$", start_token.lower()):
            return "POSS_ADJ"