def score_by_format_field(resource, score_reasons, log): ''' Looks at the format field of a resource to determine its format and score. It adds strings to score_reasons list about how it came to the conclusion. Return values: * It returns a tuple: (score, format_display_name) * If it cannot work out the format then format_display_name is None * If it cannot score it, then score is None ''' format_field = resource.format or '' if not format_field: score_reasons.append('Format field is blank.') return (None, None) format_ = Formats.by_display_name().get(format_field) or \ Formats.by_extension().get(format_field.lower()) or \ Formats.by_reduced_name().get(Formats.reduce(format_field)) if not format_: score_reasons.append( 'Polje formata "%s" ne odgovara ni jednom poznatom formatu.' % format_field) return (None, None) score = format_['openness'] score_reasons.append('Polje formata "%s" ima ocijenu otvorenosti: %s.' % \ (format_field, score)) return (score, format_['display_name'])
def score_by_format_field(resource, score_reasons, log): ''' Looks at the format field of a resource to determine its format and score. It adds strings to score_reasons list about how it came to the conclusion. Return values: * It returns a tuple: (score, format_display_name) * If it cannot work out the format then format_display_name is None * If it cannot score it, then score is None ''' format_field = resource.format or '' if not format_field: score_reasons.append('Format field is blank.') return (None, None) format_ = Formats.by_display_name().get(format_field) or \ Formats.by_extension().get(format_field.lower()) or \ Formats.by_reduced_name().get(Formats.reduce(format_field)) if not format_: score_reasons.append('Polje formata "%s" ne odgovara ni jednom poznatom formatu.' % format_field) return (None, None) score = format_['openness'] score_reasons.append('Polje formata "%s" ima ocijenu otvorenosti: %s.' % \ (format_field, score)) return (score, format_['display_name'])
def test_reduce(self): assert_equal(Formats.reduce('.XLS '), 'xls')
def test_reduce(self): assert_equal(Formats.reduce(".XLS "), "xls")