<commit_before>import re

from core.tape import Tape, MultiTape
from file_import.exceptions import FormatException, assert_format


class _InputParser:
    def __init__(self, full_str_pattern):
        self.__full_str_pattern = re.compile(full_str_pattern)

    def matches(self, string):
        return self.__full_str_pattern.match(string) is not None

    def _parse_tape_list(self, string):
        raise NotImplementedError('abstract method')

    def parse_tape(self, string, num_of_tapes):
        tapes = self._parse_tape_list(string)
        assert_format(len(tapes) > 0, 'expect tapes to be non empty', string)

        if len(tapes) < num_of_tapes:
            num_of_missing_tapes = num_of_tapes - len(tapes)
            tapes.extend([Tape() for _ in range(num_of_missing_tapes)])

        assert_format(len(tapes) == num_of_tapes, 'number of tapes exceeded', string)
        return MultiTape(tapes) if len(tapes) > 1 else tapes[0]


class _SingleCharInputParser(_InputParser):
    '''
    Eignet sich für Input der nur aus einzelnen Charactern besteht
    Input Strings sind von der Form: char1char2 char1char2
    '''

    def __init__(self):
        super().__init__('([^,;:{}\s]+ )*[^,:;{}\s]+')

    def _parse_tape_list(self, string):
        return [Tape(list(chars)) for chars in string.split(' ')]<commit_msg>Bug beim Eingabe von leeren strings gefixed<commit_after>import re

from core.tape import Tape, MultiTape
from file_import.exceptions import FormatException, assert_format


class _InputParser:
    def __init__(self, full_str_pattern):
        self.__full_str_pattern = re.compile(full_str_pattern)

    def matches(self, string):
        return self.__full_str_pattern.match(string) is not None

    def _parse_tape_list(self, string):
        raise NotImplementedError('abstract method')

    def parse_tape(self, string, num_of_tapes):
        tapes = self._parse_tape_list(string)
        assert_format(len(tapes) > 0, 'expect tapes to be non empty', string)

        if len(tapes) < num_of_tapes:
            num_of_missing_tapes = num_of_tapes - len(tapes)
            tapes.extend([Tape() for _ in range(num_of_missing_tapes)])

        assert_format(len(tapes) == num_of_tapes, 'number of tapes exceeded', string)
        return MultiTape(tapes) if len(tapes) > 1 else tapes[0]


class _SingleCharInputParser(_InputParser):
    '''
    Eignet sich für Input der nur aus einzelnen Charactern besteht
    Input Strings sind von der Form: char1char2 char1char2
    '''

    def __init__(self):
        super().__init__('([^,;:{}\s]+ )*[^,:;{}\s]*')

    def _parse_tape_list(self, string):
        return [Tape(list(chars)) for chars in string.split(' ')]
{'fraction_non_alphanumeric': 0.10631970260223049, 'fraction_numerical': 0.0052044609665427505, 'mean_word_length': 3.663778162911612, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '7514847', 'n_tokens_mistral': 908, 'n_tokens_neox': 871, 'n_words': 216}