-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtract.py
More file actions
54 lines (44 loc) · 1.62 KB
/
Extract.py
File metadata and controls
54 lines (44 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
Extract.py
This file defines a function that will be used to extract the code objects from the DevGPT Dataset
"""
# Importing the internal dependencies
from CodeClass import Code
def extract_data(json_object):
"""
This function extracts the code objects from the json object
:param json_object:
:return: code_objects
"""
code_objects = []
# Extracting the data from the DevGPT Dataset
for item in json_object["Sources"]:
chatgpt_sharings = item["ChatgptSharing"]
for chatgpt_sharing in chatgpt_sharings:
try:
title = chatgpt_sharing["Title"]
except KeyError:
title = "Untitled"
try:
model = chatgpt_sharing["Model"]
except KeyError:
model = "Unknown"
try:
conservations = chatgpt_sharing["Conversations"]
except KeyError:
conservations = []
for conservation in conservations:
code_list = conservation["ListOfCode"]
for code_object in code_list:
try:
code_type = code_object["Type"]
except KeyError:
code_type = "Unknown"
try:
# Convert to UTF-8
code = code_object["Content"]
code = code.encode('utf-8').decode('utf-8')
except KeyError:
code = "No Code Found"
code_objects.append(Code(code, code_type, model, title))
return code_objects