def test_convert_new_publication_info_to_old_handles_renamed_journals(): schema = utils.load_schema('hep') subschema = schema['properties']['publication_info'] publication_info = [ { 'artid': '525', 'journal_title': 'Nucl.Phys.B Proc.Suppl.', 'journal_volume': '118', 'page_start': '525', } ] assert utils.validate(publication_info, subschema) is None expected = [ { 'artid': '525', 'journal_title': 'Nucl.Phys.Proc.Suppl.', 'journal_volume': '118', 'page_start': '525', } ] result = utils.convert_new_publication_info_to_old(publication_info) assert utils.validate(result, subschema) is None assert expected == result
def test_convert_new_publication_info_to_old_handles_year_added_to_volumes(): schema = utils.load_schema('hep') subschema = schema['properties']['publication_info'] publication_info = [ { 'artid': '137', 'journal_title': 'JHEP', 'journal_volume': '09', 'year': 2017, 'page_start': '137', } ] assert utils.validate(publication_info, subschema) is None expected = [ { 'artid': '137', 'journal_title': 'JHEP', 'journal_volume': '1709', 'year': 2017, 'page_start': '137', } ] result = utils.convert_new_publication_info_to_old(publication_info) assert utils.validate(result, subschema) is None assert expected == result
def test_convert_new_publication_info_to_old_handles_journal_titles_without_dots( ): schema = utils.load_schema('hep') subschema = schema['properties']['publication_info'] publication_info = [ { 'artid': '30', 'journal_title': 'Physica D', 'journal_volume': '231', 'page_start': '30', 'year': 2017, }, ] assert utils.validate(publication_info, subschema) is None expected = [ { 'artid': '30', 'journal_title': 'Physica', 'journal_volume': 'D231', 'page_start': '30', 'year': 2017, }, ] result = utils.convert_new_publication_info_to_old(publication_info) assert utils.validate(result, subschema) is None assert expected == result
def test_convert_new_publication_info_to_old_handles_phys_lett_b(): schema = utils.load_schema('hep') subschema = schema['properties']['publication_info'] publication_info = [ { 'journal_title': 'Phys.Lett.B', 'journal_volume': '72', }, ] assert utils.validate(publication_info, subschema) is None expected = [ { 'journal_title': 'Phys.Lett.', 'journal_volume': '72B', }, { 'hidden': True, 'journal_title': 'Phys.Lett.', 'journal_volume': 'B72', }, ] result = utils.convert_new_publication_info_to_old(publication_info) assert utils.validate(result, subschema) is None assert expected == result
def test_convert_new_publication_info_to_old_handles_volumes_with_letters_in_the_middle(): schema = utils.load_schema('hep') subschema = schema['properties']['publication_info'] publication_info = [ { 'journal_title': 'Eur.Phys.J.A', 'journal_volume': '28S1', }, ] assert utils.validate(publication_info, subschema) is None expected = [ { 'journal_title': 'Eur.Phys.J.', 'journal_volume': 'A28S1', }, ] result = utils.convert_new_publication_info_to_old(publication_info) assert utils.validate(result, subschema) is None assert expected == result
def test_convert_new_publication_info_to_old_handles_journals_with_already_a_letter(): schema = utils.load_schema('hep') subschema = schema['properties']['publication_info'] publication_info = [ { 'journal_title': 'Kumamoto J.Sci.Ser.A', 'journal_volume': '13', }, ] assert utils.validate(publication_info, subschema) is None expected = [ { 'journal_title': 'Kumamoto J.Sci.Ser.A', 'journal_volume': '13', }, ] result = utils.convert_new_publication_info_to_old(publication_info) assert utils.validate(result, subschema) is None assert expected == result
def test_convert_new_publication_info_to_old(): schema = utils.load_schema('hep') subschema = schema['properties']['publication_info'] publication_info = [ { 'journal_title': 'Phys.Rev.C', 'journal_volume': '48', }, ] assert utils.validate(publication_info, subschema) is None expected = [ { 'journal_title': 'Phys.Rev.', 'journal_volume': 'C48', }, ] result = utils.convert_new_publication_info_to_old(publication_info) assert utils.validate(result, subschema) is None assert expected == result
def publication_info2marc(self, key, values): """Populate the ``773`` MARC field. Also populates the ``7731`` MARC field through side effects. """ result_773 = self.get('773', []) result_7731 = self.get('7731', []) for value in force_list(convert_new_publication_info_to_old(values)): page_artid = [] if value.get('page_start') and value.get('page_end'): page_artid.append(u'{page_start}-{page_end}'.format(**value)) elif value.get('page_start'): page_artid.append(u'{page_start}'.format(**value)) if value.get('artid'): page_artid.append(u'{artid}'.format(**value)) result = { '0': get_recid_from_ref(value.get('parent_record')), 'c': page_artid, 'm': value.get('material'), 'n': value.get('journal_issue'), 'p': value.get('journal_title'), 'q': value.get('conf_acronym'), 'r': value.get('parent_report_number'), 'v': value.get('journal_volume'), 'w': value.get('cnum'), 'x': value.get('pubinfo_freetext'), 'y': value.get('year'), 'z': value.get('parent_isbn'), } if value.get('hidden'): result_7731.append(result) else: result_773.append(result) self['7731'] = result_7731 return result_773
def test_convert_new_publication_info_to_old_handles_the_letter_in_proc_roy_soc_lond( ): schema = utils.load_schema('hep') subschema = schema['properties']['publication_info'] publication_info = [ { 'journal_title': 'Proc.Roy.Soc.Lond.A', 'journal_volume': '110', }, ] assert utils.validate(publication_info, subschema) is None expected = [ { 'journal_title': 'Proc.Roy.Soc.Lond.', 'journal_volume': 'A110', }, ] result = utils.convert_new_publication_info_to_old(publication_info) assert utils.validate(result, subschema) is None assert expected == result
def references2marc(self, key, value): """Populate the ``999C5`` MARC field.""" reference = value.get('reference', {}) pids = force_list(reference.get('persistent_identifiers')) a_values = ['doi:' + el for el in force_list(reference.get('dois'))] a_values.extend( ['hdl:' + el['value'] for el in pids if el.get('schema') == 'HDL']) a_values.extend( ['urn:' + el['value'] for el in pids if el.get('schema') == 'URN']) external_ids = force_list(reference.get('external_system_identifiers')) u_values = force_list(get_value(reference, 'urls.value')) u_values.extend( CDS_RECORD_FORMAT.format(el['value']) for el in external_ids if el.get('schema') == 'CDS') u_values.extend( ADS_RECORD_FORMAT.format(el['value']) for el in external_ids if el.get('schema') == 'ADS') authors = force_list(reference.get('authors')) e_values = [ el['full_name'] for el in authors if el.get('inspire_role') == 'editor' ] h_values = [ el['full_name'] for el in authors if el.get('inspire_role') != 'editor' ] r_values = force_list(reference.get('report_numbers')) if reference.get('arxiv_eprint'): arxiv_eprint = reference['arxiv_eprint'] r_values.append( 'arXiv:' + arxiv_eprint if is_arxiv_post_2007(arxiv_eprint) else arxiv_eprint) if reference.get('publication_info'): reference['publication_info'] = convert_new_publication_info_to_old( [reference['publication_info']])[0] journal_title = get_value(reference, 'publication_info.journal_title') journal_volume = get_value(reference, 'publication_info.journal_volume') page_start = get_value(reference, 'publication_info.page_start') page_end = get_value(reference, 'publication_info.page_end') artid = get_value(reference, 'publication_info.artid') s_value = build_pubnote(journal_title, journal_volume, page_start, page_end, artid) m_value = ' / '.join(force_list(reference.get('misc'))) return { '0': get_recid_from_ref(value.get('record')), '9': 'CURATOR' if value.get('legacy_curated') else None, 'a': a_values, 'b': get_value(reference, 'publication_info.cnum'), 'c': reference.get('collaborations'), 'e': e_values, 'h': h_values, 'i': reference.get('isbn'), 'k': reference.get('texkey'), 'm': m_value, 'o': reference.get('label'), 'p': get_value(reference, 'imprint.publisher'), 'q': get_value(reference, 'publication_info.parent_title'), 'r': r_values, 's': s_value, 't': get_value(reference, 'title.title'), 'u': u_values, 'x': get_value(value, 'raw_refs.value'), 'y': get_value(reference, 'publication_info.year'), 'z': 1 if value.get('curated_relation') else 0, }