<commit_before>#-*- encoding: utf-8 -*-
from __future__ import unicode_literals

import base

def matches_any(template, names):
    return any(template.name.matches(n) for n in names)

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 and unicode(template(params[1])) == 'er':
        ret += 'ᵉʳ'
    else:
        ret += 'ᵉ'
    ret += ' siècle'
    if template.name.matches('-s'):
        ret += ' av. J.-C'
    return ret

class SnippetParser(base.SnippetParserBase):
    def strip_template(self, template, normalize, collapse):
        repl = self.handle_common_templates(template, normalize, collapse)
        if repl is not None:
            return repl

        if template.name.matches('unité'):
            return ' '.join(map(unicode, template.params[:2]))
        elif template.name.matches('date'):
            return handle_date(template)
        elif matches_any(template, ('s', '-s', 's-')):
            return handle_s(template)
        elif self.is_citation_needed(template):
            repl = [base.CITATION_NEEDED_MARKER]
            # Keep the text inside the template, but not other parameters<commit_msg>Fix wrong access to template params.<commit_after>#-*- encoding: utf-8 -*-
from __future__ import unicode_literals

import base

def matches_any(template, names):
    return any(template.name.matches(n) for n in names)

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 and unicode(template.params[1]) == 'er':
        ret += 'ᵉʳ'
    else:
        ret += 'ᵉ'
    ret += ' siècle'
    if template.name.matches('-s'):
        ret += ' av. J.-C'
    return ret

class SnippetParser(base.SnippetParserBase):
    def strip_template(self, template, normalize, collapse):
        repl = self.handle_common_templates(template, normalize, collapse)
        if repl is not None:
            return repl

        if template.name.matches('unité'):
            return ' '.join(map(unicode, template.params[:2]))
        elif template.name.matches('date'):
            return handle_date(template)
        elif matches_any(template, ('s', '-s', 's-')):
            return handle_s(template)
        elif self.is_citation_needed(template):
            repl = [base.CITATION_NEEDED_MARKER]
            # Keep the text inside the template, but not other parameters
{'fraction_non_alphanumeric': 0.13192771084337349, 'fraction_numerical': 0.005421686746987952, 'mean_word_length': 2.4957894736842103, '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': '2601400', 'n_tokens_mistral': 1004, 'n_tokens_neox': 983, 'n_words': 252}