用Python代碼自動(dòng)生成文獻(xiàn)的IEEE引用格式的實(shí)現(xiàn)
今天嘗試著將引用文獻(xiàn)的格式按照IEEE的標(biāo)準(zhǔn)重新排版,感覺(jué)手動(dòng)一條一條改太麻煩,而且很容易出錯(cuò),所以嘗試著用Python寫了一個(gè)小程序用于根據(jù)BibTeX引用格式來(lái)生成IEEE引用格式。
先看代碼,如下:
import re def getIeeeJournalFormat(bibInfo): """ 生成期刊文獻(xiàn)的IEEE引用格式:{作者}, "{文章標(biāo)題}," {期刊名稱}, vol. {卷數(shù)}, no. {編號(hào)}, pp. {頁(yè)碼}, {年份}. :return: {author}, "{title}," {journal}, vol. {volume}, no. {number}, pp. {pages}, {year}. """ # 避免字典出現(xiàn)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"] + "." # 對(duì)格式進(jìn)行調(diào)整,去掉沒(méi)有的信息,調(diào)整頁(yè)碼格式 journalFormatNormal = journalFormat.replace(", vol. null", "") journalFormatNormal = journalFormatNormal.replace(", no. null", "") journalFormatNormal = journalFormatNormal.replace(", pp. null", "") journalFormatNormal = journalFormatNormal.replace("--", "-") return journalFormatNormal def getIeeeConferenceFormat(bibInfo): """ 生成會(huì)議文獻(xiàn)的IEEE引用格式:{作者}, "{文章標(biāo)題}, " in {會(huì)議名稱}, {年份}, pp. {頁(yè)碼}. :return: {author}, "{title}, " in {booktitle}, {year}, pp. {pages}. """ conferenceFormat = bibInfo["author"] + \ ", \"" + bibInfo["title"] + ",\" " + \ ", in " + bibInfo["booktitle"] + \ ", " + bibInfo["year"] + \ ", pp. " + bibInfo["pages"] + "." # 對(duì)格式進(jìn)行調(diào)整,,調(diào)整頁(yè)碼格式 conferenceFormatNormal = conferenceFormat.replace("--", "-") return conferenceFormatNormal def getIeeeFormat(bibInfo): """ 本函數(shù)用于根據(jù)文獻(xiàn)類型調(diào)用相應(yīng)函數(shù)來(lái)輸出ieee文獻(xiàn)引用格式 :param bibInfo: 提取出的BibTeX引用信息 :return: ieee引用格式 """ if "journal" in bibInfo: # 期刊論文 return getIeeeJournalFormat(bibInfo) elif "booktitle" in bibInfo: # 會(huì)議論文 return getIeeeConferenceFormat(bibInfo) def inforDir(bibtex): #pattern = "[\w]+={[^{}]+}" 用正則表達(dá)式匹配符合 ...={...} 的字符串 pattern1 = "[\w]+=" # 用正則表達(dá)式匹配符合 ...= 的字符串 pattern2 = "{[^{}]+}" # 用正則表達(dá)式匹配符合 內(nèi)層{...} 的字符串 # 找到所有的...=,并去除=號(hào) result1 = re.findall(pattern1, bibtex) for index in range(len(result1)) : result1[index] = re.sub('=', '', result1[index]) # 找到所有的{...},并去除{和}號(hào) result2 = re.findall(pattern2, bibtex) for index in range(len(result2)) : result2[index] = re.sub('\{', '', result2[index]) result2[index] = re.sub('\}', '', result2[index]) # 創(chuàng)建BibTeX引用字典,歸檔所有有效信息 infordir = {} for index in range(len(result1)): infordir[result1[index]] = result2[index] return infordir def inputBibTex(): """ 在這里輸入BibTeX格式的文獻(xiàn)引用信息 :return:提取出的BibTeX引用信息 """ bibtex = [] print("請(qǐng)輸入BibTeX格式的文獻(xiàn)引用:") i = 0 while i < 15: # 觀察可知BibTeX格式的文獻(xiàn)引用不會(huì)多于15行 lines = input() if len(lines) == 0: # 如果輸入空行,則說(shuō)明引用內(nèi)容已經(jīng)輸入完畢 break else: bibtex.append(lines) i += 1 return inforDir("".join(bibtex)) if __name__ == '__main__': bibInfo = inputBibTex() # 獲得BibTeX格式的文獻(xiàn)引用 print(getIeeeFormat(bibInfo)) # 輸出ieee格式
下面我來(lái)詳細(xì)說(shuō)說(shuō)這個(gè)代碼怎么使用。
首先,我們需要獲取到文獻(xiàn)的BibTeX引用格式,可以在百度學(xué)術(shù),或者谷歌學(xué)術(shù)的應(yīng)用欄中找到,例如這里以谷歌學(xué)術(shù)舉例:
在搜索框搜索論文:Reinforcement learning to rank in e-commerce search engine: Formalization, analysis, and application
,跳轉(zhuǎn)到以下頁(yè)面:
點(diǎn)擊“引用”,再點(diǎn)擊“BibTex”
跳轉(zhuǎn)到以下頁(yè)面,復(fù)制所有字符串
運(yùn)行我們上面給出的代碼,在交互窗口把我們復(fù)制的字符串粘貼過(guò)去:
之后點(diǎn)擊兩下回車,即可得到IEEE格式的文獻(xiàn)引用了:
這里我分了會(huì)議論文和期刊論文種格式,大家如果想要其他引用格式,可以在我的代碼的基礎(chǔ)上進(jìn)行增刪改,下面我放一些引用格式轉(zhuǎn)換的例子:
會(huì)議論文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.
會(huì)議論文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.
到此這篇關(guān)于用Python代碼自動(dòng)生成文獻(xiàn)的IEEE引用格式的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Python自動(dòng)生成IEEE格式內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python3用tkinter和PIL實(shí)現(xiàn)看圖工具
這篇文章給大家分享了Python3用tkinter和PIL實(shí)現(xiàn)看圖工具的詳細(xì)實(shí)例代碼,有興趣的朋友參考學(xué)習(xí)下。2018-06-06Django csrf 驗(yàn)證問(wèn)題的實(shí)現(xiàn)
csrf是通過(guò)偽裝來(lái)自受信任用戶的請(qǐng)求來(lái)利用受信任的網(wǎng)站。這篇文章主要介紹了Django csrf 驗(yàn)證問(wèn)題的實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-10-10OpenCV半小時(shí)掌握基本操作之像素加減乘除&邏輯運(yùn)算
這篇文章主要介紹了OpenCV基本操作之像素加減乘除&邏輯運(yùn)算,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-09-09python機(jī)器學(xué)習(xí)使數(shù)據(jù)更鮮活的可視化工具Pandas_Alive
今天我分享大家一款非常棒的動(dòng)畫可視化工具:Pandas_Alive,它以?matplotlib?繪圖為后端,不僅可以創(chuàng)建出令人驚嘆的動(dòng)畫可視化,而且使用方法非常簡(jiǎn)單。本文詳情如下2021-11-11趣味Python實(shí)戰(zhàn)練習(xí)之自動(dòng)更換桌面壁紙腳本附源碼
讀萬(wàn)卷書不如行萬(wàn)里路,學(xué)的扎不扎實(shí)要通過(guò)實(shí)戰(zhàn)才能看出來(lái),本篇文章手把手帶你編寫一個(gè)自動(dòng)更換桌面壁紙的腳本,代碼簡(jiǎn)潔而且短,相信你一定看得懂,大家可以在過(guò)程中查缺補(bǔ)漏,看看自己掌握程度怎么樣2021-10-10pytorch VGG11識(shí)別cifar10數(shù)據(jù)集(訓(xùn)練+預(yù)測(cè)單張輸入圖片操作)
這篇文章主要介紹了pytorch VGG11識(shí)別cifar10數(shù)據(jù)集(訓(xùn)練+預(yù)測(cè)單張輸入圖片操作),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-06-06mac系統(tǒng)下安裝pycharm、永久激活、中文漢化詳細(xì)教程
這篇文章主要介紹了mac系統(tǒng)下安裝pycharm、永久激活、中文漢化詳細(xì)教程,需要的朋友可以參考下2020-11-11