本文整理汇总了Python中pymarc.Record.leader方法的典型用法代码示例。如果您正苦于以下问题:Python Record.leader方法的具体用法?Python Record.leader怎么用?Python Record.leader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymarc.Record
的用法示例。
在下文中一共展示了Record.leader方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decode_record
# 需要导入模块: from pymarc import Record [as 别名]
# 或者: from pymarc.Record import leader [as 别名]
def decode_record(self, record):
r"""
>>> reader = Reader('http://opac.uthsc.edu', 2)
>>> raw = "\nLEADER 00000cas 2200517 a 4500 \n001 1481253 \n003 OCoLC \n005 19951109120000.0 \n008 750727c19589999fr qrzp b 0 b0fre d \n010 sn 86012727 \n022 0003-3995 \n030 AGTQAH \n035 0062827|bMULS|aPITT NO. 0639600000|asa64872000|bFULS \n040 MUL|cMUL|dFUL|dOCL|dCOO|dNYG|dHUL|dSER|dAIP|dNST|dAGL|dDLC\n |dTUM \n041 0 engfre|bgeritaspa \n042 nsdp \n049 TUMS \n069 1 A32025000 \n210 0 Ann. genet. \n222 0 Annales de genetique \n229 00 Annales de genetique \n229 Ann Genet \n242 00 Annals on genetics \n245 00 Annales de genetique. \n260 Paris :|bExpansion scientifique,|c1958-2004. \n300 v. :|bill. ;|c28 cm. \n310 Quarterly \n321 Two no. a year \n362 0 1,1958-47,2004. \n510 1 Excerpta medica \n510 1 Index medicus|x0019-3879 \n510 2 Biological abstracts|x0006-3169 \n510 2 Chemical abstracts|x0009-2258 \n510 2 Life sciences collection \n510 0 Bulletin signaletique \n510 0 Current contents \n546 French and English, with summaries in German, Italian, and\n Spanish. \n550 Journal of the Societe francaise de genetique. \n650 2 Genetics|vPeriodicals. \n710 2 Societ\xe9 fran\xe7aise de genetique. \n785 00 |tEuropean journal of medical genetics. \n856 41 |uhttp://library.uthsc.edu/ems/eresource/3581|zFull text \n at ScienceDirect: 43(1) Jan 2000 - 47(4) Dec 2004 \n936 Unknown|ajuin 1977 \n"
>>> record = reader.decode_record(raw)
>>> print record.title
Annales de genetique
"""
pseudo_marc = record.strip().split('\n')
raw_fields = []
if pseudo_marc[0][0:6] == 'LEADER':
record = Record()
record.leader = pseudo_marc[0][7:].strip()
else:
return None
for field in pseudo_marc[1:]:
tag = field[:3]
data = unescape_entities(field[6:].decode('latin1')).encode('utf8')
if tag.startswith(' '):
# Additional field data needs to be prepended with an extra space
# for certain fields ...
#for special_tag in ('55','260'):
# data = " %s" % (data,) if tag.startswith(special_tag) else data
data = " %s" % (data.strip(),)
raw_fields[-1]['value'] = "%s%s" % (raw_fields[-1]['value'], data)
raw_fields[-1]['raw'] = "%s%s" % (raw_fields[-1]['raw'], field.strip())
else:
data = data if (tag < '010' and tag.isdigit()) else "a%s" % (data,)
raw_fields.append({
'tag': tag,
'indicator1': field[3],
'indicator2': field[4],
'value': data.strip(),
'raw': field.strip()
})
for raw in raw_fields:
tag = raw['tag']
data = raw['value'].strip()
field = Field(tag=tag, indicators=[raw['indicator1'], raw['indicator2']], data=data)
if not field.is_control_field():
for sub in data.split('|'):
try:
field.add_subfield(sub[0].strip(), sub[1:].strip())
except Exception:
# Skip blank/empty subfields
continue
record.add_field(field)
record.parse_leader()
# Disregard record if no title present
if not record.get_fields('245'):
return None
else:
return record
示例2: test_writing_unicode
# 需要导入模块: from pymarc import Record [as 别名]
# 或者: from pymarc.Record import leader [as 别名]
def test_writing_unicode(self):
record = Record()
record.add_field(Field(245, ['1', '0'], ['a', unichr(0x1234)]))
record.leader = ' a '
writer = MARCWriter(open('test/foo', 'w'))
writer.write(record)
writer.close()
reader = MARCReader(open('test/foo'), to_unicode=True)
record = reader.next()
self.assertEqual(record['245']['a'], unichr(0x1234))
os.remove('test/foo')
示例3: __next__
# 需要导入模块: from pymarc import Record [as 别名]
# 或者: from pymarc.Record import leader [as 别名]
def __next__(self):
jobj = next(self.iter)
rec = Record()
rec.leader = jobj['leader']
for field in jobj['fields']:
k,v = list(field.items())[0]
if 'subfields' in v and hasattr(v,'update'):
# flatten m-i-j dict to list in pymarc
subfields = []
for sub in v['subfields']:
for code,value in sub.items():
subfields.extend((code,value))
fld = Field(tag=k,subfields=subfields,indicators=[v['ind1'], v['ind2']])
else:
fld = Field(tag=k,data=v)
rec.add_field(fld)
return rec
示例4: epub_to_marc
# 需要导入模块: from pymarc import Record [as 别名]
# 或者: from pymarc.Record import leader [as 别名]
def epub_to_marc(fname, conf_file=None):
ns = {
'n': 'urn:oasis:names:tc:opendocument:xmlns:container',
'pkg': 'http://www.idpf.org/2007/opf',
'dc': 'http://purl.org/dc/elements/1.1/'
}
# prepare to read from the .epub file
zip = zipfile.ZipFile(fname)
# find the contents metafile
txt = zip.read('META-INF/container.xml')
tree = etree.fromstring(txt)
for el in tree:
for elel in el:
for item in elel.items():
if item[0] == 'full-path':
cfname = item[1]
# grab the metadata block from the contents metafile
cf = zip.read(cfname)
tree = etree.fromstring(cf)
p = tree.xpath('/pkg:package/pkg:metadata',namespaces=ns)[0]
# Read from the config file
conf = configparser.ConfigParser()
if conf_file:
conf.read(conf_file)
else:
conf.read_string(DEFAULT_CONF)
leader_dict = {}
tag_005_dict = {}
tag_006_dict = {}
tag_007_dict = {}
tag_008_dict = {}
tag_040_dict = {}
tag_264_dict = {}
sections = conf.sections()
for section in sections:
if section == 'leader':
for option in conf.options(section):
leader_dict[option] = conf.get(section, option)
elif section == '006':
for option in conf.options(section):
tag_006_dict[option] = conf.get(section, option)
elif section == '007':
for option in conf.options(section):
tag_007_dict[option] = conf.get(section, option)
elif section == '008':
for option in conf.options(section):
tag_008_dict[option] = conf.get(section, option)
elif section == '040':
for option in conf.options(section):
tag_040_dict[option] = conf.get(section, option)
elif section == '264':
for option in conf.options(section):
tag_264_dict[option] = conf.get(section, option)
record = Record(force_utf8=True)
# set the leader
record.leader = build_leader(leader_dict)
# I *think* it's updating the 'Base Address of Data' position when
# it is written to file, so I have kept characters 12-16 blank.
# Field 005
record.add_field(Field(tag='005', data=build_tag_005()))
# Field 006
record.add_field(Field(tag='006', data=build_tag_006(tag_006_dict,
tag_008_dict)))
# Field 007
record.add_field(Field(tag='007', data=build_tag_007(tag_007_dict)))
# Field 008
record.add_field(Field(tag='008', data=build_tag_008(tag_008_dict,
p, ns)))
# Field 020
if p.xpath('dc:identifier[@id="ISBN"]/text()', namespaces=ns):
epub_isbn = p.xpath(
'dc:identifier[@id="ISBN"]/text()', namespaces=ns)[0].strip()
epub_field = Field(
tag = '020',
indicators = [' ', ' '],
subfields = ['a', epub_isbn, 'q', 'epub']
)
elif p.xpath('dc:identifier[@pkg:scheme="ISBN"]/text()', namespaces=ns):
epub_isbn = p.xpath(
'dc:identifier[@pkg:scheme="ISBN"]/text()', namespaces=ns)[0].strip()
epub_field = Field(
tag = '020',
indicators = [' ', ' '],
subfields = ['a', epub_isbn, 'q', 'epub']
)
# Field 040
# First, check if the indicators are empty and if they are,
# turn them into single spaces.
for value in ('indicator_1', 'indicator_2'):
if tag_040_dict[value] == '':
tag_040_dict[value] = ' '
record.add_field(Field(
#.........这里部分代码省略.........
示例5: book_to_mark21_file
# 需要导入模块: from pymarc import Record [as 别名]
# 或者: from pymarc.Record import leader [as 别名]
def book_to_mark21_file(book,owner, xml = False):
#New record
record = Record()
# Number and value explanation : http://www.loc.gov/marc/bibliographic/bdleader.html
# Adding Leader tags
l = list(record.leader)
l[5] = 'n' # New
l[6] = 'a' #For manuscript file use 't'
l[7] = 'm' # Monograph
l[9] = 'a'
l[19] = '#'
record.leader = "".join(l)
# Category of material - Text
record.add_field(record_control_field('007','t'))
#Languages
languages = book.languages.all()
if languages:
for lang in languages:
record.add_field(record_control_field('008',lang.code))
else:
record.add_field(record_control_field('008','eng'))
#ISBN - International Standard Book Number
isbn = models.Identifier.objects.filter(book=book).exclude(identifier='pub_id').exclude(identifier='urn').exclude(identifier='doi')
for identifier in isbn:
if book.book_type:
record.add_field(record_field('020',['#','#'],['a', str(identifier.value)+' '+book.book_type]))
else:
record.add_field(record_field('020',['#','#'],['a', str(identifier.value)]))
#Source of acquisition
try:
base_url = models.Setting.objects.get(group__name='general', name='base_url').value
except:
base_url='localhost:8000'
book_url = 'http://%s/editor/submission/%s/' % (base_url, book.id)
record.add_field(record_field('030',['#','#'],['b', book_url]))
# Main entry - Personal name
authors = book.author.all()
author_names=''
for author in authors:
auhtor_names=author_names+author.full_name()+' '
name=author.last_name+', '+author.first_name
if author.middle_name:
name=name+' '+author.middle_name[:1]+'.'
record.add_field(record_field('100',['1','#'],['a', name]))
#Title statement
title_words = (book.title).split(' ')
first_word = title_words[0]
if first_word.lower() == 'the':
record.add_field(record_field('245',['1','4'],['a', book.title,'c',author_names]))
else:
record.add_field(record_field('245',['1','0'],['a', book.title,'c',author_names]))
#Publication
try:
press_name = models.Setting.objects.get(group__name='general', name='press_name').value
except:
press_name=None
try:
city = models.Setting.objects.get(group__name='general', name='city').value
except:
city = None
publication_info=[]
if book.publication_date:
#Press' city
if city :
publication_info.append('a')
publication_info.append(str(city))
#Press' name
if press_name:
publication_info.append('b')
publication_info.append(str(press_name))
#Date of Publication
publication_info.append('c')
publication_info.append(str(book.publication_date))
record.add_field(record_field('260',['#','#'],publication_info))
#Physical details
if book.pages:
record.add_field(record_field('300',['#','#'],['a',str(book.pages)+' pages']))
#Content type
record.add_field(record_field('336',['#','#'],['a', 'text','2','rdacontent']))
#Media type
record.add_field(record_field('337',['#','#'],['a', 'unmediated','2','rdamedia']))
#Carrier type
record.add_field(record_field('338',['#','#'],['a', 'volume','2','rdacarrier']))
#Language note
if languages:
for lang in languages:
#.........这里部分代码省略.........