<commit_before>from __future__ import print_function

import json

from faker import Faker
from faker.config import DEFAULT_LOCALE


def load_file(file_path):
    with open(file_path) as f:
        return json.load(f)


class FakerSchema(object):
    
    def __init__(self, schema, faker=None,locale=DEFAULT_LOCALE):
        self._faker = faker or Faker(locale=locale)
        self._schema = schema
        
    def generate_fake(self, iterations=1):
        result = [self._generate_one_fake() for _ in range(iterations)]
        return result[0] if len(result) == 1 else result

    def _generate_one_fake(self):
        fake_data = {}
        for key, key_type in self._schema.items():
            try:
                fake_data[key] = getattr(self._faker, key_type)()
            except AttributeError:
                raise ValueError('No faker found for key "{0}", which has type "{1}".'
                                 .format(key, key_type))
        return fake_data

    @classmethod
    def from_json_file(cls, json_file, *args, **kwargs):
        try:
            json_data = load_file(json_file)
        except ValueError as e:
            raise ValueError('Given file {0} is not a valid JSON file: {1}'.format(json_file, e))
        else:    
            return cls(json_data, *args, **kwargs)

    @classmethod
    def from_json_string(cls, json_string, *args, **kwargs):
        try:
            json_data = json.loads(json_string)
        except ValueError as e:
            raise ValueError('Given string is not valid JSON: {0}'.format(e))
        else:    
            return cls(json_data, *args, **kwargs)<commit_msg>Allow to provide providers and customized providers<commit_after>from __future__ import print_function

import json

from faker import Faker
from faker.config import DEFAULT_LOCALE


def load_file(file_path):
    with open(file_path) as f:
        return json.load(f)


class FakerSchema(object):
    
    def __init__(self, schema, faker=None, locale=None, providers=None, includes=None):
        self._faker = faker or Faker(locale=locale, providers=providers, includes=includes)
        self._schema = schema
        
    def generate_fake(self, iterations=1):
        result = [self._generate_one_fake() for _ in range(iterations)]
        return result[0] if len(result) == 1 else result

    def _generate_one_fake(self):
        fake_data = {}
        for key, key_type in self._schema.items():
            try:
                fake_data[key] = getattr(self._faker, key_type)()
            except AttributeError:
                raise ValueError('No faker found for key "{}", which has type "{}".'
                                 .format(key, key_type))
        return fake_data

    @classmethod
    def from_json_file(cls, json_file, *args, **kwargs):
        try:
            json_data = load_file(json_file)
        except ValueError as e:
            raise ValueError('Given file {} is not a valid JSON file: {}'.format(json_file, e))
        else:    
            return cls(json_data, *args, **kwargs)

    @classmethod
    def from_json_string(cls, json_string, *args, **kwargs):
        try:
            json_data = json.loads(json_string)
        except ValueError as e:
            raise ValueError('Given string is not valid JSON: {}'.format(e))
        else:    
            return cls(json_data, *args, **kwargs)
{'fraction_non_alphanumeric': 0.09783575452119775, 'fraction_numerical': 0.003261191817373258, 'mean_word_length': 2.387550200803213, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3684644', 'n_tokens_mistral': 990, 'n_tokens_neox': 980, 'n_words': 275}