<commit_before># coding=utf-8

import logging


class TagItem(object):
    tag_R = ""
    tag_F = ""
    tag_FF = ""
    tag_FF_index = -1
    tag_R_index = -1

    def __init__(self, sections, item_db):
        super(TagItem, self).__init__()
        self.sections = sections
        self.item_db = item_db
        self.sections_count = len(self.sections)

    def set_tag_FF(self, _tag_FF, x):
        self.tag_FF = _tag_FF
        self.tag_FF_index = x

    def parse_tag_r(self):
        if (self.tag_FF != "") and (self.sections_count == 3):
            if self.tag_FF_index == 2:
                self.tag_R_index = 0
            if self.tag_FF_index == 1:
                self.tag_R_index = 2

        if (self.tag_FF != "") and (self.sections_count == 2):
            logging.debug("no tag_r in the sections, count: {}".format(self.sections_count))
            self.tag_R_index = -1

        if (self.tag_FF == "") and (self.sections_count >= 1):
            logging.debug("special sections, count: {}".format(self.sections_count))
            self.tag_R_index = -1

    def parse_common_tag_item(self):
        for x in xrange(self.sections_count - 1, -1, -1):
            _split = self.sections[x].split(' ')
            _pre_x = x - 1
            if (len(_split) == 2) and (x != 0):
                _tag_FF = self._parse_tagFF(_split, _pre_x)
                if _tag_FF:
                    self.set_tag_FF(_tag_FF, x)
                    break

    def _parse_tagFF(self, _split, pre_index):
        """
        :param self.sections:  section list
        :param _split:     such as "كامري 2016"
        :param pre_index:  if split's index is 3, pre_index is 2
        :param item_db:    database that implements query.
        :return:           the table year's id on the databse
        """
        _pre_section = self.sections[pre_index]
        _pre_split = _pre_section.split(' ')
        if len(_pre_split) != 1:
            return None

        _year_index = self._get_year_index(_split)
        _name_index = 0
        if _year_index == 0:
            _name_index = 1

        _year = _split[_year_index]
        _tag_f_name = _split[_name_index]

        _pre_tag_f_name = _pre_split[0]
        if _tag_f_name != _pre_tag_f_name:
            return ""

        _tags_FF = self.item_db.get_year_id(_year)
        return _tags_FF

    def _get_year_index(self, _split):
        for index, item in enumerate(_split):
            if len(item) == 4 and item.isdigit():
                return index
<commit_msg>charset="utf8mb4",<commit_after># coding=utf-8

import logging


class TagItem(object):
    tag_R = ""
    tag_F = ""
    tag_FF = ""
    tag_FF_index = -1
    tag_R_index = -1

    def __init__(self, sections, item_db):
        super(TagItem, self).__init__()
        self.sections = sections
        self.item_db = item_db
        self.sections_count = len(self.sections)

    def set_tag_FF(self, _tag_FF, x):
        self.tag_FF = _tag_FF
        self.tag_FF_index = x

    def parse_tag_r(self):
        if (self.tag_FF != "") and (self.sections_count == 3):
            # sections: ["2016 xxx","xxx","YYY"]
            if self.tag_FF_index == 2:
                self.tag_R_index = 0
            # sections: ["YYY","2016 xxx","xxx"]
            elif self.tag_FF_index == 1:
                self.tag_R_index = 2

        if (self.tag_FF != "") and (self.sections_count == 2):
            logging.debug("no tag_r in the sections, count: {}".format(self.sections_count))
            self.tag_R_index = -1

        if (self.tag_FF == "") and (self.sections_count >= 1):
            logging.debug("special sections, count: {}".format(self.sections_count))
            self.tag_R_index = -1

    def parse_common_tag_item(self):
        for x in xrange(self.sections_count - 1, -1, -1):
            _split = self.sections[x].split(' ')
            _pre_x = x - 1
            if (len(_split) == 2) and (x != 0):
                _tag_FF = self._parse_tagFF(_split, _pre_x)
                if _tag_FF:
                    self.set_tag_FF(_tag_FF, x)
                    break

    def _parse_tagFF(self, _split, pre_index):
        """
        :param self.sections:  section list
        :param _split:     such as "كامري 2016"
        :param pre_index:  if split's index is 3, pre_index is 2
        :param item_db:    database that implements query.
        :return:           the table year's id on the databse
        """
        _pre_section = self.sections[pre_index]
        _pre_split = _pre_section.split(' ')
        if len(_pre_split) != 1:
            return None

        _year_index = self._get_year_index(_split)
        _name_index = 0
        if _year_index == 0:
            _name_index = 1

        _year = _split[_year_index]
        _tag_f_name = _split[_name_index]

        _pre_tag_f_name = _pre_split[0]
        if _tag_f_name != _pre_tag_f_name:
            return ""

        _tags_FF = self.item_db.get_year_id(_year)
        return _tags_FF

    def _get_year_index(self, _split):
        for index, item in enumerate(_split):
            if len(item) == 4 and item.isdigit():
                return index

{'fraction_non_alphanumeric': 0.10936591041303083, 'fraction_numerical': 0.01357378320729106, 'mean_word_length': 1.8703394546466332, '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': '6074118', 'n_tokens_mistral': 1776, 'n_tokens_neox': 1674, 'n_words': 382}