<commit_before>#-*- encoding: utf-8 -*-

import base

def handle_date(template):
    year = None
    if len(template.params) >= 3:
        try:
            year = int(unicode(template.params[2]))
        except ValueError:
            pass
    if isinstance(year, int):
        # assume {{date|d|m|y|...}}
        return ' '.join(map(unicode, template.params[:3]))
    else:
        # assume {{date|d m y|...}}
        return unicode(template.params[0])

def handle_s(template):
    ret = unicode(template.params[0])
    if len(template.params) == 2:
        ret += unicode(template.params[1])
    if template.name.matches('-s'):
        ret += ' av. J.-C'
    return ret

class SnippetParser(base.SnippetParserBase):
    def strip_template(self, template, normalize, collapse):
        if template.name.matches('unité'):
            return ' '.join(map(unicode, template.params[:2]))
        elif template.name.matches('date'):
            return handle_date(template)
        elif template.name.matches('s') or template.name.matches('-s'):
            return handle_s(template)
        elif self.is_citation_needed(template):
            repl = [base.CITATION_NEEDED_MARKER]
            if template.params:
                repl = [template.params[0].value.strip_code()] + repl
            return ''.join(repl)
        return ''<commit_msg>Don't assume parameters in templates.<commit_after>#-*- encoding: utf-8 -*-

import base

def handle_date(template):
    year = None
    if len(template.params) >= 3:
        try:
            year = int(unicode(template.params[2]))
        except ValueError:
            pass
    if isinstance(year, int):
        # assume {{date|d|m|y|...}}
        return ' '.join(map(unicode, template.params[:3]))
    elif template.params:
        # assume {{date|d m y|...}}
        return unicode(template.params[0])
    return ''

def handle_s(template):
    if not template.params:
        return ''
    ret = unicode(template.params[0])
    if len(template.params) == 2:
        ret += unicode(template.params[1])
    if template.name.matches('-s'):
        ret += ' av. J.-C'
    return ret

class SnippetParser(base.SnippetParserBase):
    def strip_template(self, template, normalize, collapse):
        if template.name.matches('unité'):
            return ' '.join(map(unicode, template.params[:2]))
        elif template.name.matches('date'):
            return handle_date(template)
        elif template.name.matches('s') or template.name.matches('-s'):
            return handle_s(template)
        elif self.is_citation_needed(template):
            repl = [base.CITATION_NEEDED_MARKER]
            if template.params:
                repl = [template.params[0].value.strip_code()] + repl
            return ''.join(repl)
        return ''
{'fraction_non_alphanumeric': 0.1434219985621855, 'fraction_numerical': 0.007189072609633357, 'mean_word_length': 2.353012048192771, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '194476', 'n_tokens_mistral': 836, 'n_tokens_neox': 816, 'n_words': 176}