用途
参考文献格式转换工具,用于在 APA(第7版)、MLA(第9版)、IEEE、Harvard 四种主流学术引用格式之间相互转换,同时提供格式错误检查和批量处理能力。当需要转换参考文献格式、检查引用是否正确,或涉及 citation、bibliography、APA/MLA/IEEE/Harvard 格式、批量格式化引用等任务时适用。
支持的格式
- APA:American Psychological Association 第7版,示例:Smith, J. A. (2023). Title. Journal, 1(2), 10-20.
- MLA:Modern Language Association 第9版,示例:Smith, John A. "Title." Journal, vol. 1, no. 2, 2023, pp. 10-20.
- IEEE:Institute of Electrical and Electronics Engineers,示例:[1] J. A. Smith, "Title," Journal, vol. 1, no. 2, pp. 10-20, 2023.
- Harvard:Harvard Referencing Style,示例:Smith, J.A. (2023) 'Title', Journal, 1(2), pp. 10-20.
主要能力
工具提供以下子命令:
- format:将 JSON 结构化引用数据转为指定格式的引用文本,是最可靠的方式,无需解析文本。
- parse:将引用文本解析为结构化 JSON 数据。
- convert:格式互转,可自动检测源格式或指定源格式,支持 JSON 输出。
- check:格式错误检查,检查项包括必填字段缺失(作者、标题、年份)、年份格式正确性、期刊文章的期刊名/卷号/页码、书籍的出版社信息、DOI 格式,以及各格式特有的标点和结构规范。
- detect:自动检测引用文本所属格式。
使用方式
快速开始示例:
- 格式转换(文本输入):
python3 scripts/citation_formatter.py convert --to ieee "Smith, J. A. (2023). Machine learning approaches. Nature, 12(3), 45-67."
- 格式转换(结构化 JSON 输入,更精确):
echo '{"authors":["Smith, John A.","Jones, Mary B."],"year":"2023","title":"Machine learning approaches","journal":"Nature","volume":"12","issue":"3","pages":"45-67","entry_type":"article"}' | python3 scripts/citation_formatter.py format --style ieee
- 格式错误检查:
python3 scripts/citation_formatter.py check --style apa "Smith J (2023) Machine learning. Nature 12(3) 45-67"
- 批量处理:
从文件批量转换(每行一条引用)
python3 scripts/citation_formatter.py convert --to mla --input refs.txt
批量检查
python3 scripts/citation_formatter.py check --style apa --input refs.txt
- 自动检测格式:
python3 scripts/citation_formatter.py detect "Smith, J. A. (2023). Title. Nature, 12(3), 45-67."
format 子命令支持通过 stdin、--data 参数或 --input 传入 JSON 数组文件。JSON 字段包括:authors(string[],必填,格式 "姓, 名")、year(string,必填)、title(string,必填)、journal(期刊文章必填)、volume、issue、pages、publisher(书籍必填)、doi、url、entry_type(article / book / chapter / webpage)、edition、city。
convert 子命令可自动检测源格式或通过 --from 指定,支持 --json 输出。check 子命令支持 --json 输出以便程序处理。
使用建议:最可靠的方式是先从用户输入中提取结构化信息,构造 JSON,然后用 format 子命令格式化;快速转换可直接用 convert;批量处理将引用放入文件(每行一条)并使用 --input;转换后用 check 验证结果。
适用场景
- 学术写作中需要在不同引用格式之间转换参考文献。
- 检查已有引用是否符合指定格式规范。
- 批量格式化或检查大量参考文献。
- 自动识别引用文本所属格式。
限制与前置条件
- 前置条件:Python 3.7+。
- 无需安装额外依赖(仅使用标准库)。
- 无需 API Key。
- 其他限制暂未提供。