Datasets:
Upload reddit_climate_comment.py
Browse files- reddit_climate_comment.py +20 -32
reddit_climate_comment.py
CHANGED
|
@@ -75,47 +75,34 @@ class NewDataset(GeneratorBasedBuilder):
|
|
| 75 |
comments = []
|
| 76 |
|
| 77 |
# Extract comment data
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
comment_bodies = group['CommentBody'].tolist()
|
| 81 |
-
comment_timestamps = group['CommentTimestamp'].tolist()
|
| 82 |
-
comment_upvotes = group['CommentUpvotes'].tolist()
|
| 83 |
-
comment_permalinks = group['CommentPermalink'].tolist()
|
| 84 |
-
replies = group['replies'].tolist() # Assuming 'replies' column is a list
|
| 85 |
-
|
| 86 |
-
for i in range(len(comment_ids)):
|
| 87 |
-
comment_id = str(comment_ids[i])
|
| 88 |
|
| 89 |
if pd.isna(comment_id): # Skip if CommentID is NaN
|
| 90 |
continue
|
| 91 |
|
| 92 |
comment = {
|
| 93 |
"CommentID": comment_id,
|
| 94 |
-
"CommentAuthor":
|
| 95 |
-
"CommentBody":
|
| 96 |
-
"CommentTimestamp":
|
| 97 |
-
"CommentUpvotes":
|
| 98 |
-
"CommentPermalink":
|
| 99 |
"replies": [] # Initialize empty list for replies
|
| 100 |
}
|
| 101 |
|
| 102 |
-
# Check if
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
reply_data
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
"ReplyTimestamp": reply_data['ReplyTimestamp'],
|
| 115 |
-
"ReplyUpvotes": reply_data['ReplyUpvotes'],
|
| 116 |
-
"ReplyPermalink": reply_data['ReplyPermalink']
|
| 117 |
-
}
|
| 118 |
-
comment["replies"].append(reply)
|
| 119 |
|
| 120 |
comments.append(comment)
|
| 121 |
|
|
@@ -137,5 +124,6 @@ class NewDataset(GeneratorBasedBuilder):
|
|
| 137 |
|
| 138 |
|
| 139 |
|
|
|
|
| 140 |
|
| 141 |
|
|
|
|
| 75 |
comments = []
|
| 76 |
|
| 77 |
# Extract comment data
|
| 78 |
+
for index, comment_row in group.iterrows():
|
| 79 |
+
comment_id = str(comment_row['CommentID'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
if pd.isna(comment_id): # Skip if CommentID is NaN
|
| 82 |
continue
|
| 83 |
|
| 84 |
comment = {
|
| 85 |
"CommentID": comment_id,
|
| 86 |
+
"CommentAuthor": comment_row['CommentAuthor'],
|
| 87 |
+
"CommentBody": comment_row['CommentBody'],
|
| 88 |
+
"CommentTimestamp": comment_row['CommentTimestamp'],
|
| 89 |
+
"CommentUpvotes": comment_row['CommentUpvotes'],
|
| 90 |
+
"CommentPermalink": comment_row['CommentPermalink'],
|
| 91 |
"replies": [] # Initialize empty list for replies
|
| 92 |
}
|
| 93 |
|
| 94 |
+
# Check if there are replies for the current comment
|
| 95 |
+
replies_data = group[group['CommentID'] == comment_id][['ReplyID', 'ReplyAuthor', 'ReplyBody', 'ReplyTimestamp', 'ReplyUpvotes', 'ReplyPermalink']]
|
| 96 |
+
for _, reply_data in replies_data.iterrows():
|
| 97 |
+
reply = {
|
| 98 |
+
"ReplyID": str(reply_data['ReplyID']),
|
| 99 |
+
"ReplyAuthor": reply_data['ReplyAuthor'],
|
| 100 |
+
"ReplyBody": reply_data['ReplyBody'],
|
| 101 |
+
"ReplyTimestamp": reply_data['ReplyTimestamp'],
|
| 102 |
+
"ReplyUpvotes": reply_data['ReplyUpvotes'],
|
| 103 |
+
"ReplyPermalink": reply_data['ReplyPermalink']
|
| 104 |
+
}
|
| 105 |
+
comment["replies"].append(reply)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
comments.append(comment)
|
| 108 |
|
|
|
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
+
|
| 128 |
|
| 129 |
|