使用Python基于BibTeX引用格式自动生成文献的IEEE引用格式
生活随笔
收集整理的這篇文章主要介紹了
使用Python基于BibTeX引用格式自动生成文献的IEEE引用格式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
說明
IEEE引用格式最近讓我很頭疼,因此為了快速解決論文格式轉化為IEEE格式,我從網上搜索到相關資料,可供大家參考:
用Python代碼自動生成文獻的IEEE引用格式
上文大概描述了如何使用python代表通過BibTeX引用格式生成文獻的IEEE引用格式,但是在使用時發現以下問題:
例如下面文獻:
使用上面文章的代碼生成的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.然而在IEEE官網推薦的文章引用格式是名在前(且只保留大寫字母),姓在后,如下所示:
B. H. Nguyen, B. Xue, P. Andreae and M. Zhang, "A Hybrid Evolutionary Computation Approach to Inducing Transfer Classifiers for Domain Adaptation," in IEEE Transactions on Cybernetics, vol. 51, no. 12, pp. 6319-6332, Dec. 2021.因此在原代碼中加入該操作。
效果如下:
B. Xue and M. Zhang, et al., "A Survey on Evolutionary Computation Approaches to Feature Selection," IEEE Transactions on Evolutionary Computation, vol. 20, no. 4, pp. 606-626, 2016.完整代碼如下:
#!/usr/bin/python3 # -*- coding: utf-8 -*- # @Time : 2022/5/30 20:17 # @Author : doFighter import redef 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 journalFormatNormaldef 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 conferenceFormatNormaldef getIeeeFormat(bibInfo):"""本函數用于根據文獻類型調用相應函數來輸出ieee文獻引用格式:param bibInfo: 提取出的BibTeX引用信息:return: ieee引用格式"""if "journal" in bibInfo: # 期刊論文return getIeeeJournalFormat(bibInfo)elif "booktitle" in bibInfo: # 會議論文return getIeeeConferenceFormat(bibInfo)# 查找名,并按格式進行縮寫 def capitalLetter(name):resName = ''for i in name:if i.isupper():resName += i + '. 'return resName# 按照bib格式,調整作者的姓名縮寫形式 def nameModefy(name):nameList = name.split(' and ')resNames = []for index in range(len(nameList)):if index > 1:breaknames = nameList[index].split(',')if len(names) < 2:continuefor i in range(len(names)):names[i] = names[i].strip()resName = capitalLetter(names[1]) + names[0]resNames.append(resName)result = ' and '.join(resNames)if len(nameList) > 2:result += ', et al.'return resultdef 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)):if result1[index] == 'author':infordir[result1[index]] = nameModefy(result2[index])else:infordir[result1[index]] = result2[index]return infordirdef inputBibTex():"""在這里輸入BibTeX格式的文獻引用信息:return:提取出的BibTeX引用信息"""bibtex = []print("請輸入BibTeX格式的文獻引用:")i = 0while i < 15: # 觀察可知BibTeX格式的文獻引用不會多于15行lines = input()if len(lines) == 0: # 如果輸入空行,則說明引用內容已經輸入完畢breakelse:bibtex.append(lines)i += 1return inforDir("".join(bibtex))if __name__ == '__main__':bibInfo = inputBibTex() # 獲得BibTeX格式的文獻引用print(getIeeeFormat(bibInfo)) # 輸出ieee格式總結
以上是生活随笔為你收集整理的使用Python基于BibTeX引用格式自动生成文献的IEEE引用格式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎么彻底删除mysql服务_mysql怎
- 下一篇: NV12截图