<commit_before># -*- coding=utf -*-
"""Logical model."""

import os
import re
import urllib2
import urlparse
import copy
try:
    from collections import OrderedDict
except ImportError:
    from ordereddict import OrderedDict

from cubes.common import SimplifyingDict, get_logger, to_label
from cubes.errors import *

try:
    import json
except ImportError:
    import simplejson as json
__all__ = [
    "load_model",
    "write_model_bundle",
    "create_model",
    "create_cube",
    "create_dimension",
    "create_level",
    "attribute_list",
    "coalesce_attribute",
    "Model",
    "Cube",
    "Dimension",
    "Hierarchy",
    "Level",
    "Attribute",
    "simple_model",
    "split_aggregate_ref",
    "aggregate_ref",

    # TODO: depreciated in favor of generic load_model
    "model_from_path"
]

def _json_from_url(url):
    """Opens `resource` either as a file with `open()`or as URL with
    `urllib2.urlopen()`. Returns opened handle. """

    parts = urlparse.urlparse(url)
    if parts.scheme in ('', 'file'):
        handle = open(url)
    else:
        handle = urllib2.urlopen(url)

    try:
        desc = json.load(handle)
    except ValueError as e:
        raise SyntaxError("Syntaxt error in %s: %s" % (path, e.args))
    finally:
        handle.close()

    return desc


def load_model(resource, translations=None):
    """Load a model from `resource` which can be a filename, URL, file-like
    object or a directory path.

    If a `resource` is a directory it is considered a model bundle and has to
    have the following contents:

    * model.json – main model file
    * dim_*.json - files with dimension defition, one dimension per file<commit_msg>fix wrong variable name<commit_after># -*- coding=utf -*-
"""Logical model."""

import os
import re
import urllib2
import urlparse
import copy
try:
    from collections import OrderedDict
except ImportError:
    from ordereddict import OrderedDict

from cubes.common import SimplifyingDict, get_logger, to_label
from cubes.errors import *

try:
    import json
except ImportError:
    import simplejson as json
__all__ = [
    "load_model",
    "write_model_bundle",
    "create_model",
    "create_cube",
    "create_dimension",
    "create_level",
    "attribute_list",
    "coalesce_attribute",
    "Model",
    "Cube",
    "Dimension",
    "Hierarchy",
    "Level",
    "Attribute",
    "simple_model",
    "split_aggregate_ref",
    "aggregate_ref",

    # TODO: depreciated in favor of generic load_model
    "model_from_path"
]

def _json_from_url(url):
    """Opens `resource` either as a file with `open()`or as URL with
    `urllib2.urlopen()`. Returns opened handle. """

    parts = urlparse.urlparse(url)
    if parts.scheme in ('', 'file'):
        handle = open(url)
    else:
        handle = urllib2.urlopen(url)

    try:
        desc = json.load(handle)
    except ValueError as e:
        raise SyntaxError("Syntax error in %s: %s" % (url, e.args))
    finally:
        handle.close()

    return desc


def load_model(resource, translations=None):
    """Load a model from `resource` which can be a filename, URL, file-like
    object or a directory path.

    If a `resource` is a directory it is considered a model bundle and has to
    have the following contents:

    * model.json – main model file
    * dim_*.json - files with dimension defition, one dimension per file
{'fraction_non_alphanumeric': 0.10336680448907265, 'fraction_numerical': 0.0017720023626698169, 'mean_word_length': 3.1104368932038833, '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': '2827814', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1041, 'n_words': 340}