def assign_phonetic_block(sender, record, *args, **kwargs): """Assign a phonetic block to each signature of a Literature record. Uses the NYSIIS algorithm to compute a phonetic block from each signature's full name, skipping those that are not recognized as real names, but logging an error when that happens. """ if 'hep.json' not in record.get('$schema'): return authors = record.get('authors', []) authors_map = {} for i, author in enumerate(authors): if 'full_name' in author: authors_map[author['full_name']] = i try: signatures_blocks = phonetic_blocks(authors_map.keys()) except Exception as err: current_app.logger.error( 'Cannot extract phonetic blocks for record %d: %s', record.get('control_number'), err) return for full_name, signature_block in six.iteritems(signatures_blocks): authors[authors_map[full_name]].update({ 'signature_block': signature_block, })
def assign_phonetic_block(sender, record, *args, **kwargs): """Assign a phonetic block to each signature of a Literature record. Uses the NYSIIS algorithm to compute a phonetic block from each signature's full name, skipping those that are not recognized as real names, but logging an error when that happens. """ if not is_hep(record): return authors = record.get('authors', []) authors_map = {} for i, author in enumerate(authors): if 'full_name' in author: authors_map[author['full_name']] = i try: signatures_blocks = phonetic_blocks(authors_map.keys()) except Exception as err: current_app.logger.error( 'Cannot extract phonetic blocks for record %d: %s', record.get('control_number'), err) return for full_name, signature_block in six.iteritems(signatures_blocks): authors[authors_map[full_name]].update({ 'signature_block': signature_block, })
def assign_phonetic_block(sender, record, *args, **kwargs): """Assign a phonetic block to each signature of a Literature record. Uses the NYSIIS algorithm to compute a phonetic block from each signature's full name, skipping those that are not recognized as real names, but logging an error when that happens. """ if not is_hep(record): return author_names = get_value(record, 'authors.full_name', default=[]) try: signature_blocks = phonetic_blocks(author_names) except Exception as err: current_app.logger.error( 'Cannot extract phonetic blocks for record %d: %s', record.get('control_number'), err) return for author in record.get('authors', []): if author['full_name'] in signature_blocks and signature_blocks[author['full_name']]: author['signature_block'] = signature_blocks[author['full_name']]