一、任务
- 学习主题:作者关联(数据建模任务),对论文作者关系进行建模,统计最常出现的作者关系;
- 学习内容:构建作者关系图,挖掘作者关系
- 学习成果:论文作者知识图谱、图关系挖掘
二、读取数据并简单查看
data = []
with open("arxiv-metadata-oai-snapshot.json", 'r') as f:
for idx, line in enumerate(f):
d = json.loads(line)
d = {
'authors_parsed': d['authors_parsed']}
data.append(d)
data = pd.DataFrame(data)
data
三、简单绘制作者关系图
使用pip install networkx
下载networkx库
import networkx as nx
# 创建无向图
G = nx.Graph()
# 只用十篇论文进行构建
for row in data.iloc[:10].itertuples():
authors = row[1]
authors = [' '.join(x[:-1]) for x in authors]
for author in authors[1:]:
G.add_edge(authors[0],author) # 添加节点2,3并链接23节点
nx.draw(G, with_labels=True)
我们可以通过下面的代码访问两个作者之间的路径:
try:
print(nx.dijkstra_path(G, 'Yuan C. -P.', 'Nadolsky P. M.'))
except:
print('No path')
['Yuan C. -P.', 'Balázs C.', 'Nadolsky P. M.']
四、选择最大联通子图进行绘制
G = nx.Graph()
# 用一万篇论文进行构建
for row in data.iloc[:10000].itertuples():
authors = row[1]
authors = [' '.join(x[:-1]) for x in authors]
for author in authors[1:]:
G.add_edge(authors[0],author)
#这里指明是降序排列
degree_sequence = sorted([d for n, d in G.degree()],reverse=True)
plt.loglog(degree_sequence, "b-", marker="o")
plt.title("Degree rank plot")
plt.ylabel("degree")
plt.xlabel("rank")
plt.axes([0.45, 0.45, 0.45, 0.45])
Gcc = G.subgraph(sorted(nx.connected_components(G), key=len, reverse=True)[0])
pos = nx.spring_layout(Gcc)
plt.axis("off")
nx.draw_networkx_nodes(Gcc, pos, node_size=20)
nx.draw_networkx_edges(Gcc, pos, alpha=0.4)
plt.show()
本次任务完。
参考文献
1.Python3 sorted() 函数
https://www.runoob.com/python3/python3-func-sorted.html
2.数据分析入门(学术前沿趋势分析)Task5-作者信息关联
https://blog.csdn.net/xyc_undermoon/article/details/113083007