<commit_before>#!python
# coding=utf-8

from pyaxiom.urn import IoosUrn
from pyaxiom import logger

class DotDict(object):
    def __init__(self, *args, **kwargs):
        for k, v in kwargs.items():
            setattr(self, k, v)

    def __repr__(self):
        import pprint
        return pprint.pformat(vars(self), indent=2)


def urnify(naming_authority, station_identifier, data_variable):
    extras = []

    if hasattr(data_variable, 'cell_methods') and data_variable.cell_methods:
        split_cms = data_variable.cell_methods.split(":")
        cms = [ "{0}:{1}".format(c[0].strip(), c[1].strip()) for c in zip(split_cms[0::2], split_cms[1::2]) ]
        extras.append('cell_methods={0}'.format(','.join(cms)))

    if hasattr(data_variable, 'bounds') and data_variable.bounds:
        extras.append('bounds={0}'.format(data_variable.bounds))

    if hasattr(data_variable, 'vertical_datum') and data_variable.vertical_datum:
        extras.append('vertical_datum={0}'.format(data_variable.vertical_datum))

    variable_name = data_variable.name
    if hasattr(data_variable, 'standard_name') and data_variable.standard_name:
        variable_name = data_variable.standard_name

    if extras:
        variable_name = '{0}#{1}'.format(variable_name, ';'.join(extras))

    u = IoosUrn(asset_type='sensor',
                authority=naming_authority,
                label=station_identifier,
                component=variable_name,
                version=None)
    return u.urn<commit_msg>Come up with a random variable name if we can't find one when creating URN.<commit_after>#!python
# coding=utf-8

import random
import string

from pyaxiom.urn import IoosUrn
from pyaxiom import logger


class DotDict(object):
    def __init__(self, *args, **kwargs):
        for k, v in kwargs.items():
            setattr(self, k, v)

    def __repr__(self):
        import pprint
        return pprint.pformat(vars(self), indent=2)


def urnify(naming_authority, station_identifier, data_variable):
    extras = []

    if hasattr(data_variable, 'cell_methods') and data_variable.cell_methods:
        split_cms = data_variable.cell_methods.split(":")
        cms = [ "{0}:{1}".format(c[0].strip(), c[1].strip()) for c in zip(split_cms[0::2], split_cms[1::2]) ]
        extras.append('cell_methods={0}'.format(','.join(cms)))

    if hasattr(data_variable, 'bounds') and data_variable.bounds:
        extras.append('bounds={0}'.format(data_variable.bounds))

    if hasattr(data_variable, 'vertical_datum') and data_variable.vertical_datum:
        extras.append('vertical_datum={0}'.format(data_variable.vertical_datum))

    if hasattr(data_variable, 'standard_name') and data_variable.standard_name:
        variable_name = data_variable.standard_name
    elif hasattr(data_variable, 'name'):
        variable_name = getattr(data_variable, 'name')
    else:
        variable_name = ''.join(random.choice(string.ascii_uppercase) for _ in range(8)).lower()
        logger.warning("Had to randomly generate a variable name: {0}".format(variable_name))

    if extras:
        variable_name = '{0}#{1}'.format(variable_name, ';'.join(extras))

    u = IoosUrn(asset_type='sensor',
                authority=naming_authority,
                label=station_identifier,
                component=variable_name,
                version=None)
    return u.urn
{'fraction_non_alphanumeric': 0.12879238548483046, 'fraction_numerical': 0.009518143961927425, 'mean_word_length': 3.5262449528936743, 'pattern_counts': {'":': 2, '<': 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': '3575435', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1059, 'n_words': 207}