<commit_before># Be able to call directly such as `python test_annotators.py`
try:
    from .context import loctext
except SystemError:  # Parent module '' not loaded, cannot perform relative import
    pass

import pytest
from loctext.util import PRO_ID, LOC_ID, REL_PRO_LOC_ID, repo_path, UNIPROT_NORM_ID, GO_NORM_ID
from loctext.learning.evaluations import relation_equals_uniprot_go, GO_TREE
from nalaf import print_verbose, print_debug


def test_relation_equals_uniprot_go_basic_eq():

    are_equivalent = relation_equals_uniprot_go

    assert are_equivalent(
        "r_5|n_7|xxx|n_8|yyy",
        "r_5|n_7|xxx|n_8|yyy")

    assert are_equivalent(
        "r_5|n_7|xxx|n_8|GO:0000123",
        "r_5|n_7|xxx|n_8|GO:0000123")

    assert are_equivalent(
        "r_5|n_7|P04637|n_8|yyy",
        "r_5|n_7|P04637|n_8|yyy")

    # Note, the following is a stub test relation and does not have to be biologically true
    assert are_equivalent(
        "r_5|n_7|P04637|n_8|GO:0000123",
        "r_5|n_7|P04637|n_8|GO:0000123")


def test_relation_equals_uniprot_go_basic_ne():

    are_equivalent = relation_equals_uniprot_go

    assert not are_equivalent(
        "r_5|n_7|xxx|n_8|yyy",
        "r_5|n_7|xxx_DIFFERENT|n_8|yyy")

    assert not are_equivalent(
        "r_5|n_7|xxx|n_8|yyy",
        "r_5|n_7|xxx|n_8|yyy_DIFERENT")

    assert not are_equivalent(
        "r_5|n_7|xxx|n_8|yyy",
        "r_5|n_7|xxx_DIFFERENT|n_8|yyy_DIFERENT")

    assert not are_equivalent(
        "r_5|n_7|xxx|n_8|yyy",
        "r_DIFFERENT|n_7|xxx|n_8|yyy")


def test_relation_equals_uniprot_go_exceptions():

    are_equivalent = relation_equals_uniprot_go

    with pytest.raises(Exception) as puta:
        assert are_equivalent(
            "",
            "")

    with pytest.raises(Exception):
        assert are_equivalent(
            "r_5|n_7|xxx|n_8|yyy",
            "r_5|n_INVALID|xxx|n_8|yyy")

        assert are_equivalent(
            "r_5|n_7|xxx|n_8|yyy",
            "r_5|n_INVALID|xxx|n_8|yyy")

        assert are_equivalent(
            "r_5|n_7|xxx|n_8|yyy",
            "r_5|n_7|xxx|n_INVALID|yyy")

        assert are_equivalent(
            "r_5|n_INVALID|xxx|n_8|yyy",
            "r_5|n|xxx|n_8|yyy")

        assert are_equivalent(
            "r_5|n_7|xxx|n_INVALID|yyy",
            "r_5|n|xxx|n_8|yyy")


def test_relation_equals_uniprot_go_ORDER_DOES_MATTER():
    # see: http://www.ebi.ac.uk/QuickGO/GTerm?id=GO:0000123#term=ancchart

    # GO:0000123 is a:
    # * direct child of GO:0044451 -- nucleoplasm part
    # * direct child of GO:0031248 -- protein acetyltransferase complex

    are_equivalent = relation_equals_uniprot_go

    assert are_equivalent(
        "r_5|n_7|xxx|n_8|GO:0000123",
        "r_5|n_7|xxx|n_8|GO:0044451")

    assert are_equivalent(
        "r_5|n_7|xxx|n_8|GO:0000123",
        "r_5|n_7|xxx|n_8|GO:0031248")

    # but...

    assert are_equivalent(
        "r_5|n_7|xxx|n_8|GO:0044451",
        "r_5|n_7|xxx|n_8|GO:0000123")
<commit_msg>improve<commit_after># Be able to call directly such as `python test_annotators.py`
try:
    from .context import loctext
except SystemError:  # Parent module '' not loaded, cannot perform relative import
    pass

from pytest import raises
from loctext.util import PRO_ID, LOC_ID, REL_PRO_LOC_ID, repo_path, UNIPROT_NORM_ID, GO_NORM_ID
from loctext.learning.evaluations import relation_equals_uniprot_go, GO_TREE
from nalaf import print_verbose, print_debug


def test_relation_equals_uniprot_go_basic_eq():

    are_equivalent = relation_equals_uniprot_go

    assert are_equivalent(
        "r_5|n_7|xxx|n_8|yyy",
        "r_5|n_7|xxx|n_8|yyy")

    assert are_equivalent(
        "r_5|n_7|xxx|n_8|GO:0000123",
        "r_5|n_7|xxx|n_8|GO:0000123")

    assert are_equivalent(
        "r_5|n_7|P04637|n_8|yyy",
        "r_5|n_7|P04637|n_8|yyy")

    # Note, the following is a stub test relation and does not have to be biologically true
    assert are_equivalent(
        "r_5|n_7|P04637|n_8|GO:0000123",
        "r_5|n_7|P04637|n_8|GO:0000123")


def test_relation_equals_uniprot_go_basic_ne():

    are_equivalent = relation_equals_uniprot_go

    assert not are_equivalent(
        "r_5|n_7|xxx|n_8|yyy",
        "r_5|n_7|xxx_DIFFERENT|n_8|yyy")

    assert not are_equivalent(
        "r_5|n_7|xxx|n_8|yyy",
        "r_5|n_7|xxx|n_8|yyy_DIFERENT")

    assert not are_equivalent(
        "r_5|n_7|xxx|n_8|yyy",
        "r_5|n_7|xxx_DIFFERENT|n_8|yyy_DIFERENT")

    assert not are_equivalent(
        "r_5|n_7|xxx|n_8|yyy",
        "r_DIFFERENT|n_7|xxx|n_8|yyy")


def test_relation_equals_uniprot_go_exceptions():

    are_equivalent = relation_equals_uniprot_go

    with raises(Exception) as puta:
        assert are_equivalent(
            "",
            "")

    with raises(Exception):
        assert are_equivalent(
            "r_5|n_7|xxx|n_8|yyy",
            "r_5|n_INVALID|xxx|n_8|yyy")

    with raises(Exception):
        assert are_equivalent(
            "r_5|n_7|xxx|n_8|yyy",
            "r_5|n_INVALID|xxx|n_8|yyy")

    with raises(Exception):
        assert are_equivalent(
            "r_5|n_7|xxx|n_8|yyy",
            "r_5|n_7|xxx|n_INVALID|yyy")

    with raises(Exception):
        assert are_equivalent(
            "r_5|n_INVALID|xxx|n_8|yyy",
            "r_5|n|xxx|n_8|yyy")

    with raises(Exception):
        assert are_equivalent(
            "r_5|n_7|xxx|n_INVALID|yyy",
            "r_5|n|xxx|n_8|yyy")


def test_relation_equals_uniprot_go_ORDER_DOES_MATTER():
    # see: http://www.ebi.ac.uk/QuickGO/GTerm?id=GO:0000123#term=ancchart

    # GO:0000123 is a:
    # * direct child of GO:0044451 -- nucleoplasm part
    # * direct child of GO:0031248 -- protein acetyltransferase complex

    are_equivalent = relation_equals_uniprot_go

    assert are_equivalent(
        "r_5|n_7|xxx|n_8|GO:0000123",
        "r_5|n_7|xxx|n_8|GO:0044451")

    assert are_equivalent(
        "r_5|n_7|xxx|n_8|GO:0000123",
        "r_5|n_7|xxx|n_8|GO:0031248")

    # but...

    assert are_equivalent(
        "r_5|n_7|xxx|n_8|GO:0044451",
        "r_5|n_7|xxx|n_8|GO:0000123")

{'fraction_non_alphanumeric': 0.11260229132569557, 'fraction_numerical': 0.06743044189852701, 'mean_word_length': 3.205781142463868, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3276811', 'n_tokens_mistral': 2737, 'n_tokens_neox': 2474, 'n_words': 360}