<commit_before>
import pyxnat


def __pyxnat_assessor_type():
    return pyxnat.core.resources.Assessor


def full_label(project_id, subject_id, session_id,
               assessor_label):
    return '-x-'.join([project_id, subject_id, session_id, assessor_label])


# TODO: BenM/assessor_of_assessor/behaviour contingent on assessor version;
# the name shouldn't be used to test this
def full_label_from_assessor(assessor):
    assessor_label = assessor.label()
    if '-x-' in assessor_label:
        return assessor_label

    components = list()
    components.append(assessor_label)
    entity = assessor
    while True:
        entity = entity.parent()
        if entity is None:
            break
        components.append(entity.label())
    return '-x-'.join(reversed(components))


def parse_full_assessor_name(assessor_name):
    elements = assessor_name.split('-x-')

    if len(elements) == 5:
        # relabel is in use so no need to parse
        return assessor_name

    if len(elements) != 4:
        raise ValueError(("'assessor_name' parameter '{}' is not a valid full "
                          "assessor name".format(assessor_name)))
    return dict(zip(
        ['project_id', 'subject_label', 'session_label', 'label'],
        elements))
<commit_msg>Handle old and new assr labels<commit_after>
import pyxnat


def __pyxnat_assessor_type():
    return pyxnat.core.resources.Assessor


def full_label(project_id, subject_id, session_id,
               assessor_label):
    return '-x-'.join([project_id, subject_id, session_id, assessor_label])


# TODO: BenM/assessor_of_assessor/behaviour contingent on assessor version;
# the name shouldn't be used to test this
def full_label_from_assessor(assessor):
    assessor_label = assessor.label()
    if '-x-' in assessor_label:
        return assessor_label

    components = list()
    components.append(assessor_label)
    entity = assessor
    while True:
        entity = entity.parent()
        if entity is None:
            break
        components.append(entity.label())
    return '-x-'.join(reversed(components))


def parse_full_assessor_name(assessor_name):
    elements = assessor_name.split('-x-')
    assrdict = dict()

    if len(elements) == 5:
        # relabel is in use or old style with scan id in label
        assrdict = zip(
            ['project_id', 'subject_label', 'session_label', 'label'],
            [elements[0], elements[1], elements[2], assessor_name])

    if len(elements) != 4:
        raise ValueError(("'assessor_name' parameter '{}' is not a valid full "
                          "assessor name".format(assessor_name)))

    if len(elements[3]) == 36:
        # new style label with uuid
        assrdict = zip(
            ['project_id', 'subject_label', 'session_label', 'label'],
            elements)
    else:
        # old style label
        assrdict = zip(
            ['project_id', 'subject_label', 'session_label', 'label'],
            [elements[0], elements[1], elements[2], assessor_name])

    return assrdict

{'fraction_non_alphanumeric': 0.10855263157894737, 'fraction_numerical': 0.0042763157894736845, 'mean_word_length': 2.8591370558375635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3179202', 'n_tokens_mistral': 962, 'n_tokens_neox': 938, 'n_words': 234}