<commit_before>import logging

from dsmr_parser.clients.telegram_buffer import TelegramBuffer
from dsmr_parser.exceptions import ParseError, InvalidChecksumError
from dsmr_parser.objects import Telegram
from dsmr_parser.parsers import TelegramParser

logger = logging.getLogger(__name__)

class FileReader(object):

    def __init__(self, file, telegram_specification):
        self._file = file
        self.telegram_parser = TelegramParser(telegram_specification)
        self.telegram_buffer = TelegramBuffer()
        self.telegram_specification = telegram_specification

    def read_as_object(self):
        """<commit_msg>add some documentation for the file reader<commit_after>import logging

from dsmr_parser.clients.telegram_buffer import TelegramBuffer
from dsmr_parser.exceptions import ParseError, InvalidChecksumError
from dsmr_parser.objects import Telegram
from dsmr_parser.parsers import TelegramParser

logger = logging.getLogger(__name__)

class FileReader(object):
    """
     Filereader to read and parse raw telegram strings from a file and instantiate Telegram objects
     for each read telegram.
     Usage:
        from dsmr_parser import telegram_specifications
        from dsmr_parser.clients.filereader import FileReader

        if __name__== "__main__":

            infile = '/data/smartmeter/readings.txt'

            file_reader = FileReader(
                file = infile,
                telegram_specification = telegram_specifications.V4
                )

            for telegram in file_reader.read_as_object():
                print(telegram)

     The file can be created like:
        from dsmr_parser import telegram_specifications
        from dsmr_parser.clients import SerialReader, SERIAL_SETTINGS_V5

        if __name__== "__main__":

            outfile = '/data/smartmeter/readings.txt'

            serial_reader = SerialReader(
                device='/dev/ttyUSB0',
                serial_settings=SERIAL_SETTINGS_V5,
                telegram_specification=telegram_specifications.V4
            )

            for telegram in serial_reader.read_as_object():
                f=open(outfile,"ab+")
                f.write(telegram._telegram_data.encode())
                f.close()
     """

    def __init__(self, file, telegram_specification):
        self._file = file
        self.telegram_parser = TelegramParser(telegram_specification)
        self.telegram_buffer = TelegramBuffer()
        self.telegram_specification = telegram_specification

    def read_as_object(self):
        """
{'fraction_non_alphanumeric': 0.06350450803606429, 'fraction_numerical': 0.001960015680125441, 'mean_word_length': 2.8961832061068704, 'pattern_counts': {'":': 2, '<': 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': '7200096', 'n_tokens_mistral': 722, 'n_tokens_neox': 698, 'n_words': 156}