def compare_authors(amazon, marc): if len(amazon['authors']) == 0 and 'authors' not in marc: return ('main', 'no authors', 75) if len(amazon['authors']) == 0: return ('main', 'field missing from one record', -25) for name in amazon['authors']: if 'authors' in marc and match_name(name, marc['authors'][0]['name']): return ('main', 'exact match', 125) if 'by_statement' in marc and marc['by_statement'].find(name) != -1: return ('main', 'exact match', 125) if 'authors' not in marc: return ('main', 'field missing from one record', -25) max_score = 0 for a in amazon['authors']: percent, ordered = keyword_match(a[0], marc['authors'][0]['name']) if percent > 0.50: score = percent * 80 if ordered: score += 10 if score > max_score: max_score = score if max_score: return ('main', 'keyword match', max_score) else: return ('main', 'mismatch', -200)
def check(i, j): assert names.match_name(i, j)
def test_names(amazon, marc): assert names.match_name(amazon, marc)