DBLP DataSet Processing / 대용량 Json 파싱

2022. 1. 12. 17:58Artificial_Intelligence/Natural Language Processing

그래프 임베딩을 공부하기 위한 DataSet으로 DBLP로 정하고 이를 가져와보았다.

https://www.aminer.org/citation

 

AMiner

 

www.aminer.org

이 곳에 들어가서

이 데이터를 가져와서 다운로드를 받았다.

그런데 문제는 이 데이터를 가져와서 전처리를 해야하는데 용량이 16.1GB 이다..

웬만한 에디터로 열리지도 않는 데이터를 처리해야해서 막막했었다.

그래서 생각한 것이 데이터를 용량을 정해서 자르고,

자른 코드를 수작업으로 조금만 손봐주자고 생각하였다.

 

내가 사용한 프로그램은 GSplit 3 이다.

여기서 가져온 DBLP Json파일을 가져와서 1GB씩 먼저 잘랐다.

이렇게 되면, 딕셔너리로 자르는 것이 아닌 용량으로 자르기에 Json 형식이 깨지게 된다.

따라서, 이를 해결하기위해 앞뒤 파일을 왔다갔다하면서 잘린 Json 줄을 수정해야했다.

 

저는 Liquid Studio를 설치하여 데이터를 수정하였습니다.

VScode나 Pycharm이나 노트패드나 다른 에디터에서 대용량파일을 수정할 수 없어서 이 프로그램을 사용하여 수정하였습니다.

 

파일을 옮겨다니면서 한 20분 투자해서 17개의 분할된 데이터를 JSON형식에 맞게 수정을 해주었습니다.

이제 이 분할된 17개의 json을 사용할 수 있게 됩니다.

 

DBLP v13은 이런식으로 되어있다고 하는데, 실제로 다른 것들이 몇개 있어서 이를 먼저 찾고 수정하였습니다.

 

이 데이터를 열려고 하면 중간에 이런 문구가 껴있어서 안열립니다.

 

따라서 이런식으로 처리를 하여 파일을 열어야합니다.

with open(path+str(i+1)+".json", 'r', encoding='utf-8') as f:
    data = f.read()
fixed_data = re.sub(r"NumberInt\((\d+)\)", r"\1", data) #NumberInt(0) 변환하기
load_data = json.loads(fixed_data)
print("parse_json result: %s" % type(data))

3번째 줄이 저기 있는 NumberInt를 치환해주는 코드입니다.

 

이를 가지고 의미있는 Key값만 뽑아내기 위해 전처리를 하였습니다.

doi나 volume같은 건 필요없는 정보라고 판단되어 이런식으로 분류작업을 한 후 전처리를 하였습니다.

결론적으로 뽑은 키값들과 정보는 아래와 같습니다.

"""
_id                 str
title               str
year                int
keywords            list of str
fos                 list of str
references          list of str
n_citation          int
abstract            str
authors._id         list of str
authors.name        list of str
authors.org         list of str
authors.orgid       list of str
venue.sid           str
venue.raw           str

14개의 Key
122783개의 Dictonory
374 MB
"""

 

기존 데이터에서 삭제하는 방식이 아닌,

새로운 리스트와 딕셔너리를 만들어서 원하는 순서와 key-value 값으로 설정하여 추가하여 제작하였습니다.

 

먼저 필요한 Key 값들이 전부 있는지 확인 후,

하나라도 빠져있거나, 결측데이터가 있으면 전부 넘어가고,

필요한 정보들이 전부 존재하면 리스트에 추가하여 이를 json파일로 바꾸는 방식을 사용하였습니다.

 

최종적으로 이러한 형식의 json파일을 제작하였습니다.

 

[
{
        "_id": "53e9978db7602d9701f50739",
        "title": "iCity",
        "year": 2007,
        "keywords": [
            "Irregular cellular automata (CA)",
            "Complex systems modelling",
            "Geographic information systems (GIS)",
            "Urban planning",
            "Modelling urban growth",
            "ArcGIS",
            "Visual Basic .NET 2003",
            "ArcObjects"
        ],
        "fos": [
            "Software tool",
            "Asynchronous communication",
            "Cellular automaton",
            "Geographic information system",
            "Systems engineering",
            "ArcObjects",
            "Computer science",
            "Familiar environment",
            "Urban planning",
            "Predictive modelling"
        ],
        "references": [
            "53e9ac54b7602d9703624f16",
            "53e99aedb7602d9702379fcc",
            "53e9ae4eb7602d9703864863",
            "53e99dccb7602d970268a788",
            "53e9b7b4b7602d970435d6a5",
            "53e9b923b7602d97045101f6",
            "53e9b3b2b7602d9703e97364",
            "599c7a31601a182cd2699edc",
            "53e9be14b7602d9704acbec1",
            "53e99caeb7602d970255df3a",
            "5c7916064895d9cbc61c9f6f",
            "53e99fa8b7602d970287d2bf",
            "53e9b195b7602d9703c1d036",
            "53e9ba95b7602d97046bbc22",
            "53e9b9d3b7602d97045ca1a4",
            "53e9b607b7602d970415d4bd",
            "53e9bb6db7602d97047b1b94",
            "53e9a317b7602d9702c227ea",
            "53e9ade2b7602d97037ed1d6"
        ],
        "n_citation": 2,
        "abstract": "The objective of this study is to present a novel tool for predictive modelling of urban growth. The proposed tool, named iCity \u2013 Irregular City, extends the traditional formalization of cellular automata (CA) to include an irregular spatial structure, asynchronous urban growth, and a high spatio-temporal resolution to aid in spatial decision making for urban planning. The iCity software tool was developed as an embedded model within a common desktop geographic information system (GIS) with a user-friendly interface to control modelling operations for urban land-use change. This approach allows the model developer to focus on implementing model logic rather than developing an entire stand-alone modelling application. It also provides the model user with a familiar environment in which to run the model to simulate urban growth.",
        "authors._id": [
            "53f43531dabfaeb2ac048cb0",
            "54329aafdabfaeb4c6a92375",
            "53f39faadabfae4b34ab1ca2"
        ],
        "authors.name": [
            "D. Stevens",
            "S. Dragicevic",
            "Kristina Rothley"
        ],
        "authors.org": [
            "Spatial Analysis and Modeling Laboratory, Department of Geography, Simon Fraser University, 8888 University Drive, Burnaby, BC, Canada V5A1S6",
            "Spatial Analysis and Modeling Laboratory, Department of Geography, Simon Fraser University, 8888 University Drive, Burnaby, BC, Canada V5A1S6",
            "School of Resource and Environmental Management, Simon Fraser University, 8888 University Drive, Burnaby, BC, Canada V5A1S6"
        ],
        "authors.orgid": [
            "5f71b2841c455f439fe3c68e",
            "5f71b2841c455f439fe3c68e",
            "5f71b2841c455f439fe3c68e"
        ],
        "venue.sid": "environmental-modelling-and-software",
        "venue.raw": "Environmental Modelling & Software"
    }
 ]

이제 이 데이터를 가지고 Network, 그래프형식으로 제작하여 사용하면 됩니다.

728x90