当前位置: 首页>>代码示例>>Python>>正文


Python RecordIndexer._prepare_record方法代码示例

本文整理汇总了Python中invenio_indexer.api.RecordIndexer._prepare_record方法的典型用法代码示例。如果您正苦于以下问题:Python RecordIndexer._prepare_record方法的具体用法?Python RecordIndexer._prepare_record怎么用?Python RecordIndexer._prepare_record使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在invenio_indexer.api.RecordIndexer的用法示例。


在下文中一共展示了RecordIndexer._prepare_record方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_replace_refs

# 需要导入模块: from invenio_indexer.api import RecordIndexer [as 别名]
# 或者: from invenio_indexer.api.RecordIndexer import _prepare_record [as 别名]
def test_replace_refs(app):
    """Test replace refs."""
    app.config['INDEXER_REPLACE_REFS'] = False
    app.extensions['invenio-records'].loader_cls = json_loader_factory(
            JSONResolver(plugins=['demo.json_resolver']))

    with app.app_context():
        record = Record({'$ref': 'http://dx.doi.org/10.1234/foo'})
        data = RecordIndexer._prepare_record(record, 'records', 'record')
        assert '$ref' in data

    app.config['INDEXER_REPLACE_REFS'] = True
    with app.app_context():
        record = Record({'$ref': 'http://dx.doi.org/10.1234/foo'})
        data = RecordIndexer._prepare_record(record, 'records', 'record')
        assert '$ref' not in data
        assert json.dumps(data)
开发者ID:hachreak,项目名称:invenio-indexer,代码行数:19,代码来源:test_api.py

示例2: create_index_op

# 需要导入模块: from invenio_indexer.api import RecordIndexer [as 别名]
# 或者: from invenio_indexer.api.RecordIndexer import _prepare_record [as 别名]
def create_index_op(record):
    index, doc_type = current_record_to_index(record)

    return {
        '_op_type': 'index',
        '_index': index,
        '_type': doc_type,
        '_id': str(record.id),
        '_version': record.revision_id,
        '_version_type': 'external_gte',
        '_source': RecordIndexer._prepare_record(record, index, doc_type),
    }
开发者ID:david-caro,项目名称:inspire-next,代码行数:14,代码来源:tasks.py

示例3: test_records_serializers_marc

# 需要导入模块: from invenio_indexer.api import RecordIndexer [as 别名]
# 或者: from invenio_indexer.api.RecordIndexer import _prepare_record [as 别名]
def test_records_serializers_marc(app, test_records_data):
    with app.app_context():
        pid, record = make_record(test_records_data)
        rec = {
            '_source': RecordIndexer._prepare_record(
                record, 'records', 'record'
            ).copy(),
            '_version': record.revision_id
        }
        marcxml = oaipmh_marc21_v1(pid=pid, record=rec)

        namespaces = {'m':'http://www.loc.gov/MARC21/slim'}

        def marc_controlfields(tag):
            xpath = '//m:controlfield[@tag="{}"]'.format(tag)
            elements = marcxml.xpath(xpath, namespaces=namespaces)
            return [x.text for x in elements]

        def marc_datafields(tag, subfield_code):
            xpath = '//m:datafield[@tag="{}"]/m:subfield[@code="{}"]'.format(
                tag, subfield_code)
            elements = marcxml.xpath(xpath, namespaces=namespaces)
            return [x.text for x in elements]

        def marc_files():
            xpath = '//m:datafield[@tag="856" and @ind1="4"]/m:subfield[@code="u"]'
            elements = marcxml.xpath(xpath, namespaces=namespaces)
            return [x.text for x in elements]

        creators_and_contributors = [r['creator_name'] for r in record['creators']]
        creators_and_contributors.extend([r['contributor_name']
                                          for r in record['contributors']])

        assert marc_controlfields('001') == [pid.pid_value]

        assert marc_datafields('100', 'a') == creators_and_contributors[:1]
        assert marc_datafields('245', 'a') == [r['title'] for r in record['titles']]
        assert marc_datafields('260', 'b') == [record['publisher']]
        assert marc_datafields('260', 'c') == [record['publication_date']]
        assert marc_datafields('337', 'a') == [
            r['resource_type_general'] for r in record['resource_types']]
        assert marc_datafields('520', 'a') == [r['description'] for r in record['descriptions']]
        assert marc_datafields('526', 'a') == record.get('disciplines')
        assert marc_datafields('540', 'a') == [record.get('license', {}).get('license')]
        assert marc_datafields('542', 'l') == ['open' if record['open_access'] else 'closed']
        assert marc_datafields('546', 'a') == [record['language']]
        assert marc_datafields('653', 'a') == record.get('keywords')
        assert marc_datafields('700', 'a') == creators_and_contributors[1:]

        assert marc_files() == [f['ePIC_PID'] for f in record.get('_files')]
开发者ID:EUDAT-B2SHARE,项目名称:b2share,代码行数:52,代码来源:test_records_serializers.py

示例4: create_index_op

# 需要导入模块: from invenio_indexer.api import RecordIndexer [as 别名]
# 或者: from invenio_indexer.api.RecordIndexer import _prepare_record [as 别名]
def create_index_op(record, version_type='external_gte'):
    from inspirehep.modules.records.receivers import enhance_before_index
    index, doc_type = current_record_to_index(record)
    enhance_before_index(record)

    return {
        '_op_type': 'index',
        '_index': index,
        '_type': doc_type,
        '_id': str(record.id),
        '_version': record.revision_id,
        '_version_type': version_type,
        '_source': RecordIndexer._prepare_record(record, index, doc_type),
    }
开发者ID:harunurhan,项目名称:inspire-next,代码行数:16,代码来源:record.py

示例5: test_records_serializers_dc

# 需要导入模块: from invenio_indexer.api import RecordIndexer [as 别名]
# 或者: from invenio_indexer.api.RecordIndexer import _prepare_record [as 别名]
def test_records_serializers_dc(app, test_records_data):
    with app.app_context():
        pid, record = make_record(test_records_data)
        rec = {
            '_source': RecordIndexer._prepare_record(
                record, 'records', 'record'
            ).copy(),
            '_version': record.revision_id
        }
        dcxml = oaipmh_oai_dc(pid=pid, record=rec)

        namespaces = {'dc':'http://purl.org/dc/elements/1.1/'}
        identifiers = dcxml.xpath('//dc:identifier', namespaces=namespaces)
        titles = dcxml.xpath('//dc:title', namespaces=namespaces)
        creators = dcxml.xpath('//dc:creator', namespaces=namespaces)
        descriptions = dcxml.xpath('//dc:description', namespaces=namespaces)
        subjects = dcxml.xpath('//dc:subject', namespaces=namespaces)
        contributors = dcxml.xpath('//dc:contributor', namespaces=namespaces)
        rights = dcxml.xpath('//dc:rights', namespaces=namespaces)
        publishers = dcxml.xpath('//dc:publisher', namespaces=namespaces)
        languages = dcxml.xpath('//dc:language', namespaces=namespaces)
        types = dcxml.xpath('//dc:type', namespaces=namespaces)

        assert identifiers
        for x in identifiers:
            assert x.text.endswith(pid.pid_value)

        assert [x.text for x in titles] == [r['title'] for r in record['titles']]
        assert [x.text for x in creators] == [r['creator_name'] for r in record['creators']]
        assert [x.text for x in descriptions] == [r['description'] for r in record['descriptions']]
        assert [x.text for x in types] == [
            r['resource_type_general'] for r in record['resource_types']]
        assert [x.text for x in contributors] == [
            r['contributor_name'] for r in record['contributors']]
        assert [x.text for x in publishers] == [record['publisher']]
        assert [x.text for x in languages] == [record['language']]

        assert [x.text for x in subjects] == record.get('keywords')

        rights = [x.text for x in rights]
        access = 'info:eu-repo/semantics/closedAccess'
        if record['open_access']:
            access = 'info:eu-repo/semantics/openAccess'
        assert access in rights
        license = record.get('license', {}).get('license')
        if license:
            assert license in rights
开发者ID:EUDAT-B2SHARE,项目名称:b2share,代码行数:49,代码来源:test_records_serializers.py


注:本文中的invenio_indexer.api.RecordIndexer._prepare_record方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。