DBLP 下载网站:
https://www.aminer.cn/citation
DBLP-Citation-network V13版本
5,354,309 #paper
48,227,950 #Citation Relationship
DBLP+Citation [2021-05-14]
解压得到json文件
由于python的json包只能处理字符串,所以需要对原始数据集的所有数据转成字符串
图中year的value非字符串类型
处理代码如下:
import re
def readChunk(path,out_path,chunk_size=1024*1024*100):
chunk_count=0
with open(path,'r',encoding='utf-8') as fp:
while True:
chunk=fp.read(chunk_size) #读取一个chunk的数据
###########################################
#处理,写入新文件
with open(out_path,'a',encoding='utf-8') as fo:
#回调函数repl
def repl(m):
return (m.group(1).replace('NumberInt(', '"') + m.group(2) + m.group(3).replace(')', '"'))
#中间部分的数字不需要替换
pattern = re.compile(r"(NumberInt[(])(\d+)([)])")
result=re.sub(pattern, repl, chunk)
fo.write(result)
chunk_count+=1
if not chunk:
break
return chunk_count
path=r'D:\ZHW-FILE\dblp.v13\dbpl-test.json'
out_path=r'D:\ZHW-FILE\dblp.v13\dbpl-test.json-new.json'
chunk_count=readChunk(path,out_path,chunk_size=1024*1024*200)
print('dblp processing finished')
print('chunk_count',chunk_count)
其中 path设置为dblp数据集的路径,out_path为处理完的dblp数据集。
处理完之后还不行,在使用python json包后还是报错,报错原因为文件的83576699行18列出现非字符串类型。使用EmEditor文本编辑器定位。发现错误,修改保存。
获取2010-2021年份的数据集
# 数据路径
import json
path = r"D:\ZHW-FILE\dblp.v13\dblpv13_new.json"
outpath=r'D:\ZHW-FILE\dblp.v13\dblpv13_new(2010-2021).json'
# 读取文件数据
with open(path, "r",encoding='utf-8') as f:
row_data = json.load(f)
print('加载dblp数据完毕')
# 读取每一条json数据,保存在data_list
data_list=[]
for d in row_data:
if 'year' in d:
if int(d['year'])>=2010:
data_list.append(d)
else:
print('find a data no have year')
print(d)
with open(outpath, 'w',encoding='utf-8') as fw:
json.dump(data_list, fw)
print('写入dblp数据(2010-2021)完毕')
path为上一步修改后的V13数据集,outpath为自定义保存的路径。
读取指定年份json文件
import json
path = r"D:\ZHW-FILE\dblp.v13\dblpv13_new(2010-2021).json"
with open(path, 'r', encoding='utf-8') as f:
dicts = json.load(f)
print('total paper numbers= ',len(dicts))