Upload 4 files
Browse files
LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
MIT License
|
2 |
+
|
3 |
+
Copyright (c) 2025 正经人王同学
|
4 |
+
|
5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
+
of this software and associated documentation files (the "Software"), to deal
|
7 |
+
in the Software without restriction, including without limitation the rights
|
8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
+
copies of the Software, and to permit persons to whom the Software is
|
10 |
+
furnished to do so, subject to the following conditions:
|
11 |
+
|
12 |
+
The above copyright notice and this permission notice shall be included in all
|
13 |
+
copies or substantial portions of the Software.
|
14 |
+
|
15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21 |
+
SOFTWARE.
|
README.md
CHANGED
@@ -1,12 +1,84 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# arXiv论文引用生成器
|
2 |
+
|
3 |
+
一个简单易用的工具,用于批量生成arXiv论文的引用格式。支持多种引用样式,包括APA、MLA、Chicago和IEEE格式。
|
4 |
+
|
5 |
+
## 功能特点
|
6 |
+
|
7 |
+
- 批量处理多个arXiv ID
|
8 |
+
- 支持多种引用格式(APA、MLA、Chicago、IEEE)
|
9 |
+
- 可选的引用编号功能
|
10 |
+
- 友好的Web界面
|
11 |
+
- 一键复制生成的引用
|
12 |
+
- 错误处理和提示
|
13 |
+
|
14 |
+
## 安装说明
|
15 |
+
|
16 |
+
1. 克隆仓库:
|
17 |
+
```bash
|
18 |
+
git clone https://github.com/zjrwtx/arxiv_citation_gentools.git
|
19 |
+
cd arxiv_citation_gentools
|
20 |
+
```
|
21 |
+
|
22 |
+
2. 安装依赖:
|
23 |
+
```bash
|
24 |
+
pip install gradio requests
|
25 |
+
```
|
26 |
+
|
27 |
+
## 使用方法
|
28 |
+
|
29 |
+
1. 运行应用:
|
30 |
+
```bash
|
31 |
+
python app.py
|
32 |
+
```
|
33 |
+
|
34 |
+
2. 在浏览器中打开显示的本地URL(通常是 http://127.0.0.1:7860)
|
35 |
+
|
36 |
+
3. 使用方式:
|
37 |
+
- 在文本框中输入arXiv ID(每行一个)
|
38 |
+
- 选择所需的引用格式
|
39 |
+
- 选择是否添加引用编号
|
40 |
+
- 点击提交按钮生成引用
|
41 |
+
|
42 |
+
## 示例输入
|
43 |
+
|
44 |
+
```
|
45 |
+
2301.12345
|
46 |
+
2302.54321
|
47 |
+
```
|
48 |
+
|
49 |
+
## 支持的引用格式
|
50 |
+
|
51 |
+
- **APA** (American Psychological Association)
|
52 |
+
- **MLA** (Modern Language Association)
|
53 |
+
- **Chicago**
|
54 |
+
- **IEEE** (Institute of Electrical and Electronics Engineers)
|
55 |
+
|
56 |
+
## 错误处理
|
57 |
+
|
58 |
+
- 程序会检查arXiv ID的有效性
|
59 |
+
- 对于无效或不存在的ID,会显示相应的错误信息
|
60 |
+
- 网络连接问题会有适当的错误提示
|
61 |
+
|
62 |
+
## 依赖项
|
63 |
+
|
64 |
+
- Python 3.6+
|
65 |
+
- gradio
|
66 |
+
- requests
|
67 |
+
|
68 |
+
## 许可证
|
69 |
+
|
70 |
+
本项目基于MIT许可证开源。
|
71 |
+
|
72 |
+
## 贡献
|
73 |
+
|
74 |
+
欢迎提交问题和改进建议!如果您想贡献代码:
|
75 |
+
|
76 |
+
1. Fork 本仓库
|
77 |
+
2. 创建您的特性分支
|
78 |
+
3. 提交您的更改
|
79 |
+
4. 推送到您的分支
|
80 |
+
5. 创建Pull Request
|
81 |
+
|
82 |
+
## 联系方式
|
83 |
+
|
84 |
+
如有问题或建议,请通过GitHub Issues联系我们。
|
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from citation import get_arxiv_metadata, format_citation
|
3 |
+
|
4 |
+
def process_citations(arxiv_ids, citation_style, add_numbers):
|
5 |
+
# Split the input into individual arXiv IDs
|
6 |
+
ids = [id.strip() for id in arxiv_ids.split('\n') if id.strip()]
|
7 |
+
results = []
|
8 |
+
errors = []
|
9 |
+
|
10 |
+
for idx, arxiv_id in enumerate(ids, 1):
|
11 |
+
try:
|
12 |
+
metadata = get_arxiv_metadata(arxiv_id)
|
13 |
+
citation = format_citation(metadata, citation_style)
|
14 |
+
if add_numbers:
|
15 |
+
results.append(f"[{idx}] {citation}\n")
|
16 |
+
else:
|
17 |
+
results.append(f"✓ {arxiv_id}:\n{citation}\n")
|
18 |
+
except Exception as e:
|
19 |
+
errors.append(f"✗ {arxiv_id}: {str(e)}\n")
|
20 |
+
|
21 |
+
# Combine results and errors
|
22 |
+
output = "处理结果:\n\n" + "".join(results)
|
23 |
+
if errors:
|
24 |
+
output += "\n错误信息:\n" + "".join(errors)
|
25 |
+
|
26 |
+
return output
|
27 |
+
|
28 |
+
# 创建Gradio界面
|
29 |
+
demo = gr.Interface(
|
30 |
+
fn=process_citations,
|
31 |
+
inputs=[
|
32 |
+
gr.Textbox(
|
33 |
+
label="arXiv ID列表",
|
34 |
+
placeholder="每行输入一个arXiv ID,例如:\n2301.12345\n2302.54321",
|
35 |
+
lines=5
|
36 |
+
),
|
37 |
+
gr.Radio(
|
38 |
+
choices=["APA", "MLA", "Chicago", "IEEE"],
|
39 |
+
label="引用格式",
|
40 |
+
value="APA"
|
41 |
+
),
|
42 |
+
gr.Checkbox(
|
43 |
+
label="添加引用编号",
|
44 |
+
value=True,
|
45 |
+
info="在每条引用前添加序号 [1], [2], ..."
|
46 |
+
)
|
47 |
+
],
|
48 |
+
outputs=gr.Textbox(label="生成的引用", lines=10, show_copy_button=True),
|
49 |
+
title="arXiv论文引用生成器(开源在github)",
|
50 |
+
description="批量生成arXiv论文的引用格式,支持APA, MLA, Chicago, IEEE等格式,每行输入一个arXiv ID,选择所需的引用格式。开源地址:https://github.com/zjrwtx/arxiv_citation_gentools",
|
51 |
+
examples=[
|
52 |
+
["2402.06196", "APA", True],
|
53 |
+
["2303.18223", "MLA", True],
|
54 |
+
["2402.01680", "IEEE", True]
|
55 |
+
],
|
56 |
+
theme=gr.themes.Soft()
|
57 |
+
)
|
58 |
+
|
59 |
+
if __name__ == "__main__":
|
60 |
+
demo.launch(share=False)
|
citation.py
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import requests
|
3 |
+
import re
|
4 |
+
|
5 |
+
def get_arxiv_metadata(arxiv_id):
|
6 |
+
# 检查arXiv ID格式
|
7 |
+
if not re.match(r'^\d{4}\.\d{4,5}(v\d+)?$', arxiv_id):
|
8 |
+
raise ValueError("请输入有效的arXiv编号,例如:2301.12345")
|
9 |
+
|
10 |
+
# 构建API请求URL
|
11 |
+
url = f'http://export.arxiv.org/api/query?id_list={arxiv_id}'
|
12 |
+
response = requests.get(url)
|
13 |
+
|
14 |
+
if response.status_code != 200:
|
15 |
+
raise Exception("无法从arXiv获取数据,请检查网络连接和arXiv编号。")
|
16 |
+
|
17 |
+
# 解析XML响应
|
18 |
+
import xml.etree.ElementTree as ET
|
19 |
+
root = ET.fromstring(response.text)
|
20 |
+
ns = {'atom': 'http://www.w3.org/2005/Atom'}
|
21 |
+
|
22 |
+
entry = root.find('atom:entry', ns)
|
23 |
+
if entry is None:
|
24 |
+
raise Exception("未找到该arXiv编号的论文信息。")
|
25 |
+
|
26 |
+
# 获取论文标题
|
27 |
+
title = entry.find('atom:title', ns).text.strip()
|
28 |
+
|
29 |
+
# 获取作者列表
|
30 |
+
authors = entry.findall('atom:author/atom:name', ns)
|
31 |
+
author_names = [author.text.strip() for author in authors]
|
32 |
+
|
33 |
+
# 获取出版年份(使用发表日期的年份)
|
34 |
+
published = entry.find('atom:published', ns).text
|
35 |
+
year = published[:4]
|
36 |
+
|
37 |
+
# 获取版本号
|
38 |
+
arxiv_url = entry.find('atom:id', ns).text
|
39 |
+
version_search = re.search(r'v(\d+)$', arxiv_url)
|
40 |
+
version = version_search.group(0) if version_search else ''
|
41 |
+
|
42 |
+
# 返回元数据
|
43 |
+
metadata = {
|
44 |
+
'title': title,
|
45 |
+
'authors': author_names,
|
46 |
+
'year': year,
|
47 |
+
'arxiv_id': arxiv_id,
|
48 |
+
'version': version
|
49 |
+
}
|
50 |
+
return metadata
|
51 |
+
|
52 |
+
def format_citation(metadata, style='APA'):
|
53 |
+
authors = metadata['authors']
|
54 |
+
title = metadata['title']
|
55 |
+
arxiv_id = metadata['arxiv_id']
|
56 |
+
version = metadata['version']
|
57 |
+
year = metadata['year']
|
58 |
+
|
59 |
+
# 处理作者姓名格式
|
60 |
+
if style.upper() == 'APA':
|
61 |
+
formatted_authors = ', '.join(authors)
|
62 |
+
citation = f"{formatted_authors}. ({year}). {title}. *arXiv*预印本arXiv:{arxiv_id}{version}"
|
63 |
+
elif style.upper() == 'MLA':
|
64 |
+
formatted_authors = '、'.join(authors)
|
65 |
+
citation = f"{formatted_authors}。《{title}》。*arXiv*预印本 arXiv:{arxiv_id}{version} ({year})。"
|
66 |
+
elif style.upper() == 'CHICAGO':
|
67 |
+
formatted_authors = ', '.join(authors)
|
68 |
+
citation = f"{formatted_authors}。“{title}。” *arXiv*预印本 arXiv:{arxiv_id}{version},{year}。"
|
69 |
+
elif style.upper() == 'IEEE':
|
70 |
+
# IEEE风格通常使用英文名,需要将中文名转为拼音或使用英文名
|
71 |
+
formatted_authors = ' and '.join(authors)
|
72 |
+
citation = f"{formatted_authors}, \"{title},\" *arXiv* preprint arXiv:{arxiv_id}{version}, {year}."
|
73 |
+
else:
|
74 |
+
raise ValueError("不支持的引用格式。请选择APA、MLA、Chicago或IEEE。")
|
75 |
+
|
76 |
+
return citation
|
77 |
+
|
78 |
+
def main():
|
79 |
+
arxiv_id = input("请输入arXiv编号(例如2301.12345):").strip()
|
80 |
+
style = input("请输入引用格式(APA、MLA、Chicago、IEEE):").strip()
|
81 |
+
|
82 |
+
try:
|
83 |
+
metadata = get_arxiv_metadata(arxiv_id)
|
84 |
+
citation = format_citation(metadata, style)
|
85 |
+
print("\n生成的引用:\n")
|
86 |
+
print(citation)
|
87 |
+
except Exception as e:
|
88 |
+
print(f"发生错误:{e}")
|
89 |
+
|
90 |
+
if __name__ == '__main__':
|
91 |
+
main()
|