异质引文网络DBLP数据集(from AMiner)

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))

  • 11
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

二流子学程序

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值