RIS参考文件的Python读写器
risp的Python项目详细描述
一个python3.6+的RIS参考文件的读写器。在
使用
正在分析:
>>>importos>>>frompprintimportpprint>>>importrispy>>>filepath='tests/data/example_full.ris'>>>withopen(filepath,'r')asbibliography_file:...entries=rispy.load(bibliography_file)...forentryinentries:...print(entry['id'])...print(entry['first_authors'])12345['Marx, Karl','Lindgren, Astrid']12345['Marxus, Karlus','Lindgren, Astrid']
写作:
^{pr2}$一些RIS文件包含额外的元数据,默认情况下这些元数据将在解析过程中引发异常。要忽略不是RIS规范正式组成部分的元数据,可以使用可选的strict标志:
>>>frompathlibimportPath>>>importrispy>>>p=Path('tests/data/example_extraneous_data.ris')>>>print("\n".join(p.read_text().splitlines()[:10]))Record#1 of 2Provider:ProviderContent:text/plain;charset="UTF-8"1.TY-JOURID-12345T1-TitleofreferenceA1-Marx,KarlA1-Lindgren,AstridA2-Glattauer,Daniel>>>entries=rispy.load(p,strict=False)>>>print(entries[0]['id'])12345
RIS条目示例
1. TY - JOUR ID - 12345 T1 - Title of reference A1 - Marx, Karl A1 - Lindgren, Astrid A2 - Glattauer, Daniel Y1 - 2014// N2 - BACKGROUND: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. RESULTS: Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. CONCLUSIONS: Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. KW - Pippi KW - Nordwind KW - Piraten JF - Lorem JA - lorem VL - 9 IS - 3 SP - e0815 CY - United States PB - Fun Factory PB - Fun Factory USA SN - 1932-6208 M1 - 1008150341 L2 - http://example.com ER -
标记键映射
大多数字段包含字符串值,但有些字段(如first_authors(A1))被解析为列表。默认映射是根据分散在网络上的规范创建的,但据我们所知,没有一个单一的RIS真相来源,因此可能需要针对特定的导出系统对其进行修改:
完成默认映射
>>>fromrispy.configimportTAG_KEY_MAPPING>>>pprint(TAG_KEY_MAPPING){'A1':'first_authors','A2':'secondary_authors','A3':'tertiary_authors','A4':'subsidiary_authors','AB':'abstract','AD':'author_address','AN':'accession_number','AU':'authors','C1':'custom1','C2':'custom2','C3':'custom3','C4':'custom4','C5':'custom5','C6':'custom6','C7':'custom7','C8':'custom8','CA':'caption','CN':'call_number','CY':'place_published','DA':'date','DB':'name_of_database','DO':'doi','DP':'database_provider','EP':'end_page','ER':'end_of_reference','ET':'edition','ID':'id','IS':'number','J2':'alternate_title1','JA':'alternate_title2','JF':'alternate_title3','JO':'journal_name','KW':'keywords','L1':'file_attachments1','L2':'file_attachments2','L4':'figure','LA':'language','LB':'label','M1':'note','M3':'type_of_work','N1':'notes','N2':'notes_abstract','NV':'number_of_volumes','OP':'original_publication','PB':'publisher','PY':'year','RI':'reviewed_item','RN':'research_notes','RP':'reprint_edition','SE':'section','SN':'issn','SP':'start_page','ST':'short_title','T1':'primary_title','T2':'secondary_title','T3':'tertiary_title','TA':'translated_author','TI':'title','TT':'translated_title','TY':'type_of_reference','UK':'unknown_tag','UR':'url','VL':'volume','Y1':'publication_year','Y2':'access_date'}
覆盖键映射
解析器使用TAG_KEY_MAPPING,可以通过使用自定义映射调用rispy.load()来覆盖它。在
>>>importos>>>fromcopyimportdeepcopy>>>importrispy>>>frompprintimportpprint>>>filepath='tests/data/example_full.ris'>>>mapping=deepcopy(rispy.TAG_KEY_MAPPING)>>>mapping["SP"]="pages_this_is_my_fun">>>withopen(filepath,'r')asbibliography_file:...entries=rispy.load(bibliography_file,mapping=mapping)...pprint(sorted(entries[0].keys()))['alternate_title2','alternate_title3','file_attachments2','first_authors','id','issn','keywords','note','notes_abstract','number','pages_this_is_my_fun','place_published','primary_title','publication_year','publisher','secondary_authors','type_of_reference','url','volume']
显影剂说明书
常见的开发人员命令位于提供的Makefile中;如果没有安装make,则可以查看make命令并从命令行手动运行命令:
# setup environment python -m venv venv source venv/bin/activate pip install -e .[dev,test]# check if code format changes are required make lint # reformat code make format # run tests make test
Github操作当前已启用,可以在提交请求时运行lint和test。在
- 项目
标签: