IEEE文献引用格式脚本

引言

在写作论文写作过程中,如果引入的是非IEEE的期刊,但是你又需要投IEEE的期刊,那么你最后参考文献的引用格式就得和IEEE的保持一致,由于本人较懒,并秉持着能用脚本解决的事情,绝对不动手一个一个弄,因此,整了个python脚本对参考文献格式进行转换。具体使用过程如下:

获取Bibtex文本

Learning a target-dependent classifier for cross-domain semantic segmentation: Fine-tuning versus meta-learning文章为例,这是一篇Elsevier的文章,我们首先在熊猫学术中搜索这篇文章,并点击引用


![(https://img-blog.csdnimg.cn/direct/f726111921434e2e83006a5e910e3d57.png)
随后点击,BibTeX,
在这里插入图片描述
复制里面所有的文本信息:
在这里插入图片描述

IEEE格式转换

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 = r"[\w]+=" # 用正则表达式匹配符合 ...= 的字符串
    pattern2 = r"{[^{}]+}" # 用正则表达式匹配符合 内层{...} 的字符串

    # 找到所有的...=,并去除=号
    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])
        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))

def right_replace(string, old, new, max=1):
    return string[::-1].replace(old[::-1], new[::-1], max)[::-1]

if __name__ == '__main__':
    bibInfo = inputBibTex() # 获得BibTeX格式的文献引用
    outputchar = getIeeeFormat(bibInfo)
    outputchar = outputchar.replace('"', '“', 1)
    outputchar = outputchar.replace('"', '”', 1)
    outputchar = right_replace(outputchar, '-', '–', 1)
    print(outputchar) # 输出ieee格式

运行转换结果如下图所示:
在这里插入图片描述

### 如何在EndNote中设置IEEE会议文献格式 为了使EndNote能够按照IEEE标准来管理和格式化会议文献,研究者可以遵循特定的操作流程。首先,在安装并配置好EndNote之后,需获取适用于IEEE的样式文件(.ens),这通常是通过官方渠道或其他可靠资源获得[^1]。 一旦获得了合适的IEEE EndNote样式模板,将其放置于EndNote样式的目录下,通常位于`C:\Users\[用户名]\AppData\Roaming\EndNote\Styles`路径内。这样做的目的是让EndNote识别新的引用风格选项。 接下来,打开EndNote程序,进入编辑界面后找到“Edit”菜单下的“Output Styles”,再选择“Open Style Manager”。在这里可以看到所有已加载的输出样式列表;确认刚才添加进去的那个针对IEEE会议文献的新样式已被勾选启用状态。 对于具体应用此样式至文档中的情况而言,当撰写论文时如果使用Word插件,则只需切换到“EndNote X9/X8...”标签页,并从下拉框里挑选对应的IEEE会议文献格式即可完成转换工作。 另外值得注意的是,默认情况下某些术语表可能不完全匹配最新的IEEE规定,因此还需要手动调整一些细节部分,比如确保会议名称缩写的准确性等,这部分可以通过修改`C:\Program Files (x86)\EndNote 21\Terms Lists`内的相应条目实现[^2]。 最后,有关于如何将外部下载好的文献导入到EndNote数据库中以便进一步处理的问题,一般建议采用RIS格式进行数据交换操作,因为这是一种被广泛支持的标准格式之一。完成上述步骤后,还可以尝试点击“Find Full Text”按钮自动检索并附加PDF版本的文章副本给每一条记录[^4]。 ```python # Python代码仅用于示意,实际操作无需编写Python脚本 import os def set_ieee_conference_style(): style_path = "C:\\Users\\[用户名]\\AppData\\Roaming\\EndNote\\Styles" ieee_ens_file = "path_to_your_IEEE.ens" # 将IEEE ens 文件复制到指定位置 shutil.copy(ieee_ens_file, style_path) set_ieee_conference_style() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值