<commit_before># encoding: utf-8

"""
.. codeauthor:: <NAME> <<EMAIL>>
"""

from __future__ import absolute_import, unicode_literals

import pathvalidate
import typepy
from six.moves import zip

from ._csv import CsvTableWriter


class LtsvTableWriter(CsvTableWriter):
    """
    A table writer class for
    `Labeled Tab-separated Values (LTSV) <http://ltsv.org/>`__ format.
    """

    @property
    def format_name(self):
        return "ltsv"

    @property
    def support_split_write(self):
        return True

    def __init__(self):
        super(LtsvTableWriter, self).__init__()

        self.is_write_header = False

        self._is_require_header = True

    def write_table(self):
        """
        |write_table| with
        `Labeled Tab-separated Values (LTSV) <http://ltsv.org/>`__ format.
        Invalid characters in labels/data are removed.

        :raises pytablewriter.EmptyHeaderError: If the |header_list| is empty.
        :Example:
            :ref:`example-ltsv-table-writer`
        """

        with self._logger:
            self._verify_property()
            self._preprocess()

            for value_list in self._table_value_matrix:
                ltsv_item_list = [
                    "{:s}:{}".format(pathvalidate.sanitize_ltsv_label(header_name), value)
                    for header_name, value in zip(self.header_list, value_list)
                    if typepy.is_not_null_string(value)
                ]

                if typepy.is_empty_sequence(ltsv_item_list):
                    continue

                self.stream.write("\t".join(ltsv_item_list) + "\n")<commit_msg>Refactoring: to use a common base method<commit_after># encoding: utf-8

"""
.. codeauthor:: <NAME> <<EMAIL>>
"""

from __future__ import absolute_import, unicode_literals

import pathvalidate
import typepy
from six.moves import zip

from ._csv import CsvTableWriter


class LtsvTableWriter(CsvTableWriter):
    """
    A table writer class for
    `Labeled Tab-separated Values (LTSV) <http://ltsv.org/>`__ format.
    """

    @property
    def format_name(self):
        return "ltsv"

    @property
    def support_split_write(self):
        return True

    def __init__(self):
        super(LtsvTableWriter, self).__init__()

        self.is_write_header = False

        self._is_require_header = True

    def write_table(self):
        """
        |write_table| with
        `Labeled Tab-separated Values (LTSV) <http://ltsv.org/>`__ format.
        Invalid characters in labels/data are removed.

        :raises pytablewriter.EmptyHeaderError: If the |header_list| is empty.
        :Example:
            :ref:`example-ltsv-table-writer`
        """

        with self._logger:
            self._verify_property()
            self._preprocess()

            for value_list in self._table_value_matrix:
                ltsv_item_list = [
                    "{:s}:{}".format(pathvalidate.sanitize_ltsv_label(header_name), value)
                    for header_name, value in zip(self.header_list, value_list)
                    if typepy.is_not_null_string(value)
                ]

                if typepy.is_empty_sequence(ltsv_item_list):
                    continue

                self._write_line("\t".join(ltsv_item_list))
{'fraction_non_alphanumeric': 0.09972468644845518, 'fraction_numerical': 0.000611807892321811, 'mean_word_length': 2.2027424094025467, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '4201877', 'n_tokens_mistral': 1018, 'n_tokens_neox': 973, 'n_words': 210}