Beispiel #1
0
def merge_authors(ol, keys, debug=False):
    #    print 'merge author %s:"%s" and %s:"%s"' % (author['key'], author['name'], merge_with['key'], merge_with['name'])
    #    print 'becomes: "%s"' % repr(new_name)
    authors = [
        a for a in (withKey(k) for k in keys)
        if a['type']['key'] != '/type/redirect'
    ]
    not_redirect = set(a['key'] for a in authors)
    if debug:
        for a in authors:
            print(a)

    assert all(a['type']['key'] == '/type/author' for a in authors)
    name1 = authors[0]['name']
    for a in authors:
        print(repr(a['key'], a['name']))
    assert all(match_with_bad_chars(a['name'], name1) for a in authors[1:])

    best_key = pick_best_author(authors)['key']

    imgs = [
        a['key'] for a in authors
        if a['key'] != '/a/OL2688880A' and has_image(a['key'])
    ]
    if len(imgs) == 1:
        new_key = imgs[0]
    else:
        new_key = "/a/OL%dA" % min(key_int(a) for a in authors)
        # Molière and O. J. O. Ferreira
        if len(imgs) != 0:
            print('imgs:', imgs)
            return  # skip
        if not (imgs == [u'/a/OL21848A', u'/a/OL4280680A'] \
                or imgs == [u'/a/OL325189A', u'/a/OL266422A'] \
                or imgs == [u'/a/OL5160945A', u'/a/OL5776228A']):
            print(imgs)
            assert len(imgs) == 0

    print(new_key)
    print(best_key)

    do_normalize(new_key, best_key, authors)
    old_keys = set(k for k in keys if k != new_key)
    print('old keys:', old_keys)

    for old in old_keys:
        # /b/OL21291659M
        switch_author(ol, old, new_key, old_keys, debug=True)
        if old in not_redirect:
            make_redirect(ol, old, new_key)
        q = {
            'authors': old,
            'type': '/type/edition',
        }
        if list(get_things(q)) != []:
            switch_author(ol, old, new_key, old_keys, debug=True)
Beispiel #2
0
def merge_authors(ol, keys, debug=False):
#    print 'merge author %s:"%s" and %s:"%s"' % (author['key'], author['name'], merge_with['key'], merge_with['name'])
#    print 'becomes: "%s"' % repr(new_name)
    authors = [a for a in (withKey(k) for k in keys) if a['type']['key'] != '/type/redirect']
    not_redirect = set(a['key'] for a in authors)
    if debug:
        for a in authors:
            print(a)

    assert all(a['type']['key'] == '/type/author' for a in authors)
    name1 = authors[0]['name']
    for a in authors:
        print(repr(a['key'], a['name']))
    assert all(match_with_bad_chars(a['name'], name1) for a in authors[1:])

    best_key = pick_best_author(authors)['key']

    imgs = [a['key'] for a in authors if a['key'] != '/a/OL2688880A' and has_image(a['key'])]
    if len(imgs) == 1:
        new_key = imgs[0]
    else:
        new_key = "/a/OL%dA" % min(key_int(a) for a in authors)
        # Molière and O. J. O. Ferreira
        if len(imgs) != 0:
            print('imgs:', imgs)
            return # skip
        if not (imgs == [u'/a/OL21848A', u'/a/OL4280680A'] \
                or imgs == [u'/a/OL325189A', u'/a/OL266422A'] \
                or imgs == [u'/a/OL5160945A', u'/a/OL5776228A']):
            print(imgs)
            assert len(imgs) == 0

    print(new_key)
    print(best_key)

    do_normalize(new_key, best_key, authors)
    old_keys = set(k for k in keys if k != new_key)
    print('old keys:', old_keys)

    for old in old_keys:
        # /b/OL21291659M
        switch_author(ol, old, new_key, old_keys, debug=True)
        if old in not_redirect:
            make_redirect(ol, old, new_key)
        q = { 'authors': old, 'type': '/type/edition', }
        if list(get_things(q)) != []:
            switch_author(ol, old, new_key, old_keys, debug=True)
Beispiel #3
0
def test_pick_best_author():
    a1 = {
        'name': 'Bretteville, Etienne Dubois abb\xe9 de',
        'death_date': '1688',
        'key': '/a/OL6398452A',
        'birth_date': '1650',
        'title': 'abb\xe9 de',
        'personal_name': 'Bretteville, Etienne Dubois',
        'type': {
            'key': '/type/author'
        },
    }
    a2 = {
        'name': 'Bretteville, \xc9tienne Dubois abb\xe9 de',
        'death_date': '1688',
        'key': '/a/OL4953701A',
        'birth_date': '1650',
        'title': 'abb\xe9 de',
        'personal_name': 'Bretteville, \xc9tienne Dubois',
        'type': {
            'key': '/type/author'
        },
    }
    assert pick_best_author([a1, a2])['key'] == a2['key']
Beispiel #4
0
def test_pick_best_author():
    a1 = {u'name': u'Bretteville, Etienne Dubois abb\xe9 de', u'death_date': u'1688', 'key': u'/a/OL6398452A', u'birth_date': u'1650', u'title': u'abb\xe9 de', u'personal_name': u'Bretteville, Etienne Dubois', u'type': {u'key': u'/type/author'}, }
    a2 = {u'name': u'Bretteville, \xc9tienne Dubois abb\xe9 de', u'death_date': u'1688', u'key': u'/a/OL4953701A', u'birth_date': u'1650', u'title': u'abb\xe9 de', u'personal_name': u'Bretteville, \xc9tienne Dubois', u'type': {u'key': u'/type/author'}, }
    assert pick_best_author([a1, a2])['key'] == a2['key']