Task5 作者信息關(guān)聯(lián)-知識(shí)圖譜

5.1 任務(wù)說明

  • 學(xué)習(xí)主題:作者關(guān)聯(lián)(數(shù)據(jù)建模任務(wù)),對(duì)論文作者關(guān)系進(jìn)行建模,統(tǒng)計(jì)最常出現(xiàn)的作者關(guān)系;
  • 學(xué)習(xí)內(nèi)容:構(gòu)建作者關(guān)系圖,挖掘作者關(guān)系
  • 學(xué)習(xí)成果:論文作者知識(shí)圖譜、圖關(guān)系挖掘

5.2 數(shù)據(jù)處理步驟

  • 將論文第一作者與其他作者(論文非第一作者)構(gòu)建圖;
  • 使用圖算法統(tǒng)計(jì)圖中作者與其他作者的聯(lián)系;

5.3 社交網(wǎng)絡(luò)分析

圖是復(fù)雜網(wǎng)絡(luò)研究中的一個(gè)重要概念。Graph是用點(diǎn)和線來刻畫離散事物集合中的每對(duì)事物間以某種方式相聯(lián)系的數(shù)學(xué)模型。Graph在現(xiàn)實(shí)世界中隨處可見,如交通運(yùn)輸圖、旅游圖、流程圖等。利用圖可以描述現(xiàn)實(shí)生活中的許多事物,如用點(diǎn)可以表示交叉口,點(diǎn)之間的連線表示路徑,這樣就可以輕而易舉的描繪出一個(gè)交通運(yùn)輸網(wǎng)絡(luò)。

5.4 圖類型

  • 無向圖,忽略了兩節(jié)點(diǎn)間邊的方向。
  • 指有向圖,考慮了邊的有向性。
  • 多重?zé)o向圖,即兩個(gè)結(jié)點(diǎn)之間的邊數(shù)多于一條,又允許頂點(diǎn)通過同一條邊和自己關(guān)聯(lián)。

5.5 具體代碼以及講解

#導(dǎo)入所需的package并讀取原始數(shù)據(jù)
import seaborn as sns
from bs4 import BeautifulSoup   # 用于爬取arxiv的數(shù)據(jù)
import re
import requests   # 用于向網(wǎng)絡(luò)發(fā)送請(qǐng)求
import json
import pandas as pd  # 數(shù)據(jù)處理和分析
import matplotlib.pyplot as plt  # 畫圖工具
def readArxivFile(path, columns=['id','submitter','authors','title','comments','report-no','categories','license','abstract','versions','update_date','authors_parsed'],count=None):
    '''
    定義讀取文件的的函數(shù)
    path: 文件路徑
    columns:需要選擇的列
    count:讀取的行
    '''
    
    data = []
    with open(path,'r') as f:
        for idx, line in enumerate(f):
            if idx == count:
                break
            
            d = json.loads(line)
            d = {col: d[col] for col in columns}
            data.append(d)
            
    data = pd.DataFrame(data)
    return data

data = readArxivFile('./arxiv-metadata-oai-snapshot.json',
                    ['id','categories','authors_parsed'],
                    200000)
data
image.png
import networkx as nx 

# 創(chuàng)建無向圖
G = nx.Graph()

# 只用五篇論文進(jìn)行構(gòu)建
for row in data.iloc[:5].itertuples():
    authors = row[3]          # 第三列
    authors = [' '.join(x[:-1]) for x in authors]
    
    # 第一個(gè)作者 與 其他作者鏈接
    for author in authors[1:]:
        G.add_edge(authors[0],author)   # 添加節(jié)點(diǎn)2,3并鏈接2和3節(jié)點(diǎn)
# 繪制作者關(guān)系圖

nx.draw(G, with_labels=True)
image.png

如果我們500篇論文構(gòu)建圖,則可以得到更加完整作者關(guān)系,并選擇最大聯(lián)通子圖進(jìn)行繪制,折線圖為子圖節(jié)點(diǎn)度值。

# 用500篇論文進(jìn)行構(gòu)建
for row in data.iloc[:500].itertuples():        # 500篇論文
    authors = row[3]                            # 第三列 選擇 author
    authors = [' '.join(x[:-1]) for x in authors]
    
    # 第一個(gè)作者 與 其他作者鏈接
    for author in authors[1:]:
        G.add_edge(authors[0],author)   # 添加節(jié)點(diǎn)2,3并鏈接2和3節(jié)點(diǎn)
degree_sequence = sorted([d for n, d in G.degree()], reverse=True)
dmax = max(degree_sequence)

plt.loglog(degree_sequence, "b-", marker="o")
plt.title("Degree rank plot")
plt.ylabel("degree")
plt.xlabel("rank")

# draw graph in inset
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()
image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容