<commit_before>__all__ = [
    'cast_data', 'cast_noto_data'
]


from datetime import datetime
import json
import re


DEFAULTS = {
    'widthValue': 100,
    'weightValue': 100}


def cast_data(data, types=None, print_dbg=False):
    """Cast the attributes of parsed glyphs file content."""

    if types is None:
        types = get_type_structure()

    new_data = {}
    for key, cur_type in types.items():
        if key not in data:
            try:
                new_data[key] = DEFAULTS[key]
            except KeyError:
                pass
            continue
        if type(cur_type) == dict:
            new_data[key] = []
            for cur_data in data[key]:
                new_data[key].append(cast_data(cur_data, dict(cur_type)))
            data[key] = [dict(cur_data) for cur_data in data[key] if cur_data]
            if not data[key]:
                del data[key]
        else:
            new_data[key] = cur_type(data[key])
            del data[key]

    if print_dbg:
        print 'not casted in data:', json.dumps(data, indent=2, sort_keys=True)
    return new_data


def cast_noto_data(data):
    """Cast data which is specific to Noto font glyphs files."""

    for param in data['customParameters']:
        if param['name'] == 'openTypeOS2Type':<commit_msg>Don't remove input data during casting phase.<commit_after>__all__ = [
    'cast_data', 'cast_noto_data'
]


from datetime import datetime
import json
import re


DEFAULTS = {
    'widthValue': 100,
    'weightValue': 100}


def cast_data(data, types=None):
    """Cast the attributes of parsed glyphs file content.

    Returns the casted data, so that the type-casting functions used by
    cast_data (which are expected to return a casted value) can themselves call
    cast_data and then return the result."""

    if types is None:
        types = get_type_structure()

    for key, cur_type in types.items():
        if key not in data:
            try:
                data[key] = DEFAULTS[key]
            except KeyError:
                pass
            continue
        if type(cur_type) == dict:
            for cur_data in data[key]:
                cast_data(cur_data, dict(cur_type))
        else:
            data[key] = cur_type(data[key])
    return data


def cast_noto_data(data):
    """Cast data which is specific to Noto font glyphs files."""

    for param in data['customParameters']:
        if param['name'] == 'openTypeOS2Type':
{'fraction_non_alphanumeric': 0.09799918334013884, 'fraction_numerical': 0.006124948958758677, 'mean_word_length': 2.2754010695187166, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1613384', 'n_tokens_mistral': 762, 'n_tokens_neox': 724, 'n_words': 228}