<commit_before>from shadho.backend.base.domain import BaseDomain
from shadho.backend.json.value import Value
from shadho.backend.utils import InvalidObjectError

import uuid


class Domain(BaseDomain):
    def __init__(self, id=None, domain=None, path=None, strategy=None,
                 scaling=None, model=None, values=None, exhaustive=False,
                 exhaustive_idx=None):
        self.id = id if id is not None else str(uuid.uuid4())
        self.exhaustive_idx = exhaustive_idx
        if isinstance(domain, dict):
            distribution = getattr(scipy.stats, domain['distribution'])
            self.domain = distribution(*domain['args'],
                                       **domain['kwargs'])
            rng = np.random.RandomState()
            if 'rng' in domain:
                state = domain['rng']
                rng.set_state(tuple([state[0], np.array(state[1]), state[2],
                                     state[3], state[4]]))
            self.domain.random_state = rng
        elif exhaustive and isinstance(domain, list) and exhaustive_idx is None:
            self.domain = domain
            self.exhaustive_idx = 0
        else:
            self.domain = domain

        self.exhaustive = exhaustive

        self.path = path

        self.strategy = strategy if strategy is not None else 'random'
        self.scaling = scaling if scaling is not None else 'linear'

        self.model = model.id if hasattr(model, 'id') else model

        self.values = []
        values = values if values is not None else []
        for value in values:
            self.add_value(value)

    def add_value(self, value):
        if isinstance(value, Value):
            self.values.append(value.id)
        elif isinstance(value, (int, str)):
            self.values.append(value)
        else:
            raise InvalidObjectError(value)

    def to_json(self):
        if hasattr(self.domain, dist):
            domain = {
                'domain': self.domain.dist.name,
                'args': self.domain.args,
                'kwargs': self.domain.kwds,
            }
        else:
            domain = self.domain

        return {
            'domain': domain,
            'path': self.path,<commit_msg>update add_value to match pattern in Model<commit_after>from shadho.backend.base.domain import BaseDomain
from shadho.backend.json.value import Value
from shadho.backend.utils import InvalidObjectError

import uuid

import numpy as np
import scipy.stats


class Domain(BaseDomain):
    def __init__(self, id=None, domain=None, path=None, strategy=None,
                 scaling=None, model=None, values=None, exhaustive=False,
                 exhaustive_idx=None):
        self.id = id if id is not None else str(uuid.uuid4())
        self.exhaustive_idx = exhaustive_idx
        if isinstance(domain, dict):
            distribution = getattr(scipy.stats, domain['distribution'])
            self.domain = distribution(*domain['args'],
                                       **domain['kwargs'])
            rng = np.random.RandomState()
            if 'rng' in domain:
                state = domain['rng']
                rng.set_state(tuple([state[0], np.array(state[1]), state[2],
                                     state[3], state[4]]))
            self.domain.random_state = rng
        elif exhaustive and isinstance(domain, list) and exhaustive_idx is None:
            self.domain = domain
            self.exhaustive_idx = 0
        else:
            self.domain = domain

        self.exhaustive = exhaustive

        self.path = path

        self.strategy = strategy if strategy is not None else 'random'
        self.scaling = scaling if scaling is not None else 'linear'

        self.model = model.id if hasattr(model, 'id') else model

        self.values = []
        values = [values] if not isinstance(values, list) else values
        for value in values:
            self.add_value(value)

    def add_value(self, value):
        if value is not None:
            if isinstance(value, Value):
                self.values.append(value.id)
            elif isinstance(value, (int, str)):
                self.values.append(value)
            else:
                raise InvalidObjectError(value)

    def to_json(self):
        if hasattr(self.domain, dist):
            domain = {
                'domain': self.domain.dist.name,
                'args': self.domain.args,
                'kwargs': self.domain.kwds,
            }
        else:
            domain = self.domain

        return {
            'domain': domain,
            'path': self.path,
{'fraction_non_alphanumeric': 0.09848484848484848, 'fraction_numerical': 0.0030303030303030303, 'mean_word_length': 1.822846670739157, 'pattern_counts': {'":': 0, '<': 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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3686965', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1214, 'n_words': 328}