<commit_before>#!/usr/bin/env python

'''
@package pyon.ion.granule.record_dictionary
@file pyon/ion/granule/record_dictionary
@author <NAME>
@author <NAME>
@brief https://confluence.oceanobservatories.org/display/CIDev/R2+Construction+Data+Model
'''

import StringIO
from pyon.ion.granule.taxonomy import TaxyTool, Taxonomy
from pyon.util.log import log
import numpy

_NoneType = type(None)
class RecordDictionaryTool(object):
    """
    A granule is a unit of information which conveys part of a coverage. It is composed of a taxonomy and a nested
    structure of record dictionaries.

    The record dictionary is composed of named value sequences and other nested record dictionaries.

    The fact that all of the keys in the record dictionary are handles mapped by the taxonomy should never be exposed.
    The application user refers to everything in the record dictionary by the unique nick name from the taxonomy.

    """
    def __init__(self,taxonomy, shape=None):
        """
        @brief Initialize a new instance of Record Dictionary Tool with a taxonomy and an optional fixed length
        @param taxonomy is an instance of a TaxonomyTool or Taxonomy (IonObject) used in this record dictionary
        @param length is an optional fixed length for the value sequences of this record dictionary
        """
        if not isinstance(shape, (_NoneType, int, tuple)):
            raise TypeError('Invalid shape argument, received type "%s"; should be None or int or tuple' % type(shape))


        self._rd = {}
        self._shp = shape

        if isinstance(self._shp, int):
            self._shp = (self._shp,)

        # hold onto the taxonomy - we need it to build the granule...

        if isinstance(taxonomy, TaxyTool):
            self._tx = taxonomy
        elif isinstance(taxonomy, Taxonomy):
            self._tx = TaxyTool(taxonomy)
        else:
            raise TypeError('Invalid taxonomy argument, received type "%s"; should be Taxonomy or TaxyTool' % type(taxonomy))

    @classmethod
    def load_from_granule(cls, g):
        """
        @brief return an instance of Record Dictionary Tool from a granule. Used when a granule is received in a message
        """
        result = cls(TaxyTool(g.taxonomy))
        result._rd = g.record_dictionary
        return result
<commit_msg>Luke: fixes shape bug with rdt<commit_after>#!/usr/bin/env python

'''
@package pyon.ion.granule.record_dictionary
@file pyon/ion/granule/record_dictionary
@author <NAME>
@author <NAME>
@brief https://confluence.oceanobservatories.org/display/CIDev/R2+Construction+Data+Model
'''

import StringIO
from pyon.ion.granule.taxonomy import TaxyTool, Taxonomy
from pyon.util.log import log
import numpy

_NoneType = type(None)
class RecordDictionaryTool(object):
    """
    A granule is a unit of information which conveys part of a coverage. It is composed of a taxonomy and a nested
    structure of record dictionaries.

    The record dictionary is composed of named value sequences and other nested record dictionaries.

    The fact that all of the keys in the record dictionary are handles mapped by the taxonomy should never be exposed.
    The application user refers to everything in the record dictionary by the unique nick name from the taxonomy.

    """
    def __init__(self,taxonomy, shape=None):
        """
        @brief Initialize a new instance of Record Dictionary Tool with a taxonomy and an optional fixed length
        @param taxonomy is an instance of a TaxonomyTool or Taxonomy (IonObject) used in this record dictionary
        @param length is an optional fixed length for the value sequences of this record dictionary
        """
        if not isinstance(shape, (_NoneType, int, tuple)):
            raise TypeError('Invalid shape argument, received type "%s"; should be None or int or tuple' % type(shape))


        self._rd = {}
        self._shp = shape

        if isinstance(self._shp, int):
            self._shp = (self._shp,)

        # hold onto the taxonomy - we need it to build the granule...

        if isinstance(taxonomy, TaxyTool):
            self._tx = taxonomy
        elif isinstance(taxonomy, Taxonomy):
            self._tx = TaxyTool(taxonomy)
        else:
            raise TypeError('Invalid taxonomy argument, received type "%s"; should be Taxonomy or TaxyTool' % type(taxonomy))

    @classmethod
    def load_from_granule(cls, g):
        """
        @brief return an instance of Record Dictionary Tool from a granule. Used when a granule is received in a message
        """
        result = cls(TaxyTool(g.taxonomy))
        result._rd = g.record_dictionary
        if result._rd.has_key(0):
            result._shp = result._rd[0].shape
        return result

{'fraction_non_alphanumeric': 0.07463630613535736, 'fraction_numerical': 0.000843348091924942, 'mean_word_length': 2.9731993299832498, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '4424669', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1240, 'n_words': 515}