def counts_html(v): count = {} lens = [len(i) for i, loc in v if i and isinstance(i, six.string_types)] sep = '<br>' if lens and max(lens) > 20 else ' ' for i, loc in v: count.setdefault(i, []).append(loc) s = sorted(count.iteritems(), cmp=lambda x,y: cmp(len(y[1]), len(x[1]) )) s = strip_count(s) return sep.join('<b>%d</b>: <span title="%s">%s</span>' % (len(loc), repr(loc), value if value else '<em>empty</em>') for value, loc in s)
def top_rev_wt(d): d_sorted = sorted(d.keys(), cmp=lambda i, j: cmp(d[j], d[i]) or cmp(len(j), len(i))) return d_sorted[0]
print('editions:', [e['key'] for e in editions]) raise if all(work0 == e['works'][0] for e in editions[1:]): continue wkeys = [] for e in editions: for wkey in e['works']: if wkey not in wkeys: wkeys.append(wkey) works = [] for wkey in wkeys: w = ol.get(wkey) q = {'type': '/type/edition', 'works': wkey, 'limit': 1000} w['number_of_editions'] = len(ol.query(q)) works.append(w) title0 = works[0]['title'].lower() if not all(w['title'].lower() == title0 for w in works[1:]): continue print(ia, ekeys) print(' works:', wkeys) def work_key_int(wkey): return int(re_work_key.match(wkey).group(1)) works = sorted(works, cmp=lambda a,b:-cmp(a['number_of_editions'],b['number_of_editions']) or cmp(work_key_int(a['key']), work_key_int(b['key']))) print(' titles:', [(w['title'], w['number_of_editions']) for w in works]) print(author0) #print [w['authors'][0]['author'] for w in works] assert all(author0 == w['authors'][0]['author'] for w in works) merge_works(works) print()