def add_bibkeys(reference_table): bibkey_map = {} bibkeys = set() new_table = [] for row in reference_table: old_id = row.get('ID') if not old_id: continue try: bibkey = bib.generate_bibkey(row) except ValueError as e: print('Reference {}: Could not generate bibkey:'.format(old_id), str(e), file=sys.stderr) continue bibkey_map[str(old_id)] = bibkey # TODO Warn about potential duplicates if bibkey not in bibkeys: new_row = dict(row) new_row['ID'] = bibkey new_row['LaTeX_cite_key'] = bibkey new_table.append(new_row) bibkeys.add(bibkey) return new_table, bibkey_map
def test_more_authors(self): row = { 'author': 'Jane Doe and John Doe and Max Mustermann', 'year': 2019, 'title': 'Title'} bibkey = bib.generate_bibkey(row) self.assertEqual(bibkey, 'doe-etal-2019')
def test_unicode_removal(self): row = { 'author': "Hanka Dvořaková and Seamus O'Brien", 'year': 2019, 'title': 'Title'} bibkey = bib.generate_bibkey(row) self.assertEqual(bibkey, 'dvorakova-obrien-2019')
def test_two_authors(self): row = { 'author': 'Jane Doe and John Doe', 'year': 2019, 'title': 'Title'} bibkey = bib.generate_bibkey(row) self.assertEqual(bibkey, 'doe-doe-2019')
def test_single_author(self): row = { 'author': 'John Doe', 'year': 2019, 'title': 'Title'} bibkey = bib.generate_bibkey(row) self.assertEqual(bibkey, 'doe-2019')
def test_disambiguation_letter(self): row = { 'author': 'John Doe', 'year': 2019, 'Year_disambiguation_letter': 'a', 'title': 'Title'} bibkey = bib.generate_bibkey(row) self.assertEqual(bibkey, 'doe-2019a')
def test_fall_back_to_id(self): row = { 'ID': 1, 'title': 'Title'} bibkey = bib.generate_bibkey(row) self.assertEqual(bibkey, '1')
def test_use_existing_bibkey_if_any(self): row = { 'LaTeX_cite_key': 'key', 'title': 'Title'} bibkey = bib.generate_bibkey(row) self.assertEqual(bibkey, 'key')