當前位置: 首頁>>代碼示例>>Python>>正文


Python Client.getRecord方法代碼示例

本文整理匯總了Python中oaipmh.client.Client.getRecord方法的典型用法代碼示例。如果您正苦於以下問題:Python Client.getRecord方法的具體用法?Python Client.getRecord怎麽用?Python Client.getRecord使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在oaipmh.client.Client的用法示例。


在下文中一共展示了Client.getRecord方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_record

# 需要導入模塊: from oaipmh.client import Client [as 別名]
# 或者: from oaipmh.client.Client import getRecord [as 別名]
def get_record(target, identifier):
    if target is not None:
        client = Client(target['url'], registry)
        record = client.getRecord(identifier=identifier, metadataPrefix=target['metadata_prefix'])
        return convert_record(record, target['metadata_prefix'], target['title'])
開發者ID:cogfor,項目名稱:oai2es,代碼行數:7,代碼來源:oaipmh_harvester.py

示例2: OaiPaperSource

# 需要導入模塊: from oaipmh.client import Client [as 別名]
# 或者: from oaipmh.client.Client import getRecord [as 別名]
class OaiPaperSource(PaperSource):  # TODO: this should not inherit from PaperSource
    """
    A paper source that fetches records from the OAI-PMH proxy
    (typically: proaixy).

    It uses the ListRecord verb to fetch records from the OAI-PMH
    source. Each record is then converted to a :class:`BarePaper`
    by an :class:`OaiTranslator` that handles the format
    the metadata is served in.
    """

    def __init__(self, oaisource, day_granularity=False, *args, **kwargs):
        """
        This sets up the paper source.

        :param oaisource: the OAISource to fetch from.
        :param day_granularity: should we use day-granular timestamps
            to fetch from the proxy or full timestamps (default: False,
            full timestamps)

        See the protocol reference for more information on timestamp
        granularity:
        https://www.openarchives.org/OAI/openarchivesprotocol.html
        """
        super(OaiPaperSource, self).__init__(*args, **kwargs)
        if not oaisource.endpoint:
            raise ValueError('No OAI endpoint was configured for this OAI source.')

        self.registry = MetadataRegistry()
        self.registry.registerReader('oai_dc', oai_dc_reader)
        self.registry.registerReader('base_dc', base_dc_reader)
        self.client = Client(oaisource.endpoint, self.registry)
        self.client._day_granularity = day_granularity
        self.translators = {
            'oai_dc': OAIDCTranslator(oaisource),
            'base_dc': BASEDCTranslator(oaisource),
        }

    # Translator management

    def add_translator(self, translator):
        """
        Adds the given translator to the paper source,
        so that we know how to translate papers in the given format.

        The paper source cannot hold more than one translator
        per OAI format (it decides what translator to use
        solely based on the format) so if there is already a translator
        for that format, it will be overriden.
        """
        self.translators[translator.format()] = translator

    # Record ingestion

    def ingest(self, from_date=None, metadataPrefix='oai_dc',
               resumptionToken=None):
        """
        Main method to fill Dissemin with papers!

        :param from_date: only fetch papers modified after that date in
                          the proxy (useful for incremental fetching)
        :param metadataPrefix: restrict the ingest for this metadata
                          format
        """
        args = {'metadataPrefix':metadataPrefix}
        if from_date:
            args['from_'] = from_date
        if resumptionToken:
            args['resumptionToken'] = resumptionToken
        records = self.client.listRecords(**args)
        self.process_records(records, metadataPrefix)

    def create_paper_by_identifier(self, identifier, metadataPrefix):
        """
        Queries the OAI-PMH proxy for a single paper.

        :param identifier: the OAI identifier to fetch
        :param metadataPrefix: the format to use (a translator
                    has to be registered for that format, otherwise
                    we return None with a warning message)
        :returns: a Paper or None
        """
        record = self.client.getRecord(
                    metadataPrefix=metadataPrefix,
                    identifier=identifier)
        return self.process_record(record[0], record[1]._map, metadataPrefix)

    # Record search utilities

    def listRecords_or_empty(self, source, *args, **kwargs):
        """
        pyoai raises :class:`NoRecordsMatchError` when no records match,
        we would rather like to get an empty list in that case.
        """
        try:
            return source.listRecords(*args, **kwargs)
        except NoRecordsMatchError:
            return []

    def process_record(self, header, metadata, format):
#.........這裏部分代碼省略.........
開發者ID:Phyks,項目名稱:dissemin,代碼行數:103,代碼來源:oai.py

示例3:

# 需要導入模塊: from oaipmh.client import Client [as 別名]
# 或者: from oaipmh.client.Client import getRecord [as 別名]
# 'marc21'

sets = oai.listSets()
for s in sets:
	print s

# 'MZK03'

recids = oai.listIdentifiers(metadataPrefix='marc21', set='MZK03') # from_='2003-01-01T00:00:00Z', until=''

# for example: 'MZK03-907223' is in the list of maps
# or 356050 *not a map

# 238208 problematic
r = oai.getRecord(identifier='MZK03-1479', metadataPrefix='marc21')

# from lxml import etree
# print etree.tostring(r[1],pretty_print=True)

# xpath_evaluator = etree.XPathEvaluator(r[1][0], namespaces={'marc21':'http://www.loc.gov/MARC21/slim'})
# e = xpath_evaluator.evaluate

#s = etree.tostring(r[1][0],pretty_print=True)

rec = r[1] # this returns parsed MARC record

# Processing of the MARC record:

# link is in
rec['856']
開發者ID:klokan,項目名稱:oldmapsonline,代碼行數:32,代碼來源:oaipmh-client.py

示例4: XMLReader

# 需要導入模塊: from oaipmh.client import Client [as 別名]
# 或者: from oaipmh.client.Client import getRecord [as 別名]
from oaipmh import metadata

registry = metadata.MetadataRegistry()
registry.registerReader('marc21', XMLReader() )

#### OAI-PMH Client processing 

from oaipmh.client import Client
from lxml import etree

oai = Client('http://snape.mzk.cz/OAI-script', registry)

#recs = oai.listRecords(metadataPrefix='marc21', set='MZK03')

#rec = recs.next()
#for rec in recs:

rec = oai.getRecord(identifier='MZK03-907223', metadataPrefix='marc21')

if rec:
	print rec[0].identifier()
	r = rec[1] # Get XML tree for record 
	print etree.tostring(r,pretty_print=True)

	if r:
		xpath_evaluator = etree.XPathEvaluator(r, namespaces={'marc':'http://www.loc.gov/MARC21/slim'})
		e = xpath_evaluator.evaluate

		print e("//marc:datafield[@tag='856']")
		print e("//marc:datafield[@tag='034']")
開發者ID:klokan,項目名稱:oldmapsonline,代碼行數:32,代碼來源:oaipmh-client-xpath.py


注:本文中的oaipmh.client.Client.getRecord方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。