def test_publication_info_from_773__q_t(): schema = load_schema('hep') subschema = schema['properties']['publication_info'] snippet = ( '<datafield tag="773" ind1=" " ind2=" ">' ' <subfield code="q">LENPIC2017</subfield>' ' <subfield code="t">Chiral Forces in Low Energy Nuclear Physics</subfield>' '</datafield>') # record/1598069 expected = [ { 'conf_acronym': 'LENPIC2017' }, ] result = hep.do(create_record(snippet)) assert validate(result['publication_info'], subschema) is None assert expected == result['publication_info'] expected = [ { 'q': 'LENPIC2017' }, ] result = hep2marc.do(result) assert expected == result['773']
def test_private_notes_from_595_Ha(): schema = load_schema('hep') subschema = schema['properties']['_private_notes'] snippet = ( '<datafield tag="595" ind1=" " ind2="H">' ' <subfield code="a">affiliations à corriger, voir avec Mathieu - Dominique</subfield>' '</datafield>') # record/1514389 expected = [ { 'source': 'HAL', 'value': u'affiliations à corriger, voir avec Mathieu - Dominique', }, ] result = hep.do(create_record(snippet)) assert validate(result['_private_notes'], subschema) is None assert expected == result['_private_notes'] expected = [ { 'a': u'affiliations à corriger, voir avec Mathieu - Dominique' }, ] result = hep2marc.do(result) assert expected == result['595_H']
def test_report_numbers_from_037__a_9_arXiv_reportnumber(): schema = load_schema('hep') subschema = schema['properties']['report_numbers'] snippet = ('<datafield tag="037" ind1=" " ind2=" ">' ' <subfield code="9">arXiv:reportnumber</subfield>' ' <subfield code="a">LIGO-P1500247</subfield>' '</datafield>') # record/1618037 expected = [ { 'source': 'arXiv', 'value': 'LIGO-P1500247', }, ] result = hep.do(create_record(snippet)) assert validate(result['report_numbers'], subschema) is None assert expected == result['report_numbers'] expected = [ { '9': 'arXiv:reportnumber', 'a': 'LIGO-P1500247', }, ] result = hep2marc.do(result) assert expected == result['037'] assert '035' not in result
def test_license_from_540__double_a_u(): schema = load_schema('hep') subschema = schema['properties']['license'] snippet = ( '<datafield tag="540" ind1=" " ind2=" ">' ' <subfield code="a">Open Access</subfield>' ' <subfield code="a">CC-BY-3.0</subfield>' ' <subfield code="u">http://creativecommons.org/licenses/by/3.0/</subfield>' '</datafield>') # record/1414671 expected = [ { 'license': 'CC-BY-3.0', 'url': 'http://creativecommons.org/licenses/by/3.0/', }, ] result = hep.do(create_record(snippet)) assert validate(result['license'], subschema) is None assert expected == result['license'] expected = [ { 'a': 'CC-BY-3.0', 'u': 'http://creativecommons.org/licenses/by/3.0/', }, ] result = hep2marc.do(result) assert expected == result['540']
def test_copyright_from_542__d_g_3_with_weird_material(): schema = load_schema('hep') subschema = schema['properties']['copyright'] snippet = ('<datafield tag="542" ind1=" " ind2=" ">' ' <subfield code="3">Published thesis as a book</subfield>' ' <subfield code="d">Shaker Verlag</subfield>' ' <subfield code="g">2007</subfield>' '</datafield>') # record/773620 expected = [ { 'holder': 'Shaker Verlag', 'material': 'publication', 'year': 2007, }, ] result = hep.do(create_record(snippet)) assert validate(result['copyright'], subschema) is None assert expected == result['copyright'] expected = [ { 'd': 'Shaker Verlag', 'e': 'Article', 'g': 2007, }, ] result = hep2marc.do(result) assert expected == result['542']
def test_abstracts_from_520__a_9(): schema = load_schema('hep') subschema = schema['properties']['abstracts'] snippet = ( '<datafield tag="520" ind1=" " ind2=" ">' ' <subfield code="9">Springer</subfield>' ' <subfield code="a">We study a notion of non-commutative integration, in the spirit of modular spectral triples, for the quantum group SU$_{q}$ (2). In particular we define the non-commutative integral as the residue at the spectral dimension of a zeta function, which is constructed using a Dirac operator and a weight. We consider the Dirac operator introduced by Kaad and Senior and a family of weights depending on two parameters, which are related to the diagonal automorphisms of SU$_{q}$ (2). We show that, after fixing one of the parameters, the non-commutative integral coincides with the Haar state of SU$_{q}$ (2). Moreover we can impose an additional condition on the zeta function, which also fixes the second parameter. For this unique choice the spectral dimension coincides with the classical dimension.</subfield>' '</datafield>') # record/1346798 expected = [ { 'source': 'Springer', 'value': 'We study a notion of non-commutative integration, in the spirit of modular spectral triples, for the quantum group SU$_{q}$ (2). In particular we define the non-commutative integral as the residue at the spectral dimension of a zeta function, which is constructed using a Dirac operator and a weight. We consider the Dirac operator introduced by Kaad and Senior and a family of weights depending on two parameters, which are related to the diagonal automorphisms of SU$_{q}$ (2). We show that, after fixing one of the parameters, the non-commutative integral coincides with the Haar state of SU$_{q}$ (2). Moreover we can impose an additional condition on the zeta function, which also fixes the second parameter. For this unique choice the spectral dimension coincides with the classical dimension.', }, ] result = hep.do(create_record(snippet)) assert validate(result['abstracts'], subschema) is None assert expected == result['abstracts'] expected = [ { '9': 'Springer', 'a': 'We study a notion of non-commutative integration, in the spirit of modular spectral triples, for the quantum group SU$_{q}$ (2). In particular we define the non-commutative integral as the residue at the spectral dimension of a zeta function, which is constructed using a Dirac operator and a weight. We consider the Dirac operator introduced by Kaad and Senior and a family of weights depending on two parameters, which are related to the diagonal automorphisms of SU$_{q}$ (2). We show that, after fixing one of the parameters, the non-commutative integral coincides with the Haar state of SU$_{q}$ (2). Moreover we can impose an additional condition on the zeta function, which also fixes the second parameter. For this unique choice the spectral dimension coincides with the classical dimension.', }, ] result = hep2marc.do(result) assert expected == result['520']
def test_funding_info_from_536__a_c_f_0(): schema = load_schema('hep') subschema = schema['properties']['funding_info'] snippet = ( '<datafield tag="536" ind1=" " ind2=" ">' ' <subfield code="0">G:(EU-Grant)317089</subfield>' ' <subfield code="a">GATIS - Gauge Theory as an Integrable System (317089)</subfield>' ' <subfield code="c">317089</subfield>' ' <subfield code="f">FP7-PEOPLE-2012-ITN</subfield>' '</datafield>') # record/1508869 expected = [ { 'agency': 'GATIS - Gauge Theory as an Integrable System (317089)', 'grant_number': '317089', 'project_number': 'FP7-PEOPLE-2012-ITN', }, ] result = hep.do(create_record(snippet)) assert validate(result['funding_info'], subschema) is None assert expected == result['funding_info'] expected = [ { 'a': 'GATIS - Gauge Theory as an Integrable System (317089)', 'c': '317089', 'f': 'FP7-PEOPLE-2012-ITN', }, ] result = hep2marc.do(result) assert expected == result['536']
def test_collaborations_from_710__g_0(): schema = load_schema('hep') subschema = schema['properties']['collaborations'] snippet = ('<datafield tag="710" ind1=" " ind2=" ">' ' <subfield code="g">ANTARES</subfield>' ' <subfield code="0">1110619</subfield>' '</datafield>') # record/1422032 expected = [ { 'record': { '$ref': 'http://localhost:5000/api/experiments/1110619', }, 'value': 'ANTARES', }, ] result = hep.do(create_record(snippet)) assert validate(result['collaborations'], subschema) is None assert expected == result['collaborations'] expected = [ { 'g': 'ANTARES' }, ] result = hep2marc.do(result) assert expected == result['710']
def test_related_superseding_records_78502r_w_z(): schema = load_schema('hep') subschema = schema['properties']['related_records'] snippet = ('<datafield tag="785" ind1="0" ind2="2">' '<subfield code="i">superseded by</subfield>' '<subfield code="r">CERN-EP-2016-305</subfield>' '<subfield code="w">1510564</subfield>' '</datafield>') # record/1503270 expected = [ { 'curated_relation': True, 'record': { '$ref': 'http://localhost:5000/api/literature/1510564', }, 'relation': 'successor', }, ] result = hep.do(create_record(snippet)) assert validate(result['related_records'], subschema) is None assert expected == result['related_records'] expected = [ { 'i': 'superseded by', 'w': 1510564, }, ] result = hep2marc.do(result) assert expected == result['78502']
def test_publication_info2marc_handles_unicode(): schema = load_schema('hep') subschema = schema['properties']['publication_info'] record = { 'publication_info': [ { 'artid': u'207–214', 'journal_issue': '36', 'journal_title': 'Electronic Journal of Theoretical Physics', 'journal_volume': '13', 'year': 2016, }, ], } # holdingpen/650664 assert validate(record['publication_info'], subschema) is None expected = [ { 'c': [ u'207–214', ], 'n': '36', 'p': 'Electronic Journal of Theoretical Physics', 'v': '13', 'y': 2016, }, ] result = hep2marc.do(record) assert expected == result['773']
def test_related_records_from_78002i_r_w(): schema = load_schema('hep') subschema = schema['properties']['related_records'] snippet = ('<datafield tag="780" ind1="0" ind2="2">' ' <subfield code="i">supersedes</subfield>' ' <subfield code="r">ATLAS-CONF-2016-113</subfield>' ' <subfield code="w">1503270</subfield>' '</datafield>') # record/1510564 expected = [ { 'curated_relation': True, 'record': { '$ref': 'http://localhost:5000/api/literature/1503270', }, 'relation': 'predecessor', }, ] result = hep.do(create_record(snippet)) assert validate(result['related_records'], subschema) is None assert expected == result['related_records'] expected = [ { 'i': 'supersedes', 'w': 1503270, }, ] result = hep2marc.do(result) assert expected == result['78002']
def test_collaborations_from_710__g_normalizes_value(): schema = load_schema('hep') subschema = schema['properties']['collaborations'] snippet = ( '<datafield tag="710" ind1=" " ind2=" ">' ' <subfield code="g">on behalf of the CMS Collaboration</subfield>' '</datafield>') # http://cds.cern.ch/record/2293683 expected = [ { 'value': 'CMS' }, ] result = hep.do(create_record(snippet)) assert validate(result['collaborations'], subschema) is None assert expected == result['collaborations'] expected = [ { 'g': 'CMS' }, ] result = hep2marc.do(result) assert expected == result['710']
def test_publication_info_from_773__c_z_handles_dashes_in_isbns(): schema = load_schema('hep') subschema = schema['properties']['publication_info'] snippet = ('<datafield tag="773" ind1=" " ind2=" ">' ' <subfield code="c">110-125</subfield>' ' <subfield code="z">978-1-4684-7552-4</subfield>' '</datafield>') # record/1334853 expected = [ { 'page_end': '125', 'page_start': '110', 'parent_isbn': '9781468475524', }, ] result = hep.do(create_record(snippet)) assert validate(result['publication_info'], subschema) is None assert expected == result['publication_info'] expected = [ { 'c': [ '110-125', ], 'z': '9781468475524', }, ] result = hep2marc.do(result) assert expected == result['773']
def test_publication_info_from_773__w_handles_slashes_in_cnums(): schema = load_schema('hep') subschema = schema['properties']['publication_info'] snippet = ('<datafield tag="773" ind1=" " ind2=" ">' ' <subfield code="w">C17/05/14</subfield>' '</datafield>') # record/1622968 expected = [ { 'cnum': 'C17-05-14' }, ] result = hep.do(create_record(snippet)) assert validate(result['publication_info'], subschema) is None assert expected == result['publication_info'] expected = [ { 'w': 'C17-05-14' }, ] result = hep2marc.do(result) assert expected == result['773']
def test_export_to_from_595__double_c(): schema = load_schema('hep') subschema = schema['properties']['_export_to'] snippet = ('<datafield tag="595" ind1=" " ind2=" ">' ' <subfield code="c">CDS</subfield>' ' <subfield code="c">not HAL</subfield>' '</datafield>') # record/1512843 expected = { 'CDS': True, 'HAL': False, } result = hep.do(create_record(snippet)) assert validate(result['_export_to'], subschema) is None assert expected == result['_export_to'] expected = [ { 'c': 'CDS' }, { 'c': 'not HAL' }, ] result = hep2marc.do(result) assert expected == result['595']
def test_related_records_from_78708i_w(): schema = load_schema('hep') subschema = schema['properties']['related_records'] snippet = ('<datafield tag="787" ind1="0" ind2="8">' ' <subfield code="i">Addendum</subfield>' ' <subfield code="w">1474710</subfield>' '</datafield>') # record/1415979 expected = [ { 'curated_relation': True, 'record': { '$ref': 'http://localhost:5000/api/literature/1474710', }, 'relation_freetext': 'Addendum', }, ] result = hep.do(create_record(snippet)) assert validate(result['related_records'], subschema) is None assert expected == result['related_records'] expected = [ { 'i': 'Addendum', 'w': 1474710, }, ] result = hep2marc.do(result) assert expected == result['78708']
def test_public_notes_from_500__a_9(): schema = load_schema('hep') subschema = schema['properties']['public_notes'] snippet = ('<datafield tag="500" ind1=" " ind2=" ">' ' <subfield code="9">arXiv</subfield>' ' <subfield code="a">5 pages</subfield>' '</datafield>') # record/1450044 expected = [ { 'source': 'arXiv', 'value': '5 pages', }, ] result = hep.do(create_record(snippet)) assert validate(result['public_notes'], subschema) is None assert expected == result['public_notes'] expected = [ { '9': 'arXiv', 'a': '5 pages', }, ] result = hep2marc.do(result) assert expected == result['500']
def test_references_from_999C5k(): schema = load_schema('hep') subschema = schema['properties']['references'] snippet = ( '<datafield tag="999" ind1="C" ind2="5">' ' <subfield code="k">Robilotta:2008js</subfield>' '</datafield>' ) # synthetic data expected = [ { 'reference': { 'texkey': 'Robilotta:2008js', }, }, ] result = hep.do(create_record(snippet)) assert validate(result['references'], subschema) is None assert expected == result['references'] expected = [ {'k': 'Robilotta:2008js'}, ] result = hep2marc.do(result) assert expected == result['999C5']
def test_abstracts_from_520__h_9(): schema = load_schema('hep') subschema = schema['properties']['abstracts'] snippet = ( '<datafield tag="520" ind1=" " ind2=" ">' ' <subfield code="9">HEPDATA</subfield>' ' <subfield code="h">CERN-SPS. Measurements of the spectra of positively charged kaons in proton-carbon interactions at a beam momentum of 31 GeV/c. The analysis is based on the full set of data collected in 2007 using a 4% nuclear interaction length graphite target. Charged pion spectra taken using the same data set are compared with the kaon spectra.</subfield>' '</datafield>') # record/1079585 expected = [ { 'source': 'HEPDATA', 'value': 'CERN-SPS. Measurements of the spectra of positively charged kaons in proton-carbon interactions at a beam momentum of 31 GeV/c. The analysis is based on the full set of data collected in 2007 using a 4% nuclear interaction length graphite target. Charged pion spectra taken using the same data set are compared with the kaon spectra.', }, ] result = hep.do(create_record(snippet)) assert validate(result['abstracts'], subschema) is None assert expected == result['abstracts'] expected = [ { '9': 'HEPDATA', 'h': 'CERN-SPS. Measurements of the spectra of positively charged kaons in proton-carbon interactions at a beam momentum of 31 GeV/c. The analysis is based on the full set of data collected in 2007 using a 4% nuclear interaction length graphite target. Charged pion spectra taken using the same data set are compared with the kaon spectra.', }, ] result = hep2marc.do(result) assert expected == result['520']
def test_document_type_from_980__a(): schema = load_schema('hep') subschema = schema['properties']['document_type'] snippet = ( '<datafield tag="980" ind1=" " ind2=" ">' ' <subfield code="a">Book</subfield>' '</datafield>' ) # record/1512050 expected = [ 'book', ] result = hep.do(create_record(snippet)) assert validate(result['document_type'], subschema) is None assert expected == result['document_type'] expected = [ {'a': 'Book'}, {'a': 'HEP'} ] result = hep2marc.do(result) assert expected == result['980']
def test_license_from_540__a_3(): schema = load_schema('hep') subschema = schema['properties']['license'] snippet = ('<datafield tag="540" ind1=" " ind2=" ">' ' <subfield code="3">Article</subfield>' ' <subfield code="a">OA</subfield>' '</datafield>') # record/120203 expected = [ { 'license': 'OA', 'material': 'publication', }, ] result = hep.do(create_record(snippet)) assert validate(result['license'], subschema) is None assert expected == result['license'] expected = [ { '3': 'publication', 'a': 'OA', }, ] result = hep2marc.do(result) assert expected == result['540']
def test_record_affiliations_from_902__a_z(): schema = load_schema('hep') subschema = schema['properties']['record_affiliations'] snippet = ( '<datafield tag="902" ind1=" " ind2=" ">' ' <subfield code="a">Iowa State U.</subfield>' ' <subfield code="z">902893</subfield>' '</datafield>' ) # record/1216295 expected = [ { 'curated_relation': True, 'record': { '$ref': 'http://localhost:5000/api/institutions/902893', }, 'value': 'Iowa State U.', }, ] result = hep.do(create_record(snippet)) assert validate(result['record_affiliations'], subschema) is None assert expected == result['record_affiliations'] expected = [ {'a': 'Iowa State U.'}, ] result = hep2marc.do(result) assert expected == result['902']
def test_copyright_from_542__d_g_3(): schema = load_schema('hep') subschema = schema['properties']['copyright'] snippet = ('<datafield tag="542" ind1=" " ind2=" ">' ' <subfield code="3">Article</subfield>' ' <subfield code="d">American Physical Society</subfield>' ' <subfield code="g">2014</subfield>' '</datafield>') # record/1255327 expected = [ { 'holder': 'American Physical Society', 'material': 'publication', 'year': 2014, }, ] result = hep.do(create_record(snippet)) assert validate(result['copyright'], subschema) is None assert expected == result['copyright'] expected = [ { 'd': 'American Physical Society', 'e': 'Article', 'g': 2014, }, ] result = hep2marc.do(result) assert expected == result['542']
def test_document_type_from_980__a_handles_conference_paper(): schema = load_schema('hep') subschema = schema['properties']['document_type'] snippet = ( '<datafield tag="980" ind1=" " ind2=" ">' ' <subfield code="a">ConferencePaper</subfield>' '</datafield>' ) # record/1589240 expected = [ 'conference paper', ] result = hep.do(create_record(snippet)) assert validate(result['document_type'], subschema) is None assert expected == result['document_type'] expected = [ {'a': 'ConferencePaper'}, {'a': 'HEP'}, ] result = hep2marc.do(result) assert expected == result['980']
def test_private_notes_from_595__a_9(): schema = load_schema('hep') subschema = schema['properties']['_private_notes'] snippet = ('<datafield tag="595" ind1=" " ind2=" ">' ' <subfield code="9">SPIRES-HIDDEN</subfield>' ' <subfield code="a">Title changed from ALLCAPS</subfield>' '</datafield>') # record/109310 expected = [ { 'source': 'SPIRES-HIDDEN', 'value': 'Title changed from ALLCAPS', }, ] result = hep.do(create_record(snippet)) assert validate(result['_private_notes'], subschema) is None assert expected == result['_private_notes'] expected = [ { '9': 'SPIRES-HIDDEN', 'a': 'Title changed from ALLCAPS', }, ] result = hep2marc.do(result) assert expected == result['595']
def test_document_type_from_980__a_handles_activity_report(): schema = load_schema('hep') subschema = schema['properties']['document_type'] snippet = ( '<datafield tag="980" ind1=" " ind2=" ">' ' <subfield code="a">ActivityReport</subfield>' '</datafield>' ) # record/1514964 expected = [ 'activity report', ] result = hep.do(create_record(snippet)) assert validate(result['document_type'], subschema) is None assert expected == result['document_type'] expected = [ {'a': 'ActivityReport'}, {'a': 'HEP'}, ] result = hep2marc.do(result) assert expected == result['980']
def test_desy_bookkeeping_from_595_D_double_a_d_s(): schema = load_schema('hep') subschema = schema['properties']['_desy_bookkeeping'] snippet = ('<datafield tag="595" ind1=" " ind2="D">' ' <subfield code="d">2016-07-23</subfield>' ' <subfield code="a">E</subfield>' ' <subfield code="s">final</subfield>' ' <subfield code="a">E</subfield>' '</datafield>') # record/558693 expected = [ { 'expert': 'E', 'date': '2016-07-23', 'status': 'final', }, ] result = hep.do(create_record(snippet)) assert validate(result['_desy_bookkeeping'], subschema) is None assert expected == result['_desy_bookkeeping'] expected = [ { 'a': 'E', 'd': '2016-07-23', 's': 'final', }, ] result = hep2marc.do(result) assert expected == result['595_D']
def test_publication_type_from_980__a(): schema = load_schema('hep') subschema = schema['properties']['publication_type'] snippet = ( '<datafield tag="980" ind1=" " ind2=" ">' ' <subfield code="a">Review</subfield>' '</datafield>' ) # record/1509993 expected = [ 'review', ] result = hep.do(create_record(snippet)) assert validate(result['publication_type'], subschema) is None assert expected == result['publication_type'] expected = [ {'a': 'review'}, {'a': 'HEP'} ] result = hep2marc.do(result) assert expected == result['980']
def test_arxiv_eprints_from_037__a_c_9_and_multiple_65017_a_2(): schema = load_schema('hep') subschema = schema['properties']['arxiv_eprints'] snippet = ('<record>' ' <datafield tag="037" ind1=" " ind2=" ">' ' <subfield code="9">arXiv</subfield>' ' <subfield code="a">arXiv:1702.00702</subfield>' ' <subfield code="c">math-ph</subfield>' ' </datafield>' ' <datafield tag="650" ind1="1" ind2="7">' ' <subfield code="a">math-ph</subfield>' ' <subfield code="2">arXiv</subfield>' ' </datafield>' ' <datafield tag="650" ind1="1" ind2="7">' ' <subfield code="a">gr-qc</subfield>' ' <subfield code="2">arXiv</subfield>' ' </datafield>' '</record>') # record/1511862 expected = [{ 'categories': [ 'math-ph', 'gr-qc', ], 'value': '1702.00702' }] result = hep.do(create_record(snippet)) assert validate(result['arxiv_eprints'], subschema) is None assert expected == result['arxiv_eprints'] expected_035 = [ { '9': 'arXiv', 'a': 'oai:arXiv.org:1702.00702', }, ] expected_037 = [ { '9': 'arXiv', 'a': 'arXiv:1702.00702', 'c': 'math-ph', }, ] expected_65017 = [ { '2': 'arXiv', 'a': 'math-ph', }, { '2': 'arXiv', 'a': 'gr-qc', }, ] result = hep2marc.do(result) assert expected_035 == result['035'] assert expected_037 == result['037'] assert expected_65017 == result['65017']
def test_collaborations_from_710__g(): schema = load_schema('hep') subschema = schema['properties']['collaborations'] snippet = ('<datafield tag="710" ind1=" " ind2=" ">' ' <subfield code="g">Pierre Auger</subfield>' '</datafield>') # record/1510404 expected = [ { 'value': 'Pierre Auger' }, ] result = hep.do(create_record(snippet)) assert validate(result['collaborations'], subschema) is None assert expected == result['collaborations'] expected = [ { 'g': 'Pierre Auger' }, ] result = hep2marc.do(result) assert expected == result['710']