Пример #1
0
def match_beitrag(engine, beitrag):
    nkp = nk_persons()
    beitrag_print = make_long_name(beitrag)
    log.info("Matching: %s", beitrag_print)
    try:
        value = match_speaker(beitrag_print)
        if sl.find_one(engine, sl.get_table(engine, 'person'),
                fingerprint=value) is None:
            make_person(beitrag, value, engine)
        return value
    except NKNoMatch, nm:
        log.info("Beitrag person is unknown: %s", beitrag_print)
        return None
Пример #2
0
def match_beitrag(db, master, beitrag, prints):
    beitrag_print = make_long_name(beitrag)
    print "Matching:", beitrag_print.encode('utf-8')
    matches = [(p, levenshtein(p, beitrag_print)) for p in prints]
    matches = sorted(matches, key=lambda (p,d): d)
    if not len(matches):
        # create new
        return make_person(beitrag, beitrag_print, db)
    first, dist = matches[0]
    if dist == 0:
        return first
    NameMatch = master['name_match']
    match = NameMatch.find_one(dirty=beitrag_print)
    if match is not None:
        Person = db['person']
        if Person.find_one(fingerprint=match.get('clean')) is None:
            return make_person(beitrag, match.get('clean'), db)
        return match.get('clean')
    try:
        user_res = ask_user(beitrag, beitrag_print, matches, db)
        NameMatch.writerow({'dirty': beitrag_print, 'clean': user_res})
        return user_res
    except ValueError: pass