Did I find the right examples for you? yes no

All Samples(14)  |  Call(14)  |  Derive(0)  |  Import(0)
Determines the case of a list or dictionary of values.
Args:
  - type:    if not == 'string', will return 'n/a'
  - values:  could be either dictionary or list.  If it's a list, then
             it will only examine the keys.
Returns:
  - one of:  'mixed','lower','upper','unknown'
Misc notes:
  - "unknown values" are ignored
  - empty values list/dict results in 'unknown' result(more...)

        def get_case(field_type, values):
    """ Determines the case of a list or dictionary of values.
        Args:
          - type:    if not == 'string', will return 'n/a'
          - values:  could be either dictionary or list.  If it's a list, then
                     it will only examine the keys.
        Returns:
          - one of:  'mixed','lower','upper','unknown'
        Misc notes:
          - "unknown values" are ignored
          - empty values list/dict results in 'unknown' result
        To do:
          - add consistency factor
        Test coverage:
          - complete, via test harness
    """
    freq = collections.defaultdict(int)
    case = None

    if field_type != 'string':
        return 'n/a'

    # count occurances of each case field_type in values:
    for key in values:
        if typer.is_unknown(key):
            freq['unk']    += 1
        elif typer.is_integer(key):     # will be ignoring these
            freq['number'] += 1
        elif typer.is_float(key):       # will be ignoring these
            freq['number'] += 1
        elif key.islower():
            freq['lower'] += 1
        elif key.isupper():
            freq['upper'] += 1
        else:
            freq['mixed'] += 1

    # evaluate frequency distribution:
    if 'mixed' in freq:
        case = 'mixed'
    elif ('lower' in freq and 'upper' not in freq):
        case = 'lower'
    elif ('lower' not in freq and 'upper' in freq):
        case = 'upper'
    elif ('lower' in freq and 'upper' in freq):
        case = 'mixed'
    else:
        case = 'unknown'

    return case
        


src/d/a/datagristle-0.56/gristle/field_determinator.py   datagristle(Download)
 
            if self.field_types[f_no] == 'string':
                self.field_case[f_no]  = miscer.get_case(self.field_types[f_no],
                                                         self.field_freqs[f_no])
                self.field_min_length[f_no]  = miscer.get_min_length(self.field_freqs[f_no])

src/d/a/DataGristle-HEAD/gristle/field_determinator.py   DataGristle(Download)
 
            if self.field_types[f_no] == 'string':
                self.field_case[f_no]  = miscer.get_case(self.field_types[f_no],
                                                         self.field_freqs[f_no])
                self.field_min_length[f_no]  = miscer.get_min_length(self.field_freqs[f_no])

src/d/a/datagristle-0.56/gristle/tests/test_field_misc.py   datagristle(Download)
    def test_misc_a01(self):
        assert mod.get_case('string', self.test_u1) == 'upper'
        assert mod.get_case('string', self.test_u2) == 'upper'
 
        assert mod.get_case('string', self.test_m1) == 'lower'
        assert mod.get_case('string', self.test_m2) == 'mixed'
 
        assert mod.get_case('string', self.test_unk1) == 'unknown'

src/d/a/DataGristle-HEAD/gristle/tests/test_field_misc.py   DataGristle(Download)
    def test_misc_a01(self):
        assert mod.get_case('string', self.test_u1) == 'upper'
        assert mod.get_case('string', self.test_u2) == 'upper'
 
        assert mod.get_case('string', self.test_m1) == 'lower'
        assert mod.get_case('string', self.test_m2) == 'mixed'
 
        assert mod.get_case('string', self.test_unk1) == 'unknown'