• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pymarc.Record类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pymarc.Record的典型用法代码示例。如果您正苦于以下问题:Python Record类的具体用法?Python Record怎么用?Python Record使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_add_title

    def test_add_title(self):
        edition = self._edition()
        edition.title = "The Good Soldier"
        edition.sort_title = "Good Soldier, The"
        edition.subtitle = "A Tale of Passion"

        record = Record()
        Annotator.add_title(record, edition)
        [field] = record.get_fields("245")
        self._check_field(
            record, "245", {
                "a": edition.title,
                "b": edition.subtitle,
                "c": edition.author,
            }, ["0", "4"])

        # If there's no subtitle or no author, those subfields are left out.
        edition.subtitle = None
        edition.author = None

        record = Record()
        Annotator.add_title(record, edition)
        [field] = record.get_fields("245")
        self._check_field(
            record, "245", {
                "a": edition.title,
            }, ["0", "4"])
        eq_([], field.get_subfields("b"))
        eq_([], field.get_subfields("c"))
开发者ID:NYPL-Simplified,项目名称:server_core,代码行数:29,代码来源:test_marc.py


示例2: test_add_simplified_genres

    def test_add_simplified_genres(self):
        work = self._work(with_license_pool=True)
        fantasy, ignore = Genre.lookup(self._db, "Fantasy", autocreate=True)
        romance, ignore = Genre.lookup(self._db, "Romance", autocreate=True)
        work.genres = [fantasy, romance]

        record = Record()
        Annotator.add_simplified_genres(record, work)
        fields = record.get_fields("650")
        [fantasy_field, romance_field] = sorted(fields, key=lambda x: x.get_subfields("a")[0])
        eq_(["0", "7"], fantasy_field.indicators)
        eq_("Fantasy", fantasy_field.get_subfields("a")[0])
        eq_("Library Simplified", fantasy_field.get_subfields("2")[0])
        eq_(["0", "7"], romance_field.indicators)
        eq_("Romance", romance_field.get_subfields("a")[0])
        eq_("Library Simplified", romance_field.get_subfields("2")[0])

        # It also works with a materialized work.
        self.add_to_materialized_view([work])
        # The work is in the materialized view twice since it has two genres,
        # but we can use either one.
        [mw, ignore] = self._db.query(MaterializedWorkWithGenre).all()

        record = Record()
        Annotator.add_simplified_genres(record, mw)
        fields = record.get_fields("650")
        [fantasy_field, romance_field] = sorted(fields, key=lambda x: x.get_subfields("a")[0])
        eq_(["0", "7"], fantasy_field.indicators)
        eq_("Fantasy", fantasy_field.get_subfields("a")[0])
        eq_("Library Simplified", fantasy_field.get_subfields("2")[0])
        eq_(["0", "7"], romance_field.indicators)
        eq_("Romance", romance_field.get_subfields("a")[0])
        eq_("Library Simplified", romance_field.get_subfields("2")[0])
开发者ID:NYPL-Simplified,项目名称:server_core,代码行数:33,代码来源:test_marc.py


示例3: test_add_series

    def test_add_series(self):
        edition = self._edition()
        edition.series = self._str
        edition.series_position = 5
        record = Record()
        Annotator.add_series(record, edition)
        self._check_field(record, "490", {
            "a": edition.series,
            "v": str(edition.series_position),
        }, ["0", " "])

        # If there's no series position, the same field is used without
        # the v subfield.
        edition.series_position = None
        record = Record()
        Annotator.add_series(record, edition)
        self._check_field(record, "490", {
            "a": edition.series,
        }, ["0", " "])
        [field] = record.get_fields("490")
        eq_([], field.get_subfields("v"))

        # If there's no series, the field is left out.
        edition.series = None
        record = Record()
        Annotator.add_series(record, edition)
        eq_([], record.get_fields("490"))
开发者ID:NYPL-Simplified,项目名称:server_core,代码行数:27,代码来源:test_marc.py


示例4: test_add_contributors

    def test_add_contributors(self):
        author = "a"
        author2 = "b"
        translator = "c"

        # Edition with one author gets a 100 field and no 700 fields.
        edition = self._edition(authors=[author])
        edition.sort_author = "sorted"

        record = Record()
        Annotator.add_contributors(record, edition)
        eq_([], record.get_fields("700"))
        self._check_field(record, "100", {"a": edition.sort_author}, ["1", " "])

        # Edition with two authors and a translator gets three 700 fields and no 100 fields.
        edition = self._edition(authors=[author, author2])
        edition.add_contributor(translator, Contributor.TRANSLATOR_ROLE)

        record = Record()
        Annotator.add_contributors(record, edition)
        eq_([], record.get_fields("100"))
        fields = record.get_fields("700")
        for field in fields:
            eq_(["1", " "], field.indicators)
        [author_field, author2_field, translator_field] = sorted(fields, key=lambda x: x.get_subfields("a")[0])
        eq_(author, author_field.get_subfields("a")[0])
        eq_(Contributor.PRIMARY_AUTHOR_ROLE, author_field.get_subfields("e")[0])
        eq_(author2, author2_field.get_subfields("a")[0])
        eq_(Contributor.AUTHOR_ROLE, author2_field.get_subfields("e")[0])
        eq_(translator, translator_field.get_subfields("a")[0])
        eq_(Contributor.TRANSLATOR_ROLE, translator_field.get_subfields("e")[0])
开发者ID:NYPL-Simplified,项目名称:server_core,代码行数:31,代码来源:test_marc.py


示例5: test_add_physical_description

    def test_add_physical_description(self):
        book = self._edition()
        book.medium = Edition.BOOK_MEDIUM
        audio = self._edition()
        audio.medium = Edition.AUDIO_MEDIUM

        record = Record()
        Annotator.add_physical_description(record, book)
        self._check_field(record, "300", {"a": "1 online resource"})
        self._check_field(record, "336", {
            "a": "text",
            "b": "txt",
            "2": "rdacontent",
        })
        self._check_field(record, "337", {
            "a": "computer",
            "b": "c",
            "2": "rdamedia",
        })
        self._check_field(record, "338", {
            "a": "online resource",
            "b": "cr",
            "2": "rdacarrier",
        })
        self._check_field(record, "347", {
            "a": "text file",
            "2": "rda",
        })
        self._check_field(record, "380", {
            "a": "eBook",
            "2": "tlcgt",
        })

        record = Record()
        Annotator.add_physical_description(record, audio)
        self._check_field(record, "300", {
            "a": "1 sound file",
            "b": "digital",
        })
        self._check_field(record, "336", {
            "a": "spoken word",
            "b": "spw",
            "2": "rdacontent",
        })
        self._check_field(record, "337", {
            "a": "computer",
            "b": "c",
            "2": "rdamedia",
        })
        self._check_field(record, "338", {
            "a": "online resource",
            "b": "cr",
            "2": "rdacarrier",
        })
        self._check_field(record, "347", {
            "a": "audio file",
            "2": "rda",
        })
        eq_([], record.get_fields("380"))
开发者ID:NYPL-Simplified,项目名称:server_core,代码行数:59,代码来源:test_marc.py


示例6: test_unicode

    def test_unicode(self):
        record = Record()
        record.add_field(Field(245, ['1', '0'], ['a', unichr(0x1234)]))
        writer = MARCWriter(open('test/foo', 'w'))
        writer.write(record)
        writer.close()

        reader = MARCReader(open('test/foo'))
        record = reader.next()
        self.assertEqual(record['245']['a'], unichr(0x1234))
开发者ID:mattgrayson,项目名称:pymarc,代码行数:10,代码来源:marc8.py


示例7: create_record

    def create_record(cls, work, annotator, force_create=False, integration=None):
        """Build a complete MARC record for a given work."""
        if callable(annotator):
            annotator = annotator()

        if isinstance(work, BaseMaterializedWork):
            pool = work.license_pool
        else:
            pool = work.active_license_pool()
        if not pool:
            return None

        edition = pool.presentation_edition
        identifier = pool.identifier

        _db = Session.object_session(work)

        record = None
        existing_record = getattr(work, annotator.marc_cache_field)
        if existing_record and not force_create:
            record = Record(data=existing_record.encode('utf-8'), force_utf8=True)

        if not record:
            record = Record(leader=annotator.leader(work), force_utf8=True)
            annotator.add_control_fields(record, identifier, pool, edition)
            annotator.add_isbn(record, identifier)

            # TODO: The 240 and 130 fields are for translated works, so they can be grouped even
            # though they have different titles. We do not group editions of the same work in
            # different languages, so we can't use those yet.

            annotator.add_title(record, edition)
            annotator.add_contributors(record, edition)
            annotator.add_publisher(record, edition)
            annotator.add_physical_description(record, edition)
            annotator.add_audience(record, work)
            annotator.add_series(record, edition)
            annotator.add_system_details(record)
            annotator.add_ebooks_subject(record)

            data = record.as_marc()
            if isinstance(work, BaseMaterializedWork):
                setattr(pool.work, annotator.marc_cache_field, data)
            else:
                setattr(work, annotator.marc_cache_field, data)

        # Add additional fields that should not be cached.
        annotator.annotate_work_record(work, pool, edition, identifier, record, integration)

        return record
开发者ID:NYPL-Simplified,项目名称:server_core,代码行数:50,代码来源:marc.py


示例8: sort_6_subs

def sort_6_subs(rec):
	msg = ''
	new_rec = Record(to_unicode=True, force_utf8=True)
	new_rec_fields = []
	rec_fields = rec.get_fields()
	for field in rec_fields:
		script_field = False
		if not field.is_control_field() and (len(field.get_subfields('6')) > 0):	# the field contains a subfield $6
			script_field = True
			ind1 = field.indicator1
			ind2 = field.indicator2
			tag = field.tag
			first_sub = True		# variable to keep track of whether you're on the first subfield in the field
			needs_sorted = True		# variable to keep track of whether the field needs sorted or if the $6 is already correctly the first subfield
			field_subs = []			# list variable to capture all the subfields in the field *except* for the subfield $6
			for subfield in field:
				# check if $6 is the first subfield - if so, the field is OK and does *not* need to be sorted
				if needs_sorted and first_sub and subfield[0] == '6':
					needs_sorted = False
				
				elif needs_sorted:
					if first_sub:
						# this is the first subfield and is *not* $6, so the field needs sorted - creates one instance of a new_field object only when the 1st subfield is encountered
						new_field = Field(tag=tag, indicators=[ind1,ind2], subfields=[])
					
					# when subfield $6 is finally encountered in the field (not the 1st), add it to the new_field object now so it becomes the first subfield
					# Note: subfield[0] is the subfield code and subfield[1] is the subfield content for this subfield
					if subfield[0]=='6':
						new_field.add_subfield(subfield[0],subfield[1])
					
					# if the subfield is *not* $6, add it to the list of subfields to be added later to the new_field
					else:
						field_subs.append([subfield[0],subfield[1]])
				
				first_sub = False
			
			if needs_sorted:
				# then the $6 was *not* the 1st subfield and we need to now add the remaining subfields to the new_field object
				for sub in field_subs:
					# add the remaining subfields to the new_field object
					new_field.add_subfield(sub[0],sub[1])
				new_rec_fields.append(new_field)	# add the new field to the record
		
		if not script_field or not needs_sorted:
			new_rec_fields.append(field)
	
	for new_f in new_rec_fields:
		new_rec.add_field(new_f)
	
	return new_rec
开发者ID:NYULibraries,项目名称:aco-karms,代码行数:50,代码来源:aco_functions.py


示例9: test_writing_unicode

    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', 'wb'))
        writer.write(record)
        writer.close()

        reader = MARCReader(open('test/foo', 'rb'), to_unicode=True)
        record = next(reader)
        self.assertEqual(record['245']['a'], unichr(0x1234))
        reader.close()

        os.remove('test/foo')
开发者ID:EdwardBetts,项目名称:pymarc,代码行数:14,代码来源:marc8.py


示例10: writeMetadataToMarc

def writeMetadataToMarc(data, MARCMapping, saveLocation):
    record = Record()
    for key in data:
        if key in MARCMapping:
            if(key == u'UUID'):
                field = Field(
                    tag = MARCMapping[key],
                    data = data[key])
            else:
		field = Field(
			tag = MARCMapping[key][:3],
			subfields = [MARCMapping[key][3], data[key]],
			indicators=['0', '0'])  
            record.add_field(field)
    writeRecordToFile(record, filename)
开发者ID:JamieJQuinn,项目名称:baobab-scripts,代码行数:15,代码来源:scraperUtil.py


示例11: faulty015

def faulty015(record: Record) -> bool:
    found = False
    for f in record.get_fields("015"):
        if "a" in f:
            if len(f["a"].split(' ')) > 1:
                found = True
    return found
开发者ID:tvirolai,项目名称:MARC-scripts,代码行数:7,代码来源:findErroneous.py


示例12: empty020a

def empty020a(record: Record) -> bool:
    sf020a = []
    if "020" in record:
        fields = record.get_fields("020")
        for f in fields:
            if "a" in f:
                sf020a.append(f.get_subfields("a").pop())
    return sf020a == [""]
开发者ID:tvirolai,项目名称:MARC-scripts,代码行数:8,代码来源:findErroneous.py


示例13: __next__

 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
开发者ID:termim,项目名称:pymarc,代码行数:17,代码来源:reader.py


示例14: test_add_formats

    def test_add_formats(self):
        edition, pool = self._edition(with_license_pool=True)
        epub_no_drm, ignore = DeliveryMechanism.lookup(
            self._db, Representation.EPUB_MEDIA_TYPE, DeliveryMechanism.NO_DRM)
        pool.delivery_mechanisms[0].delivery_mechanism = epub_no_drm
        LicensePoolDeliveryMechanism.set(
            pool.data_source, pool.identifier, Representation.PDF_MEDIA_TYPE,
            DeliveryMechanism.ADOBE_DRM, RightsStatus.IN_COPYRIGHT)

        record = Record()
        Annotator.add_formats(record, pool)
        fields = record.get_fields("538")
        eq_(2, len(fields))
        [pdf, epub] = sorted(fields, key=lambda x: x.get_subfields("a")[0])
        eq_("Adobe PDF eBook", pdf.get_subfields("a")[0])
        eq_([" ", " "], pdf.indicators)
        eq_("EPUB eBook", epub.get_subfields("a")[0])
        eq_([" ", " "], epub.indicators)
开发者ID:NYPL-Simplified,项目名称:server_core,代码行数:18,代码来源:test_marc.py


示例15: periodsMissing

def periodsMissing(record: Record) -> bool:
    fields = record.get_fields("100", "110", "700", "710")
    for f in fields:
        if "e" in f:
            functions = f.get_subfields("e")
            for func in functions:
                if func[-1].isalpha():
                    return True
    return False
开发者ID:tvirolai,项目名称:MARC-scripts,代码行数:9,代码来源:findErroneous.py


示例16: phrasesInFields

def phrasesInFields(record: Record, phrases: list, fields: list) -> bool:
    '''Takes a record object, a list of strings and a list of fields (as strings).
    Returns a boolean.'''
    for f in fields:
        for rf in record.get_fields(f):
            for p in phrases:
                if p in rf.value().lower():
                    return True
    return False
开发者ID:tvirolai,项目名称:MARC-scripts,代码行数:9,代码来源:findErroneous.py


示例17: decode_record

    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. &#59;|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
开发者ID:anarchivist,项目名称:iiitools,代码行数:59,代码来源:iiitools.py


示例18: test_add_publisher

    def test_add_publisher(self):
        edition = self._edition()
        edition.publisher = self._str
        edition.issued = datetime.datetime(1894, 4, 5)

        record = Record()
        Annotator.add_publisher(record, edition)
        self._check_field(
            record, "264", {
                "a": "[Place of publication not identified]",
                "b": edition.publisher,
                "c": "1894",
            }, [" ", "1"])

        # If there's no publisher, the field is left out.
        record = Record()
        edition.publisher = None
        Annotator.add_publisher(record, edition)
        eq_([], record.get_fields("264"))
开发者ID:NYPL-Simplified,项目名称:server_core,代码行数:19,代码来源:test_marc.py


示例19: test_add_isbn

    def test_add_isbn(self):
        isbn = self._identifier(identifier_type=Identifier.ISBN)
        record = Record()
        Annotator.add_isbn(record, isbn)
        self._check_field(record, "020", {"a": isbn.identifier})

        # If the identifier isn't an ISBN, but has an equivalent that is, it still
        # works.
        equivalent = self._identifier()
        data_source = DataSource.lookup(self._db, DataSource.OCLC)
        equivalent.equivalent_to(data_source, isbn, 1)
        record = Record()
        Annotator.add_isbn(record, equivalent)
        self._check_field(record, "020", {"a": isbn.identifier})

        # If there is no ISBN, the field is left out.
        non_isbn = self._identifier()
        record = Record()
        Annotator.add_isbn(record, non_isbn)
        eq_([], record.get_fields("020"))
开发者ID:NYPL-Simplified,项目名称:server_core,代码行数:20,代码来源:test_marc.py


示例20: textIn020z

def textIn020z(record: Record) -> bool:
    sf020z = []
    if "020" in record:
        fields = record.get_fields("020")
        for f in fields:
            if "z" in f:
                sf020z.append(f.get_subfields("z").pop())
    if len(sf020z) > 0:
        alpha = 0
        for f in sf020z:
            alpha += len([x for x in f if x.isalpha()])
        return alpha > 1
    return False
开发者ID:tvirolai,项目名称:MARC-scripts,代码行数:13,代码来源:findErroneous.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python record.Record类代码示例发布时间:2022-05-25
下一篇:
Python proxies.threadsafe_call函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap