<commit_before>'''
File: generate_indexes.py
Author: <NAME>
Description: A generator to create all possible indexes from a pattern.
'''
import re
from dmrg_helpers.core.dmrg_exceptions import DMRGException

class SiteFilter(object):
    """A class to filter out integers according to a pattern.

    You construct this class using a string with some index specification,
    such as `2*i+1` to filter out even numbers, or `1` to get out only index
    labeled by 1.

    You use this class in the generator.

    Attributes
    ----------
    pattern: a regex with the pattern accepted filters should have.
        Basically, filters can have a mute index, 'i', which may be multiplied
        by an integer and can have a positive or negative constant added.

    Example
    -------
    >>> from dmrg_helpers.extract.generate_indexes import SiteFilter
    >>> site_filter = SiteFilter('2*i+1')
    >>> print [site_filter.a, site_filter.i, site_filter.pm, site_filter.b]
    ['2', 'i', '+', '1']
    >>> site_filter = SiteFilter('i-1')
    >>> print [site_filter.a, site_filter.i, site_filter.pm, site_filter.b]
    [None', 'i', '-', '1']
    """

    pattern = r"([0-9]+)\*?([a-z])[([\+|\-])([0-9]+)]?"

    def __init__(self, string):
        """
        Parameters
        ----------
        string: a string.
            The filter you want to apply to the sites of the chain.
        """
        super(SiteFilter, self).__init__()
        match = re.search(SiteFilter.pattern, string)
        if not match:
            raise DMRGException('Not match in site filter')

        self.a = match(0)
        self.i = match(1)
        self.pm = match(2)
        self.b = match(3)

        if self.is_index_not_ok():
            raise DMRGException('Bad expression for site indexes')

    def is_index_not_ok(self):
        """Checks whether an index is right.
        """
        not_ok = (self.pm is None and self.b is not None) or (self.i is None
                and self.pm is not None)
        return not_ok

    def is_constant(self):
        '''Checks whether the expression is just a constant.
        '''<commit_msg>Fixing the pattern and a bug.<commit_after>'''
File: generate_indexes.py
Author: <NAME>
Description: A generator to create all possible indexes from a pattern.
'''
import re
from dmrg_helpers.core.dmrg_exceptions import DMRGException

class SiteFilter(object):
    """A class to filter out integers according to a pattern.

    You construct this class using a string with some index specification,
    such as `2*i+1` to filter out even numbers, or `1` to get out only index
    labeled by 1.

    You use this class in the generator.

    Attributes
    ----------
    pattern: a regex with the pattern accepted filters should have.
        Basically, filters can have a mute index, 'i', which may be multiplied
        by an integer and can have a positive or negative constant added.

    Example
    -------
    >>> from dmrg_helpers.extract.generate_indexes import SiteFilter
    >>> site_filter = SiteFilter('2*i+1')
    >>> print [site_filter.a, site_filter.i, site_filter.pm, site_filter.b]
    ['2', 'i', '+', '1']
    >>> site_filter = SiteFilter('i-1')
    >>> print [site_filter.a, site_filter.i, site_filter.pm, site_filter.b]
    [None, 'i', '-', '1']
    """

    pattern = r"([0-9]+)?\*?([a-z])?([\+|\-])?([0-9]+)?"

    def __init__(self, string):
        """
        Parameters
        ----------
        string: a string.
            The filter you want to apply to the sites of the chain.
        """
        super(SiteFilter, self).__init__()
        match = re.search(SiteFilter.pattern, string)
        if not match:
            raise DMRGException('Not match in site filter')

        self.a = match.group(1)
        self.i = match.group(2)
        self.pm = match.group(3)
        self.b = match.group(4)

        if self.is_index_not_ok():
            raise DMRGException('Bad expression for site indexes')

    def is_index_not_ok(self):
        """Checks whether an index is right.
        """
        not_ok = (self.pm is None and self.b is not None) or (self.i is None
                and self.pm is not None)
        return not_ok

    def is_constant(self):
        '''Checks whether the expression is just a constant.
        '''
{'fraction_non_alphanumeric': 0.12529164722351843, 'fraction_numerical': 0.008399440037330844, 'mean_word_length': 2.35708692247455, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '6425845', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1260, 'n_words': 443}