<commit_before>from __future__ import unicode_literals

from dateutil.parser import parse

from .helpers import (
    default_name_parser,
    format_tags,
    oai_extract_url,
    oai_extract_doi,
    oai_process_contributors
)

SKIP = None

BASEXMLSCHEMA = {
    "description": ('//dc:description/node()', lambda x: unicode(x.strip())),
    "contributors": ('//dc:creator/node()', lambda x: default_name_parser(x.split(';'))),
    "title": ('//dc:title/node()', lambda x: unicode(x.strip())),
    "dateUpdated": ('//dc:dateEntry/node()', lambda x: unicode(x.strip())),
    "id": {
        "url": ('//dcq:identifier-citation/node()', lambda x: unicode(x.strip())),
        "serviceID": ('//dc:ostiId/node()', lambda x: unicode(x.strip())),
        "doi": ('//dc:doi/node()', lambda x: unicode(x.strip()))
    },
    "tags": ('//dc:subject/node()', format_tags)
}

OAISCHEMA = {
    "contributors": ('//dc:creator/node()', '//dc:contributor/node()', oai_process_contributors),
    'tags': ('//dc:subject/node()', format_tags),
    'id': {
        'doi': ('//dc:identifier/node()', oai_extract_doi),
        'url': ('//dc:identifier/node()', oai_extract_url),
        'serviceID': '//ns0:header/ns0:identifier/node()'
    },
    'dateUpdated': ('//ns0:header/ns0:datestamp/node()', lambda x: unicode(parse(x).isoformat())),
    'title': ('//dc:title/node()', lambda x: x[0] if isinstance(x, list) else x),
    'description': ('//dc:description/node()', lambda x: x[0] if isinstance(x, list) else x)
}
<commit_msg>Add CONSTANT function, allowing you to define a callable that will return a default value in the transformer<commit_after>from __future__ import unicode_literals

from dateutil.parser import parse

from .helpers import (
    default_name_parser,
    format_tags,
    oai_extract_url,
    oai_extract_doi,
    oai_process_contributors
)

CONSTANT = lambda x: lambda doc: x

BASEXMLSCHEMA = {
    "description": ('//dc:description/node()', lambda x: unicode(x.strip())),
    "contributors": ('//dc:creator/node()', lambda x: default_name_parser(x.split(';'))),
    "title": ('//dc:title/node()', lambda x: unicode(x.strip())),
    "dateUpdated": ('//dc:dateEntry/node()', lambda x: unicode(x.strip())),
    "id": {
        "url": ('//dcq:identifier-citation/node()', lambda x: unicode(x.strip())),
        "serviceID": ('//dc:ostiId/node()', lambda x: unicode(x.strip())),
        "doi": ('//dc:doi/node()', lambda x: unicode(x.strip()))
    },
    "tags": ('//dc:subject/node()', format_tags)
}

OAISCHEMA = {
    "contributors": ('//dc:creator/node()', '//dc:contributor/node()', oai_process_contributors),
    'tags': ('//dc:subject/node()', format_tags),
    'id': {
        'doi': ('//dc:identifier/node()', oai_extract_doi),
        'url': ('//dc:identifier/node()', oai_extract_url),
        'serviceID': '//ns0:header/ns0:identifier/node()'
    },
    'dateUpdated': ('//ns0:header/ns0:datestamp/node()', lambda x: unicode(parse(x).isoformat())),
    'title': ('//dc:title/node()', lambda x: x[0] if isinstance(x, list) else x),
    'description': ('//dc:description/node()', lambda x: x[0] if isinstance(x, list) else x)
}

{'fraction_non_alphanumeric': 0.21865054105665183, 'fraction_numerical': 0.0038192234245703373, 'mean_word_length': 3.9574132492113563, 'pattern_counts': {'":': 20, '<': 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': '1321341', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1101, 'n_words': 221}