本文整理汇总了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'])
示例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):
#.........这里部分代码省略.........
示例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']
示例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']")