Ejemplo n.º 1
0
def test_ids_from_double_035__a_9_with_kaken():
    snippet = (
        '<record>'
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">BAI</subfield>'
        '    <subfield code="a">Toshio.Suzuki.2</subfield>'
        '  </datafield>'
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">KAKEN</subfield>'
        '    <subfield code="a">70139070</subfield>'
        '  </datafield>'
        '</record>'
    )  # record/1474271/export/xme

    expected = [
        {
            'type': 'INSPIRE BAI',
            'value': 'Toshio.Suzuki.2',
        },
        {
            'type': 'KAKEN',
            'value': 'KAKEN-70139070',
        },
    ]
    result = clean_record(hepnames.do(create_record(snippet)))

    assert expected == result['ids']
Ejemplo n.º 2
0
def test_positions_from_371__a_m_r_z():
    snippet = (
        '<datafield tag="371" ind1=" " ind2=" ">'
        '  <subfield code="a">Antwerp U.</subfield>'
        '  <subfield code="m">[email protected]</subfield>'
        '  <subfield code="r">SENIOR</subfield>'
        '  <subfield code="z">Current</subfield>'
        '</datafield>'
    )  # record/997958

    expected = [
        {
            'curated_relation': False,
            'email': '*****@*****.**',
            'institution': {
                'name': 'Antwerp U.',
            },
            'rank': 'SENIOR',
            '_rank': 'SENIOR',
            'status': 'Current',
        },
    ]
    result = clean_record(hepnames.do(create_record(snippet)))

    assert expected == result['positions']
Ejemplo n.º 3
0
def test_advisors_from_701__a_g_i():
    snippet = (
        '<datafield tag="701" ind1=" " ind2=" ">'
        '  <subfield code="a">Rivelles, Victor O.</subfield>'
        '  <subfield code="g">PhD</subfield>'
        '  <subfield code="i">INSPIRE-00120420</subfield>'
        '  <subfield code="x">991627</subfield>'
        '  <subfield code="y">1</subfield>'
        '</datafield>'
    )  # record/1474091

    expected = [
        {
            'name': 'Rivelles, Victor O.',
            'degree_type': 'PhD',
            '_degree_type': 'PhD',
            'record': {
                '$ref': 'http://localhost:5000/api/authors/991627',
            },
            'curated_relation': True
        },
    ]
    result = clean_record(hepnames.do(create_record(snippet)))

    assert expected == result['advisors']
def test_field_from_marcxml_650_with_two_2():
    """Two '2' subfields in one datafield.

    The first will be taken (this time it's correct).
    """
    snippet = (
        '<record>'
        '  <datafield tag="650" ind1="1" ind2="7">'
        '    <subfield code="2">arXiv</subfield>'
        '    <subfield code="2">INSPIRE</subfield>'
        '    <subfield code="a">hep-ex</subfield>'
        '  </datafield>'
        '</record>'
    )

    expected = [
        {
            '_scheme': 'arXiv',
            'scheme': 'INSPIRE',
            '_term': 'hep-ex',
            'term': 'Experiment-HEP',
        },
    ]
    result = clean_record(hepnames.do(create_record(snippet)))

    assert expected == result['field_categories']
Ejemplo n.º 5
0
def test_status_from_100__a_g_q():
    schema = load_schema('authors')
    subschema = schema['properties']['status']

    snippet = (
        '<datafield tag="100" ind1=" " ind2=" ">'
        '  <subfield code="a">Abarbanel, Henry D.I.</subfield>'
        '  <subfield code="q">Henry D.I. Abarbanel</subfield>'
        '  <subfield code="g">ACTIVE</subfield>'
        '</datafield>'
    )  # record/1019100

    expected = 'active'
    result = hepnames.do(create_record(snippet))

    assert validate(result['status'], subschema) is None
    assert expected == result['status']

    expected = {
        'a': 'Abarbanel, Henry D.I.',
        'q': 'Henry D.I. Abarbanel',
        'g': 'active',
    }
    result = hepnames2marc.do(result)

    assert expected == result['100']
Ejemplo n.º 6
0
def test_positions_from_371__a_double_m_z():
    snippet = (
        '<datafield tag="371" ind1=" " ind2=" ">'
        '  <subfield code="a">Argonne</subfield>'
        '  <subfield code="m">[email protected]</subfield>'
        '  <subfield code="m">[email protected]</subfield>'
        '  <subfield code="z">current</subfield>'
        '</datafield>'
    )  # record/1408378

    expected = [
        {
            'current': True,
            'emails': [
                '*****@*****.**',
                '*****@*****.**',
            ],
            'institution': {
                'curated_relation': False,
                'name': 'Argonne',
            },
        }
    ]
    result = clean_record(hepnames.do(create_record(snippet)))

    assert expected == result['positions']
Ejemplo n.º 7
0
def test_other_names_from_400__triple_a():
    schema = load_schema('authors')
    subschema = schema['properties']['other_names']

    snippet = (
        '<datafield tag="400" ind1=" " ind2=" ">'
        '  <subfield code="a">Yosef Cohen, Hadar</subfield>'
        '  <subfield code="a">Josef Cohen, Hadar</subfield>'
        '  <subfield code="a">Cohen, Hadar Josef</subfield>'
        '</datafield>'
    )  # record/1292399/export/xme

    expected = [
        'Yosef Cohen, Hadar',
        'Josef Cohen, Hadar',
        'Cohen, Hadar Josef',
    ]
    result = hepnames.do(create_record(snippet))

    assert validate(result['other_names'], subschema) is None
    assert expected == result['other_names']

    expected = [
        {'a': 'Yosef Cohen, Hadar'},
        {'a': 'Josef Cohen, Hadar'},
        {'a': 'Cohen, Hadar Josef'},
    ]
    result = hepnames2marc.do(result)

    assert expected == result['400']
Ejemplo n.º 8
0
def test_ids_from_035__a_9_with_researcherid():
    schema = load_schema('authors')
    subschema = schema['properties']['ids']

    snippet = (
        '<datafield tag="035" ind1=" " ind2=" ">'
        '  <subfield code="9">RESEARCHERID</subfield>'
        '  <subfield code="a">B-4717-2008</subfield>'
        '</datafield>'
    )  # record/1051026/export/xme

    expected = [
        {
            'schema': 'RESEARCHERID',
            'value': 'B-4717-2008',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert validate(result['ids'], subschema) is None
    assert expected == result['ids']

    expected = [
        {
            '9': 'RESEARCHERID',
            'a': 'B-4717-2008',
        },
    ]
    result = hepnames2marc.do(result)

    assert expected == result['035']
Ejemplo n.º 9
0
def test_ids_from_035__a_9_with_desy():
    schema = load_schema('authors')
    subschema = schema['properties']['ids']

    snippet = (
        '<datafield tag="035" ind1=" " ind2=" ">'
        '  <subfield code="a">DESY-1001805</subfield>'
        '  <subfield code="9">DESY</subfield>'
        '</datafield>'
    )  # record/993224/export/xme

    expected = [
        {
            'schema': 'DESY',
            'value': 'DESY-1001805',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert validate(result['ids'], subschema) is None
    assert expected == result['ids']

    expected = [
        {
            '9': 'DESY',
            'a': 'DESY-1001805',
        },
    ]
    result = hepnames2marc.do(result)

    assert expected == result['035']
Ejemplo n.º 10
0
def test_private_notes_from_595__a_9():
    schema = load_schema('authors')
    subschema = schema['properties']['_private_notes']

    snippet = (
        '<datafield tag="595" ind1=" " ind2=" ">'
        '  <subfield code="a">Author prefers Alexandrov, A.S.</subfield>'
        '  <subfield code="9">SPIRES-HIDDEN</subfield>'
        '</datafield>'
    )  # record/1050484

    expected = [
        {
            'source': 'SPIRES-HIDDEN',
            'value': 'Author prefers Alexandrov, A.S.',
        }
    ]
    result = hepnames.do(create_record(snippet))

    assert validate(result['_private_notes'], subschema) is None
    assert expected == result['_private_notes']

    expected = [
        {
            '9': 'SPIRES-HIDDEN',
            'a': 'Author prefers Alexandrov, A.S.',
        }
    ]
    result = hepnames2marc.do(result)

    assert expected == result['595']
Ejemplo n.º 11
0
def test_ids_from_035__a_9_with_scopus():
    schema = load_schema('authors')
    subschema = schema['properties']['ids']

    snippet = (
        '<datafield tag="035" ind1=" " ind2=" ">'
        '  <subfield code="9">SCOPUS</subfield>'
        '  <subfield code="a">7103280792</subfield>'
        '</datafield>'
    )  # record/1017182/export/xme

    expected = [
        {
            'schema': 'SCOPUS',
            'value': '7103280792',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert validate(result['ids'], subschema) is None
    assert expected == result['ids']

    expected = [
        {
            '9': 'SCOPUS',
            'a': '7103280792',
        },
    ]
    result = hepnames2marc.do(result)

    assert expected == result['035']
Ejemplo n.º 12
0
def test_ids_from_035__a_9_with_orcid():
    schema = load_schema('authors')
    subschema = schema['properties']['ids']

    snippet = (
        '<datafield tag="035" ind1=" " ind2=" ">'
        '  <subfield code="9">ORCID</subfield>'
        '  <subfield code="a">0000-0001-6771-2174</subfield>'
        '</datafield>'
    )

    expected = [
        {
            'schema': 'ORCID',
            'value': '0000-0001-6771-2174',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert validate(result['ids'], subschema) is None
    assert expected == result['ids']

    expected = [
        {
            '9': 'ORCID',
            'a': '0000-0001-6771-2174',
        }
    ]
    result = hepnames2marc.do(result)

    assert expected == result['035']
Ejemplo n.º 13
0
def update():
    """View for INSPIRE author update form."""
    from dojson.contrib.marc21.utils import create_record
    from inspirehep.dojson.hepnames import hepnames

    recid = request.values.get('recid', 0, type=int)

    data = {}
    if recid:
        try:
            url = os.path.join(
                current_app.config["AUTHORS_UPDATE_BASE_URL"],
                "record", str(recid), "export", "xm")
            xml = requests.get(url)
            record_regex = re.compile(
                r"\<record\>.*\<\/record\>", re.MULTILINE + re.DOTALL)
            xml_content = record_regex.search(xml.content).group()

            data = strip_empty_values(
                hepnames.do(create_record(xml_content)))  # .encode("utf-8")
            convert_for_form(data)
        except requests.exceptions.RequestException:
            pass
        data["recid"] = recid
    else:
        return redirect(url_for("inspirehep_authors_holdingpen.new"))
    form = AuthorUpdateForm(data=data, is_update=True)
    ctx = {
        "action": url_for('.submitupdate'),
        "name": "authorUpdateForm",
        "id": "authorUpdateForm",
    }

    # FIXME create template in authors module
    return render_template('authors/forms/update_form.html', form=form, **ctx)
Ejemplo n.º 14
0
def test_ids_from_double_035__a_9():
    snippet = (
        '<record>'
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="a">INSPIRE-00134135</subfield>'
        '    <subfield code="9">INSPIRE</subfield>'
        '  </datafield>'
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="a">H.Vogel.1</subfield>'
        '    <subfield code="9">BAI</subfield>'
        '  </datafield>'
        '</record>'
    )

    expected = [
        {
            'type': 'INSPIRE ID',
            'value': 'INSPIRE-00134135',
        },
        {
            'type': 'INSPIRE BAI',
            'value': 'H.Vogel.1',
        },
    ]
    result = clean_record(hepnames.do(create_record(snippet)))

    assert expected == result['ids']
Ejemplo n.º 15
0
def test_inspire_categories_from_65017a_2_E():
    schema = load_schema('authors')
    subschema = schema['properties']['inspire_categories']

    snippet = (
        '<datafield tag="650" ind1="1" ind2="7">'
        '  <subfield code="2">INSPIRE</subfield>'
        '  <subfield code="a">E</subfield>'
        '</datafield>'
    )  # record/1019112

    expected = [
        {'term': 'Experiment-HEP'},
    ]
    result = hepnames.do(create_record(snippet))

    assert validate(result['inspire_categories'], subschema) is None
    assert expected == result['inspire_categories']

    expected = [
        {
            '2': 'INSPIRE',
            'a': 'Experiment-HEP',
        },
    ]
    result = hepnames2marc.do(result)

    assert expected == result['65017']
def test_field_from_marcxml_650_with_two_a():
    """Two 'a' subfields in one datafield.

    The first is an arXiv fieldcode an the second an INSPIRE category.
    """
    snippet = (
        '<record>'
        '  <datafield tag="650" ind1="1" ind2="7">'
        '    <subfield code="2">INSPIRE</subfield>'
        '    <subfield code="a">hep-ex</subfield>'
        '    <subfield code="a">Gravitation and Cosmology</subfield>'
        '  </datafield>'
        '</record>'
    )

    expected = [
        {
            '_scheme': 'INSPIRE',
            'scheme': 'INSPIRE',
            '_term': 'hep-ex',
            'term': 'Experiment-HEP',
        },
        {
            '_scheme': 'INSPIRE',
            'scheme': 'INSPIRE',
            '_term': 'Gravitation and Cosmology',
            'term': 'Gravitation and Cosmology',
        },
    ]
    result = clean_record(hepnames.do(create_record(snippet)))

    assert expected == result['field_categories']
def test_field_from_marcxml_650_with_single_a_and_9():
    """Simple case.

    One arXiv fieldcode that will be mapped to an INSPIRE category. Source
    will also be mapped to a standard term.
    """
    snippet = (
        '<record>'
        '  <datafield tag="650" ind1="1" ind2="7">'
        '    <subfield code="2">INSPIRE</subfield>'
        '    <subfield code="a">HEP-PH</subfield>'
        '    <subfield code="9">automatically added based on DCC, PPF, DK </subfield>'
        '  </datafield>'
        '</record>'
    )

    expected = [
        {
            'source': 'INSPIRE',
            '_scheme': 'INSPIRE',
            'scheme': 'INSPIRE',
            '_term': 'HEP-PH',
            'term': 'Phenomenology-HEP',
        },
    ]
    result = clean_record(hepnames.do(create_record(snippet)))

    assert expected == result['field_categories']
Ejemplo n.º 18
0
def convert_marcxml(source):
    """Convert MARC XML to JSON."""
    from dojson.contrib.marc21.utils import create_record, split_blob

    from inspirehep.dojson.utils import strip_empty_values
    from inspirehep.dojson.hep import hep
    from inspirehep.dojson.institutions import institutions
    from inspirehep.dojson.journals import journals
    from inspirehep.dojson.experiments import experiments
    from inspirehep.dojson.hepnames import hepnames
    from inspirehep.dojson.jobs import jobs
    from inspirehep.dojson.conferences import conferences

    for data in split_blob(source.read()):
        record = create_record(data)
        if _collection_in_record(record, 'institution'):
            yield strip_empty_values(institutions.do(record))
        elif _collection_in_record(record, 'experiment'):
            yield strip_empty_values(experiments.do(record))
        elif _collection_in_record(record, 'journals'):
            yield strip_empty_values(journals.do(record))
        elif _collection_in_record(record, 'hepnames'):
            yield strip_empty_values(hepnames.do(record))
        elif _collection_in_record(record, 'job') or \
                _collection_in_record(record, 'jobhidden'):
            yield strip_empty_values(jobs.do(record))
        elif _collection_in_record(record, 'conferences'):
            yield strip_empty_values(conferences.do(record))
        else:
            yield strip_empty_values(hep.do(record))
Ejemplo n.º 19
0
def test_ids_from_035__a_9_with_wikipedia():
    schema = load_schema('authors')
    subschema = schema['properties']['ids']

    snippet = (
        '<datafield tag="035" ind1=" " ind2=" ">'
        '  <subfield code="9">Wikipedia</subfield>'
        '  <subfield code="a">Guido_Tonelli</subfield>'
        '</datafield>'
    )  # record/985898/export/xme

    expected = [
        {
            'schema': 'WIKIPEDIA',
            'value': 'Guido_Tonelli',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert validate(result['ids'], subschema) is None
    assert expected == result['ids']

    expected = [
        {
            '9': 'WIKIPEDIA',
            'a': 'Guido_Tonelli',
        },
    ]
    result = hepnames2marc.do(result)

    assert expected == result['035']
Ejemplo n.º 20
0
def test_ids_from_035__a_with_bai():
    schema = load_schema('authors')
    subschema = schema['properties']['ids']

    snippet = (
        '<datafield tag="035" ind1=" " ind2=" ">'
        '  <subfield code="a">Jian.Long.Han.1</subfield>'
        '</datafield>'
    )  # record/1464894/export/xme

    expected = [
        {
            'schema': 'INSPIRE BAI',
            'value': 'Jian.Long.Han.1',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert validate(result['ids'], subschema) is None
    assert expected == result['ids']

    expected = [
        {
            '9': 'BAI',
            'a': 'Jian.Long.Han.1',
        },
    ]
    result = hepnames2marc.do(result)

    assert expected == result['035']
Ejemplo n.º 21
0
def test_ids_from_035__a_9_with_googlescholar():
    schema = load_schema('authors')
    subschema = schema['properties']['ids']

    snippet = (
        '<datafield tag="035" ind1=" " ind2=" ">'
        '  <subfield code="9">GoogleScholar</subfield>'
        '  <subfield code="a">Tnl-9KoAAAAJ</subfield>'
        '</datafield>'
    )  # record/1467553/export/xme

    expected = [
        {
            'schema': 'GOOGLESCHOLAR',
            'value': 'Tnl-9KoAAAAJ',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert validate(result['ids'], subschema) is None
    assert expected == result['ids']

    expected = [
        {
            '9': 'GOOGLESCHOLAR',
            'a': 'Tnl-9KoAAAAJ',
        },
    ]
    result = hepnames2marc.do(result)

    assert expected == result['035']
Ejemplo n.º 22
0
def test_ids_from_035__a_9_with_viaf():
    schema = load_schema('authors')
    subschema = schema['properties']['ids']

    snippet = (
        '<datafield tag="035" ind1=" " ind2=" ">'
        '  <subfield code="9">VIAF</subfield>'
        '  <subfield code="a">34517183</subfield>'
        '</datafield>'
    )  # record/1008109/export/xme

    expected = [
        {
            'schema': 'VIAF',
            'value': '34517183',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert validate(result['ids'], subschema) is None
    assert expected == result['ids']

    expected = [
        {
            '9': 'VIAF',
            'a': '34517183',
        },
    ]
    result = hepnames2marc.do(result)

    assert expected == result['035']
Ejemplo n.º 23
0
def test_ids_from_035__a_9_with_cern():
    schema = load_schema('authors')
    subschema = schema['properties']['ids']

    snippet = (
        '<datafield tag="035" ind1=" " ind2=" ">'
        '  <subfield code="9">CERN</subfield>'
        '  <subfield code="a">CERN-622961</subfield>'
        '</datafield>'
    )  # record/1064570/export/xme

    expected = [
        {
            'schema': 'CERN',
            'value': 'CERN-622961',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert validate(result['ids'], subschema) is None
    assert expected == result['ids']

    expected = [
        {
            '9': 'CERN',
            'a': 'CERN-622961'
        }
    ]
    result = hepnames2marc.do(result)

    assert expected == result['035']
Ejemplo n.º 24
0
def test_positions_from_371__a():
    schema = load_schema('authors')
    subschema = schema['properties']['positions']

    snippet = (
        '<datafield tag="371" ind1=" " ind2=" ">'
        '  <subfield code="a">Aachen, Tech. Hochsch.</subfield>'
        '</datafield>'
    )  # record/997958

    expected = [
        {
            'current': False,
            'institution': {
                'curated_relation': False,
                'name': 'Aachen, Tech. Hochsch.',
            },
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert validate(result['positions'], subschema) is None
    assert expected == result['positions']

    expected = [
        {'a': 'Aachen, Tech. Hochsch.'}
    ]
    result = hepnames2marc.do(result)

    assert expected == result['371']
def test_field_from_multiple_marcxml_650():
    """Two datafields.

    Both are arXiv field codes, but the other is incorrectly labeled as INSPIRE.
    """
    snippet = (
        '<record>'
        '  <datafield tag="650" ind1="1" ind2="7">'
        '    <subfield code="2">arXiv</subfield>'
        '    <subfield code="a">HEP-PH</subfield>'
        '  </datafield>'
        '  <datafield tag="650" ind1="1" ind2="7">'
        '    <subfield code="2">INSPIRE</subfield>'
        '    <subfield code="a">astro-ph.IM</subfield>'
        '  </datafield>'
        '</record>'
    )

    expected = [
        {
            '_scheme': 'arXiv',
            'scheme': 'INSPIRE',
            '_term': 'HEP-PH',
            'term': 'Phenomenology-HEP',
        },
        {
            '_scheme': 'INSPIRE',
            'scheme': 'INSPIRE',
            '_term': 'astro-ph.IM',
            'term': 'Instrumentation',
        },
    ]
    result = clean_record(hepnames.do(create_record(snippet)))

    assert expected == result['field_categories']
Ejemplo n.º 26
0
def update(recid):
    """View for INSPIRE author update form."""
    from dojson.contrib.marc21.utils import create_record
    from inspirehep.dojson.hepnames import hepnames

    data = {}
    if recid:
        try:
            url = os.path.join(cfg["AUTHORS_UPDATE_BASE_URL"], "record",
                               str(recid), "export", "xm")
            xml = requests.get(url)
            data = hepnames.do(create_record(xml.content.encode("utf-8")))
            convert_for_form(data)
        except requests.exceptions.RequestException:
            pass
        data["recid"] = recid
    else:
        return redirect(url_for("inspire_authors.new"))
    form = AuthorUpdateForm(data=data)
    ctx = {
        "action": url_for('.submitupdate'),
        "name": "authorUpdateForm",
        "id": "authorUpdateForm",
    }

    return render_template('authors/forms/update_form.html', form=form, **ctx)
Ejemplo n.º 27
0
def test_arxiv_categories_from_65017a_2():
    schema = load_schema('authors')
    subschema = schema['properties']['arxiv_categories']

    snippet = (
        '<datafield tag="650" ind1="1" ind2="7">'
        '  <subfield code="2">INSPIRE</subfield>'
        '  <subfield code="a">HEP-TH</subfield>'
        '</datafield>'
    )  # record/1010819

    expected = [
        'hep-th',
    ]
    result = hepnames.do(create_record(snippet))

    assert validate(result['arxiv_categories'], subschema) is None
    assert expected == result['arxiv_categories']

    expected = [
        {
            '2': 'arXiv',
            'a': 'hep-th',
        },
    ]
    result = hepnames2marc.do(result)

    assert expected == result['65017']
Ejemplo n.º 28
0
def test_ids_from_970__a():
    schema = load_schema('authors')
    subschema = schema['properties']['ids']

    snippet = (
        '<datafield tag="970" ind1=" " ind2=" ">'
        '  <subfield code="a">HEPNAMES-646482</subfield>'
        '</datafield>'
    )  # record/1498151

    expected = [
        {
            'schema': 'SPIRES',
            'value': 'HEPNAMES-646482',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert validate(result['ids'], subschema) is None
    assert expected == result['ids']

    expected = [
        {'a': 'HEPNAMES-646482'},
    ]
    result = hepnames2marc.do(result)

    assert expected == result['970']
Ejemplo n.º 29
0
def test_private_notes_from_595__9():
    snippet = (
        '<datafield tag="595" ind1=" " ind2=" ">'
        '  <subfield code="9">SPIRES-HIDDEN</subfield>'
        '</datafield>'
    )  # record/1005469

    assert '_private_notes' not in hepnames.do(create_record(snippet))
Ejemplo n.º 30
0
def marcxml_to_json():
    marcxml = pkg_resources.resource_string(__name__,
                                            os.path.join(
                                                'fixtures',
                                                'test_hepnames_record.xml'
                                            ))
    record = create_record(marcxml)
    return hepnames.do(record)
def test_ids_from_035__a_9_with_cern_malformed():
    snippet = (
        '<record>'
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">CERN</subfield>'
        '    <subfield code="a">CERN-CERN-645257</subfield>'
        '  </datafield>'  # record/1030771/export/xme
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">CERN</subfield>'
        '    <subfield code="a">cern-783683</subfield>'
        '  </datafield>'  # record/1408145/export/xme
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">CERN</subfield>'
        '    <subfield code="a">CERM-724319</subfield>'
        '  </datafield>'  # record/1244430/export/xme
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">CERN</subfield>'
        '    <subfield code="a">CNER-727986</subfield>'
        '  </datafield>'  # record/1068077/export/xme
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">CERN</subfield>'
        '    <subfield code="a">CVERN-765559</subfield>'
        '  </datafield>'  # record/1340631/export/xme
        '</record>'
    )

    expected = [
        {
            'type': 'CERN',
            'value': 'CERN-645257',
        },
        {
            'type': 'CERN',
            'value': 'CERN-783683',
        },
        {
            'type': 'CERN',
            'value': 'CERN-724319',
        },
        {
            'type': 'CERN',
            'value': 'CERN-727986',
        },
        {
            'type': 'CERN',
            'value': 'CERN-765559',
        },
    ]
    result = clean_record(hepnames.do(create_record(snippet)))

    assert expected == result['ids']
Ejemplo n.º 32
0
def test_ids_from_035__a_with_bai():
    snippet = ('<datafield tag="035" ind1=" " ind2=" ">'
               '  <subfield code="a">Jian.Long.Han.1</subfield>'
               '</datafield>')  # record/1464894/export/xme

    expected = [
        {
            'type': 'INSPIRE BAI',
            'value': 'Jian.Long.Han.1',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert expected == result['ids']
Ejemplo n.º 33
0
def test_ids_from_035__a_9_with_viaf():
    snippet = ('<datafield tag="035" ind1=" " ind2=" ">'
               '  <subfield code="9">VIAF</subfield>'
               '  <subfield code="a">34517183</subfield>'
               '</datafield>')  # record/1008109/export/xme

    expected = [
        {
            'type': 'VIAF',
            'value': '34517183',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert expected == result['ids']
Ejemplo n.º 34
0
def test_ids_from_035__a_9_with_slac():
    snippet = ('<datafield tag="035" ind1=" " ind2=" ">'
               '  <subfield code="9">SLAC</subfield>'
               '  <subfield code="a">SLAC-218626</subfield>'
               '</datafield>')  # record/1028379/export/xme

    expected = [
        {
            'type': 'SLAC',
            'value': 'SLAC-218626',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert expected == result['ids']
Ejemplo n.º 35
0
def test_ids_from_035__a_9_with_researcherid():
    snippet = ('<datafield tag="035" ind1=" " ind2=" ">'
               '  <subfield code="9">RESEARCHERID</subfield>'
               '  <subfield code="a">B-4717-2008</subfield>'
               '</datafield>')  # record/1051026/export/xme

    expected = [
        {
            'type': 'RESEARCHERID',
            'value': 'B-4717-2008',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert expected == result['ids']
Ejemplo n.º 36
0
def test_ids_from_035__a_9_with_scopus():
    snippet = ('<datafield tag="035" ind1=" " ind2=" ">'
               '  <subfield code="9">SCOPUS</subfield>'
               '  <subfield code="a">7103280792</subfield>'
               '</datafield>')  # record/1017182/export/xme

    expected = [
        {
            'type': 'SCOPUS',
            'value': '7103280792',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert expected == result['ids']
Ejemplo n.º 37
0
def test_other_names_from_400__triple_a():
    snippet = ('<datafield tag="400" ind1=" " ind2=" ">'
               '  <subfield code="a">Yosef Cohen, Hadar</subfield>'
               '  <subfield code="a">Josef Cohen, Hadar</subfield>'
               '  <subfield code="a">Cohen, Hadar Josef</subfield>'
               '</datafield>')  # record/1292399/export/xme

    expected = [
        'Yosef Cohen, Hadar',
        'Josef Cohen, Hadar',
        'Cohen, Hadar Josef',
    ]
    result = hepnames.do(create_record(snippet))

    assert expected == result['other_names']
Ejemplo n.º 38
0
def test_ids_from_035__a_9_with_googlescholar():
    snippet = ('<datafield tag="035" ind1=" " ind2=" ">'
               '  <subfield code="9">GoogleScholar</subfield>'
               '  <subfield code="a">Tnl-9KoAAAAJ</subfield>'
               '</datafield>')  # record/1467553/export/xme

    expected = [
        {
            'type': 'GOOGLESCHOLAR',
            'value': 'Tnl-9KoAAAAJ',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert expected == result['ids']
Ejemplo n.º 39
0
def test_ids_from_035__a_9_with_desy():
    snippet = ('<datafield tag="035" ind1=" " ind2=" ">'
               '  <subfield code="a">DESY-1001805</subfield>'
               '  <subfield code="9">DESY</subfield>'
               '</datafield>')  # record/993224/export/xme

    expected = [
        {
            'type': 'DESY',
            'value': 'DESY-1001805',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert expected == result['ids']
Ejemplo n.º 40
0
def test_ids_from_035__a_9_with_orcid():
    snippet = ('<datafield tag="035" ind1=" " ind2=" ">'
               '  <subfield code="9">ORCID</subfield>'
               '  <subfield code="a">0000-0001-6771-2174</subfield>'
               '</datafield>')

    expected = [
        {
            'type': 'ORCID',
            'value': '0000-0001-6771-2174',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert expected == result['ids']
Ejemplo n.º 41
0
def test_ids_from_035__a_9_with_wikipedia():
    snippet = ('<datafield tag="035" ind1=" " ind2=" ">'
               '  <subfield code="9">Wikipedia</subfield>'
               '  <subfield code="a">Guido_Tonelli</subfield>'
               '</datafield>')  # record/985898/export/xme

    expected = [
        {
            'type': 'WIKIPEDIA',
            'value': 'Guido_Tonelli',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert expected == result['ids']
Ejemplo n.º 42
0
def test_ids_from_035__a_9_with_cern():
    snippet = ('<datafield tag="035" ind1=" " ind2=" ">'
               '  <subfield code="9">CERN</subfield>'
               '  <subfield code="a">CERN-622961</subfield>'
               '</datafield>')  # record/1064570/export/xme

    expected = [
        {
            'type': 'CERN',
            'value': 'CERN-622961',
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert expected == result['ids']
Ejemplo n.º 43
0
def test_experiments(mock_get_record_ref, mock_get_recid_from_ref, test_name,
                     xml_snippet, expected_json, expected_marc):
    mock_get_record_ref.side_effect = \
        lambda x, *_: x and 'mocked_recid_%s' % x
    mock_get_recid_from_ref.side_effect = \
        lambda x, *_: x and int(x.rsplit('_')[-1])

    if not xml_snippet.strip().startswith('<record>'):
        xml_snippet = '<record>%s</record>' % xml_snippet

    json_data = hepnames.do(create_record(xml_snippet))
    json_experiments = json_data['experiments']
    marc_experiments = hepnames2marc.do(json_data)['693']

    assert marc_experiments == expected_marc
    assert json_experiments == expected_json
Ejemplo n.º 44
0
def test_ids_from_035__9():
    snippet = (
        '<record>'
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">INSPIRE</subfield>'
        '  </datafield>'  # record/edit/?ln=en#state=edit&recid=1474355&recrev=20160707223728
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">CERN</subfield>'
        '  </datafield>'  # record/1364570/export/xme
        '  <datafield tag="035" ind1=" " ind2=" ">'
        '    <subfield code="9">KAKEN</subfield>'
        '  </datafield>'  # record/1480252/export/xme
        '</record>')

    result = hepnames.do(create_record(snippet))

    assert 'ids' not in result
Ejemplo n.º 45
0
def test_positions_from_371__a():
    snippet = ('<datafield tag="371" ind1=" " ind2=" ">'
               '  <subfield code="a">Aachen, Tech. Hochsch.</subfield>'
               '</datafield>')  # record/997958

    expected = [
        {
            'current': False,
            'institution': {
                'curated_relation': False,
                'name': 'Aachen, Tech. Hochsch.',
            },
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert expected == result['positions']
Ejemplo n.º 46
0
def overdo_marc_dict(record):
    """Convert MARC Groupable Ordered Dict into JSON."""
    if _collection_in_record(record, 'institution'):
        return institutions.do(record)
    elif _collection_in_record(record, 'experiment'):
        return experiments.do(record)
    elif _collection_in_record(record, 'journals'):
        return journals.do(record)
    elif _collection_in_record(record, 'hepnames'):
        return hepnames.do(record)
    elif _collection_in_record(record, 'job') or \
            _collection_in_record(record, 'jobhidden'):
        return jobs.do(record)
    elif _collection_in_record(record, 'conferences'):
        return conferences.do(record)
    else:
        return hep.do(record)
Ejemplo n.º 47
0
def test_field_categories_from_650__a_2():
    snippet = (
        '<datafield tag="650" ind1="1" ind2="7">'
        '  <subfield code="2">Inspire</subfield>'
        '  <subfield code="a">Experiment-HEP</subfield>'
        '</datafield>'
    )  # record/1426196

    expected = [
        {
            '_scheme': 'Inspire',
            'scheme': 'INSPIRE',
            '_term': 'Experiment-HEP',
            'term': 'Experiment-HEP',
        },
    ]
    result = clean_record(hepnames.do(create_record(snippet)))

    assert expected == result['field_categories']
Ejemplo n.º 48
0
def test_advisors_from_701__a_g_i():
    snippet = ('<datafield tag="701" ind1=" " ind2=" ">'
               '  <subfield code="a">Rivelles, Victor O.</subfield>'
               '  <subfield code="g">PhD</subfield>'
               '  <subfield code="i">INSPIRE-00120420</subfield>'
               '  <subfield code="x">991627</subfield>'
               '  <subfield code="y">1</subfield>'
               '</datafield>')  # record/1474091

    expected = [
        {
            'name': 'Rivelles, Victor O.',
            'degree_type': 'PhD',
            '_degree_type': 'PhD',
            'record': {
                '$ref': 'http://localhost:5000/api/authors/991627',
            },
            'curated_relation': True
        },
    ]
    result = hepnames.do(create_record(snippet))

    assert expected == result['advisors']
def test_acquisition_source_field():
    """Test acquisition_source."""
    snippet = (
        '<record>'
        '   <datafield tag="541" ind1=" " ind2=" ">'
        '       <subfield code="a">inspire:uid:50000</subfield>'
        '       <subfield code="b">[email protected]</subfield>'
        '       <subfield code="c">submission</subfield>'
        '       <subfield code="d">2015-12-10</subfield>'
        '       <subfield code="e">339830</subfield>'
        '   </datafield>'
        '</record>'
    )

    expected = {
        'source': "inspire:uid:50000",
        'email': "*****@*****.**",
        'method': "submission",
        'date': "2015-12-10",
        'submission_number': "339830",
    }
    result = clean_record(hepnames.do(create_record(snippet)))

    assert expected == result['acquisition_source']
Ejemplo n.º 50
0
def test_old_single_email_from_371__a():
    snippet = ('<datafield tag="371" ind1=" " ind2=" ">'
               '   <subfield code="a">IMSc, Chennai</subfield>'
               '   <subfield code="o">[email protected]</subfield>'
               '   <subfield code="r">PD</subfield>'
               '   <subfield code="s">2012</subfield>'
               '   <subfield code="t">2013</subfield>'
               '</datafield>')  # record/1060782

    expected = [{
        "current": False,
        "old_emails": ["*****@*****.**"],
        "end_date": "2013",
        "rank": "POSTDOC",
        "institution": {
            "name": "IMSc, Chennai",
            "curated_relation": False
        },
        "_rank": "PD",
        "start_date": "2012"
    }]
    result = hepnames.do(create_record(snippet))

    assert expected == result['positions']

    expected = [{
        "a": "IMSc, Chennai",
        "o": ["*****@*****.**"],
        "s": "2012",
        "r": "PD",
        "t": "2013"
    }]

    marc = hepnames2marc.do(result)

    assert expected == marc['371']
Ejemplo n.º 51
0
def create_record(record, force=True, dry_run=False):
    """Create record from marc21 model."""
    errors = ""

    if _collection_in_record(record, 'institution'):
        json = strip_empty_values(institutions.do(record))
    elif _collection_in_record(record, 'experiment'):
        json = strip_empty_values(experiments.do(record))
    elif _collection_in_record(record, 'journals'):
        json = strip_empty_values(journals.do(record))
    elif _collection_in_record(record, 'hepnames'):
        json = strip_empty_values(hepnames.do(record))
    elif _collection_in_record(record, 'job') or \
            _collection_in_record(record, 'jobhidden'):
        json = strip_empty_values(jobs.do(record))
    elif _collection_in_record(record, 'conferences'):
        json = strip_empty_values(conferences.do(record))
    else:
        json = strip_empty_values(hep.do(record))

    if dry_run:
        return errors, json

    return json