コード例 #1
0
ファイル: bd90x99x.py プロジェクト: jacenkow/inspire-next
    def get_value(value):
        # Retrieve fields as described here:
        # https://twiki.cern.ch/twiki/bin/view/Inspire/DevelopmentRecordMarkup.
        rb = ReferenceBuilder()
        mapping = [
            ('o', rb.set_number),
            ('m', rb.add_misc),
            ('x', partial(rb.add_raw_reference, source='dojson')),
            ('1', rb.set_texkey),
            ('u', rb.add_url),
            ('r', rb.add_report_number),
            ('s', rb.set_pubnote),
            ('p', rb.set_publisher),
            ('y', rb.set_year),
            ('i', rb.add_uid),
            ('b', rb.add_uid),
            ('a', rb.add_uid),
            ('c', rb.add_collaboration),
            ('q', rb.add_title),
            ('t', rb.add_title),
            ('h', rb.add_refextract_authors_str),
            ('e', partial(rb.add_author, role='ed.'))
        ]

        for field, method in mapping:
            for element in force_force_list(value.get(field)):
                if element:
                    method(element)

        if '0' in value:
            recid = get_int_value(value, '0')
            rb.set_record(get_record_ref(recid, 'literature'))

        return rb.obj
コード例 #2
0
def test_curation():
    rb = ReferenceBuilder()
    rb.set_record({'$ref': 'http://example.com'})

    assert rb.obj == {'record': {'$ref': 'http://example.com'},
                      'curated_relation': False}

    rb.curate()
    assert rb.obj == {'record': {'$ref': 'http://example.com'},
                      'curated_relation': True}
コード例 #3
0
    def get_value(value):
        # Retrieve fields as described here:
        # https://twiki.cern.ch/twiki/bin/view/Inspire/DevelopmentRecordMarkup.
        rb = ReferenceBuilder()
        mapping = [('o', rb.set_number), ('m', rb.add_misc),
                   ('x', partial(rb.add_raw_reference, source='dojson')),
                   ('1', rb.set_texkey), ('u', rb.add_url),
                   ('r', rb.add_report_number), ('s', rb.set_pubnote),
                   ('p', rb.set_publisher), ('y', rb.set_year),
                   ('i', rb.add_uid), ('b', rb.add_uid), ('a', rb.add_uid),
                   ('c', rb.add_collaboration), ('q', rb.add_title),
                   ('t', rb.add_title), ('h', rb.add_refextract_authors_str),
                   ('e', partial(rb.add_author, role='ed.'))]

        for field, method in mapping:
            for element in force_force_list(value.get(field)):
                if element:
                    method(element)

        if '0' in value:
            recid = get_int_value(value, '0')
            rb.set_record(get_record_ref(recid, 'literature'))

        return rb.obj
コード例 #4
0
def test_curation():
    rb = ReferenceBuilder()
    rb.set_record({'$ref': 'http://example.com'})

    assert rb.obj == {
        'record': {
            '$ref': 'http://example.com'
        },
        'curated_relation': False
    }

    rb.curate()
    assert rb.obj == {
        'record': {
            '$ref': 'http://example.com'
        },
        'curated_relation': True
    }
コード例 #5
0
def test_reference_builder_add_uid():
    rb = ReferenceBuilder()
    rb.add_uid(None)
    rb.add_uid('')
    rb.add_uid('thisisarandomstring')

    # arXiv eprint variations
    rb.add_uid('hep-th/0603001')
    rb.add_uid('0705.0017 [something-th]')
    # isbn
    rb.add_uid('1449344852')
    # cnum
    rb.add_uid('C87-11-11')
    # doi
    rb.add_uid('http://dx.doi.org/10.3972/water973.0145.db')
    # handle
    rb.add_uid('hdl:10443/1646')

    expected = {
        'arxiv_eprints': ['arXiv:hep-th/0603001', 'arXiv:0705.0017'],
        'publication_info': {
            'isbn': '978-1-4493-4485-6',
            'cnum': 'C87-11-11',
            'doi': '10.3972/water973.0145.db'
        },
        'persistent_identifiers': ['hdl:10443/1646']
    }

    assert expected == rb.obj
コード例 #6
0
def test_reference_builder_no_uids():
    rb = ReferenceBuilder()
    rb.set_number('oops')
    rb.set_number('1')
    rb.set_texkey('book')
    rb.add_title('Awesome Paper')
    rb.add_raw_reference('[1] Awesome Paper', 'arXiv')
    rb.add_misc('misc 0')
    rb.add_misc('misc 1')
    rb.add_author('Cox, Brian')
    rb.add_author('O Briain, Dara', 'ed.')
    rb.set_pubnote('Nucl.Phys.,B360,362')
    rb.set_pubnote('BAD PUBNOTE')
    rb.set_year('oops')
    rb.set_year('1991')
    rb.add_url('http://example.com')

    rb.set_publisher('Elsevier')
    rb.add_collaboration('ALICE')

    rb.add_report_number('hep-th/0603001')
    rb.add_report_number('hep-th/0603002')
    rb.add_report_number('arXiv:0705.0016 [hep-th]')
    rb.add_report_number('0705.0017 [hep-th]')
    rb.add_report_number('NOT ARXIV')

    expected = {
        'number': 1,
        'texkey': 'book',
        'titles': [{'title': 'Awesome Paper'}],
        'raw_reference': [
            {'value': '[1] Awesome Paper', 'format': 'text',
             'source': 'arXiv'},
            {'value': 'BAD PUBNOTE', 'format': 'text',
             'source': 'reference_builder'}
        ],
        'misc': ['misc 0', 'misc 1'],
        'authors': [{'full_name': 'Cox, Brian'},
                    {'full_name': 'O Briain, Dara', 'role': 'ed.'}],
        'publication_info': {
            'journal_title': 'Nucl.Phys.',
            'journal_volume': 'B360',
            'page_start': '362',
            'artid': '362',
            'reportnumber': 'NOT ARXIV',
            'year': 1991
        },
        'collaboration': ['ALICE'],
        'imprint': {'publisher': 'Elsevier'},
        'arxiv_eprints': ['arXiv:hep-th/0603001', 'arXiv:hep-th/0603002',
                          'arXiv:0705.0016', 'arXiv:0705.0017'],
        'urls': [{'value': 'http://example.com'}]
    }

    assert expected == rb.obj
コード例 #7
0
def test_reference_builder_no_uids():
    rb = ReferenceBuilder()
    rb.set_number('oops')
    rb.set_number('1')
    rb.set_texkey('book')
    rb.add_title('Awesome Paper')
    rb.add_raw_reference('[1] Awesome Paper', 'arXiv')
    rb.add_misc('misc 0')
    rb.add_misc('misc 1')
    rb.add_author('Cox, Brian')
    rb.add_author('O Briain, Dara', 'ed.')
    rb.set_pubnote('Nucl.Phys.,B360,362')
    rb.set_pubnote('BAD PUBNOTE')
    rb.set_year('oops')
    rb.set_year('1991')
    rb.add_url('http://example.com')

    rb.set_publisher('Elsevier')
    rb.add_collaboration('ALICE')

    rb.add_report_number('hep-th/0603001')
    rb.add_report_number('hep-th/0603002')
    rb.add_report_number('arXiv:0705.0016 [hep-th]')
    rb.add_report_number('0705.0017 [hep-th]')
    rb.add_report_number('NOT ARXIV')

    expected = {
        "reference": {
            "texkey":
            "book",
            "collaboration": ["ALICE"],
            "arxiv_eprints": [
                "arXiv:hep-th/0603001", "arXiv:hep-th/0603002",
                "arXiv:0705.0016", "arXiv:0705.0017"
            ],
            "misc": ["misc 0", "misc 1"],
            "number":
            1,
            "imprint": {
                "publisher": "Elsevier"
            },
            "titles": [{
                "title": "Awesome Paper"
            }],
            "urls": [{
                "value": "http://example.com"
            }],
            "authors": [{
                "full_name": "Cox, Brian"
            }, {
                "role": "ed.",
                "full_name": "O Briain, Dara"
            }],
            "publication_info": {
                "journal_title": "Nucl.Phys.",
                "journal_volume": "B360",
                "reportnumber": "NOT ARXIV",
                "artid": "362",
                "year": 1991,
                "page_start": "362"
            }
        },
        "raw_refs": [{
            "source": "arXiv",
            "value": "[1] Awesome Paper",
            "schema": "text"
        }, {
            "source": "reference_builder",
            "value": "BAD PUBNOTE",
            "schema": "text"
        }]
    }

    assert expected == rb.obj
コード例 #8
0
def test_reference_builder_add_uid():
    rb = ReferenceBuilder()
    rb.add_uid(None)
    rb.add_uid('')
    rb.add_uid('thisisarandomstring')

    # arXiv eprint variations
    rb.add_uid('hep-th/0603001')
    rb.add_uid('0705.0017 [something-th]')
    # isbn
    rb.add_uid('1449344852')
    # cnum
    rb.add_uid('C87-11-11')
    # doi
    rb.add_uid('http://dx.doi.org/10.3972/water973.0145.db')
    # handle
    rb.add_uid('hdl:10443/1646')

    expected = {
        'reference': {
            'arxiv_eprints': ['arXiv:hep-th/0603001', 'arXiv:0705.0017'],
            'publication_info': {
                'isbn': '978-1-4493-4485-6',
                'cnum': 'C87-11-11',
            },
            'dois': ['10.3972/water973.0145.db'],
            'persistent_identifiers': ['hdl:10443/1646']
        }
    }

    assert expected == rb.obj
コード例 #9
0
def test_reference_builder_no_uids():
    rb = ReferenceBuilder()
    rb.set_number('oops')
    rb.set_number('1')
    rb.set_texkey('book')
    rb.add_title('Awesome Paper')
    rb.add_raw_reference('[1] Awesome Paper', 'arXiv')
    rb.add_misc('misc 0')
    rb.add_misc('misc 1')
    rb.add_author('Cox, Brian')
    rb.add_author('O Briain, Dara', 'ed.')
    rb.set_pubnote('Nucl.Phys.,B360,362')
    rb.set_pubnote('BAD PUBNOTE')
    rb.set_year('oops')
    rb.set_year('1991')
    rb.add_url('http://example.com')

    rb.set_publisher('Elsevier')
    rb.add_collaboration('ALICE')

    rb.add_report_number('hep-th/0603001')
    rb.add_report_number('hep-th/0603002')
    rb.add_report_number('arXiv:0705.0016 [hep-th]')
    rb.add_report_number('0705.0017 [hep-th]')
    rb.add_report_number('NOT ARXIV')

    expected = {
        "reference": {
            "texkey": "book",
            "collaboration": [
                "ALICE"
            ],
            "arxiv_eprints": [
                "arXiv:hep-th/0603001",
                "arXiv:hep-th/0603002",
                "arXiv:0705.0016",
                "arXiv:0705.0017"
            ],
            "misc": [
                "misc 0",
                "misc 1"
            ],
            "number": 1,
            "imprint": {
                "publisher": "Elsevier"
            },
            "titles": [
                {
                    "title": "Awesome Paper"
                }
            ],
            "urls": [
                {
                    "value": "http://example.com"
                }
            ],
            "authors": [
                {
                    "full_name": "Cox, Brian"
                },
                {
                    "role": "ed.",
                    "full_name": "O Briain, Dara"
                }
            ],
            "publication_info": {
                "journal_title": "Nucl.Phys.",
                "journal_volume": "B360",
                "reportnumber": "NOT ARXIV",
                "artid": "362",
                "year": 1991,
                "page_start": "362"
            }
        },
        "raw_refs": [
            {
                "source": "arXiv",
                "value": "[1] Awesome Paper",
                "schema": "text"
            },
            {
                "source": "reference_builder",
                "value": "BAD PUBNOTE",
                "schema": "text"
            }
        ]
    }

    assert expected == rb.obj
コード例 #10
0
def test_reference_builder_no_uids():
    rb = ReferenceBuilder()
    rb.set_number('oops')
    rb.set_number('1')
    rb.set_texkey('book')
    rb.add_title('Awesome Paper')
    rb.add_raw_reference('[1] Awesome Paper', 'arXiv')
    rb.add_misc('misc 0')
    rb.add_misc('misc 1')
    rb.add_author('Cox, Brian')
    rb.add_author('O Briain, Dara', 'ed.')
    rb.set_pubnote('Nucl.Phys.,B360,362')
    rb.set_pubnote('BAD PUBNOTE')
    rb.set_year('oops')
    rb.set_year('1991')
    rb.add_url('http://example.com')

    rb.set_publisher('Elsevier')
    rb.add_collaboration('ALICE')

    rb.add_report_number('hep-th/0603001')
    rb.add_report_number('hep-th/0603002')
    rb.add_report_number('arXiv:0705.0016 [hep-th]')
    rb.add_report_number('0705.0017 [hep-th]')
    rb.add_report_number('NOT ARXIV')

    expected = {
        'number':
        1,
        'texkey':
        'book',
        'titles': [{
            'title': 'Awesome Paper'
        }],
        'raw_reference': [{
            'value': '[1] Awesome Paper',
            'format': 'text',
            'source': 'arXiv'
        }, {
            'value': 'BAD PUBNOTE',
            'format': 'text',
            'source': 'reference_builder'
        }],
        'misc': ['misc 0', 'misc 1'],
        'authors': [{
            'full_name': 'Cox, Brian'
        }, {
            'full_name': 'O Briain, Dara',
            'role': 'ed.'
        }],
        'publication_info': {
            'journal_title': 'Nucl.Phys.',
            'journal_volume': 'B360',
            'page_start': '362',
            'artid': '362',
            'reportnumber': 'NOT ARXIV',
            'year': 1991
        },
        'collaboration': ['ALICE'],
        'imprint': {
            'publisher': 'Elsevier'
        },
        'arxiv_eprints': [
            'arXiv:hep-th/0603001', 'arXiv:hep-th/0603002', 'arXiv:0705.0016',
            'arXiv:0705.0017'
        ],
        'urls': [{
            'value': 'http://example.com'
        }]
    }

    assert expected == rb.obj