用Python代码自动生成文献的IEEE引用格式的实现
作者:白水baishui 发布时间:2021-05-26 15:24:49
今天尝试着将引用文献的格式按照IEEE的标准重新排版,感觉手动一条一条改太麻烦,而且很容易出错,所以尝试着用Python写了一个小程序用于根据BibTeX引用格式来生成IEEE引用格式。
先看代码,如下:
import re
def getIeeeJournalFormat(bibInfo):
"""
生成期刊文献的IEEE引用格式:{作者}, "{文章标题}," {期刊名称}, vol. {卷数}, no. {编号}, pp. {页码}, {年份}.
:return: {author}, "{title}," {journal}, vol. {volume}, no. {number}, pp. {pages}, {year}.
"""
# 避免字典出现null值
if "volume" not in bibInfo:
bibInfo["volume"] = "null"
if "number" not in bibInfo:
bibInfo["number"] = "null"
if "pages" not in bibInfo:
bibInfo["pages"] = "null"
journalFormat = bibInfo["author"] + \
", \"" + bibInfo["title"] + \
",\" " + bibInfo["journal"] + \
", vol. " + bibInfo["volume"] + \
", no. " + bibInfo["number"] + \
", pp. " + bibInfo["pages"] + \
", " + bibInfo["year"] + "."
# 对格式进行调整,去掉没有的信息,调整页码格式
journalFormatNormal = journalFormat.replace(", vol. null", "")
journalFormatNormal = journalFormatNormal.replace(", no. null", "")
journalFormatNormal = journalFormatNormal.replace(", pp. null", "")
journalFormatNormal = journalFormatNormal.replace("--", "-")
return journalFormatNormal
def getIeeeConferenceFormat(bibInfo):
"""
生成会议文献的IEEE引用格式:{作者}, "{文章标题}, " in {会议名称}, {年份}, pp. {页码}.
:return: {author}, "{title}, " in {booktitle}, {year}, pp. {pages}.
"""
conferenceFormat = bibInfo["author"] + \
", \"" + bibInfo["title"] + ",\" " + \
", in " + bibInfo["booktitle"] + \
", " + bibInfo["year"] + \
", pp. " + bibInfo["pages"] + "."
# 对格式进行调整,,调整页码格式
conferenceFormatNormal = conferenceFormat.replace("--", "-")
return conferenceFormatNormal
def getIeeeFormat(bibInfo):
"""
本函数用于根据文献类型调用相应函数来输出ieee文献引用格式
:param bibInfo: 提取出的BibTeX引用信息
:return: ieee引用格式
"""
if "journal" in bibInfo: # 期刊论文
return getIeeeJournalFormat(bibInfo)
elif "booktitle" in bibInfo: # 会议论文
return getIeeeConferenceFormat(bibInfo)
def inforDir(bibtex):
#pattern = "[\w]+={[^{}]+}" 用正则表达式匹配符合 ...={...} 的字符串
pattern1 = "[\w]+=" # 用正则表达式匹配符合 ...= 的字符串
pattern2 = "{[^{}]+}" # 用正则表达式匹配符合 内层{...} 的字符串
# 找到所有的...=,并去除=号
result1 = re.findall(pattern1, bibtex)
for index in range(len(result1)) :
result1[index] = re.sub('=', '', result1[index])
# 找到所有的{...},并去除{和}号
result2 = re.findall(pattern2, bibtex)
for index in range(len(result2)) :
result2[index] = re.sub('\{', '', result2[index])
result2[index] = re.sub('\}', '', result2[index])
# 创建BibTeX引用字典,归档所有有效信息
infordir = {}
for index in range(len(result1)):
infordir[result1[index]] = result2[index]
return infordir
def inputBibTex():
"""
在这里输入BibTeX格式的文献引用信息
:return:提取出的BibTeX引用信息
"""
bibtex = []
print("请输入BibTeX格式的文献引用:")
i = 0
while i < 15: # 观察可知BibTeX格式的文献引用不会多于15行
lines = input()
if len(lines) == 0: # 如果输入空行,则说明引用内容已经输入完毕
break
else:
bibtex.append(lines)
i += 1
return inforDir("".join(bibtex))
if __name__ == '__main__':
bibInfo = inputBibTex() # 获得BibTeX格式的文献引用
print(getIeeeFormat(bibInfo)) # 输出ieee格式
下面我来详细说说这个代码怎么使用。
首先,我们需要获取到文献的BibTeX引用格式,可以在百度学术,或者谷歌学术的应用栏中找到,例如这里以谷歌学术举例:
在搜索框搜索论文:Reinforcement learning to rank in e-commerce search engine: Formalization, analysis, and application
,跳转到以下页面:
点击“引用”,再点击“BibTex”
跳转到以下页面,复制所有字符串
运行我们上面给出的代码,在交互窗口把我们复制的字符串粘贴过去:
之后点击两下回车,即可得到IEEE格式的文献引用了:
这里我分了会议论文和期刊论文种格式,大家如果想要其他引用格式,可以在我的代码的基础上进行增删改,下面我放一些引用格式转换的例子:
会议论文1:
Reinforcement learning to rank in e-commerce search engine: Formalization, analysis, and application
BibTeX格式:
@inproceedings{hu2018reinforcement,
title={Reinforcement learning to rank in e-commerce search engine: Formalization, analysis, and application},
author={Hu, Yujing and Da, Qing and Zeng, Anxiang and Yu, Yang and Xu, Yinghui},
booktitle={Proceedings of the 24th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining},
pages={368–377},
year={2018}
}
IEEE格式:
Hu, Yujing and Da, Qing and Zeng, Anxiang and Yu, Yang and Xu, Yinghui, “Reinforcement learning to rank in e-commerce search engine: Formalization, analysis, and application,” , in Proceedings of the 24th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining, 2018, pp. 368-377.
会议论文2:
A contextual-bandit approach to personalized news article recommendation
BibTeX格式:
@inproceedings{li2010contextual,
title={A contextual-bandit approach to personalized news article recommendation},
author={Li, Lihong and Chu, Wei and Langford, John and Schapire, Robert E},
booktitle={Proceedings of the 19th international conference on World wide web},
pages={661–670},
year={2010}
}
IEEE格式:
Li, Lihong and Chu, Wei and Langford, John and Schapire, Robert E, “A contextual-bandit approach to personalized news article recommendation,” , in Proceedings of the 19th international conference on World wide web, 2010, pp. 661-670.
期刊论文1:
Infrared navigation-Part I: An assessment of feasibility
BibTeX格式:
@article{duncombe1959infrared,
title={Infrared navigation—Part I: An assessment of feasibility},
author={Duncombe, JU},
journal={IEEE Trans. Electron Devices},
volume={11},
number={1},
pages={34–39},
year={1959}
}
IEEE格式:
Duncombe, JU, “Infrared navigation—Part I: An assessment of feasibility,” IEEE Trans. Electron Devices, vol. 11, no. 1, pp. 34-39, 1959.
期刊论文2(arXiv):
Reinforcement learning for slate-based recommender systems: A tractable decomposition and practical methodology
BibTeX格式:
@article{ie2019reinforcement,
title={Reinforcement learning for slate-based recommender systems: A tractable decomposition and practical methodology},
author={Ie, Eugene and Jain, Vihan and Wang, Jing and Narvekar, Sanmit and Agarwal, Ritesh and Wu, Rui and Cheng, Heng-Tze and Lustman, Morgane and Gatto, Vince and Covington, Paul and others},
journal={arXiv preprint arXiv:1905.12767},
year={2019}
}
IEEE格式:
Ie, Eugene and Jain, Vihan and Wang, Jing and Narvekar, Sanmit and Agarwal, Ritesh and Wu, Rui and Cheng, Heng-Tze and Lustman, Morgane and Gatto, Vince and Covington, Paul and others, “Reinforcement learning for slate-based recommender systems: A tractable decomposition and practical methodology,” arXiv preprint arXiv:1905.12767, 2019.
来源:https://blog.csdn.net/baishuiniyaonulia/article/details/114026471


猜你喜欢
- var arr=['a','b','c'];若要删除其中的'b',有两种方法
- PHP下载图片后文件打开显示损坏问题用php写个图片下载方法,测试发现下载的图片大小都没问题,但是无法打开文件。解决方法如下:首先打开文件下
- Python中try块可以捕获测试代码块中的错误。except块可以处理错误。finally块可以执行代码,而不管try-和except块的
- 文件处理流程1.打开文件,得到文件句柄并赋值给一个变量2.通过句柄对文件进行操作3.关闭文件 r模式,默认模式,文件不存在则报错w
- 设计页面时,经常会从一个页面打开一个子窗口以供浏览者查看。通常,这种子窗口中的内容一经浏览者看过,对于浏览者而言就不再需要,而他们常常会忘记
- 有两个简单的方法MySQL中的数据加载到MySQL数据库从先前备份的文件。LOAD DATA导入数据:MySQL提供了LOAD DATA语句
- 起步在 《分布式任务队列Celery使用说明》 中介绍了在 Python 中使用 Celery 来实验异步任务和定时任务功能。本文介绍如何在
- PyQt5中QInputDialog的使用,Qt的QInputDialog类提供了一种简单方面的对话框来获得用户的单个输入信息,它提供了4种
- 在pycharm中,当调用( import / from … import… )其他文件夹下的函数或模块,会发现编辑器无法识别( can n
- 一:前言刚看了一篇软文,说什么“才华是改变人生最有效的途径”,反正呢,大体就是科技进步,要想一直在车
- 1. 定义节点// Node 定义节点type Node struct { Data any
- 1. 上下文管理器是什么?举个例子,你在写Python代码的时候经常将一系列操作放在一个语句块中:(1)当某条件为真 – 执行这个语句块(2
- 先思考一些问题:它是做什么的、以及怎么使用它。带着这些问题往下走。consul是做什么的consul用于微服务下的服务治理。服务治理是什么?
- anaconda用法:查看已经安装的包:pip list 或者 conda list安装和更新:pip install requestspi
- declare @t varchar(255),@c varchar(255) declare table_cursor cursor fo
- 本文实例为大家分享了OpenCV+face++实现实时人脸识别解锁功能的具体代码,供大家参考,具体内容如下1.背景最近做一个小东西,需要登录
- 利用卷积神经网络训练图像数据分为以下几个步骤1.读取图片文件2.产生用于训练的批次3.定义训练的模型(包括初始化参数,卷积、池化层等参数、网
- queue配置首先说明一下我之前的项目中如何使用queue的。我们现在的项目都是用的symfony,老一点的项目用的symfony1.4,新
- 今天我去隽辰的博客去看他的文章,在读完他的文章之后,我很自然的就去读网友们给他留的评论,在读的时候我发现他的评论是顺序的,也就是最早的评论在
- 如何在网上查找链接? 见下:findlinks.html<html><head>