Datasets:
Upload reddit_climate_comment.py
Browse files- reddit_climate_comment.py +41 -67
reddit_climate_comment.py
CHANGED
|
@@ -74,71 +74,48 @@ class NewDataset(GeneratorBasedBuilder):
|
|
| 74 |
|
| 75 |
comments = []
|
| 76 |
|
| 77 |
-
#
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
"ReplyUpvotes": reply_upvotes,
|
| 106 |
-
"ReplyPermalink": reply_permalink
|
| 107 |
-
}
|
| 108 |
-
replies.append(reply)
|
| 109 |
-
|
| 110 |
-
# Add comment with its replies to the list
|
| 111 |
-
comment = {
|
| 112 |
-
"CommentID": comment_id,
|
| 113 |
-
"CommentAuthor": comment_author,
|
| 114 |
-
"CommentBody": comment_body,
|
| 115 |
-
"CommentTimestamp": comment_timestamp,
|
| 116 |
-
"CommentUpvotes": comment_upvotes,
|
| 117 |
-
"CommentPermalink": comment_permalink,
|
| 118 |
-
"replies": replies
|
| 119 |
}
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
#
|
| 123 |
-
|
| 124 |
-
comment_id
|
| 125 |
-
comment_author
|
| 126 |
-
comment_body
|
| 127 |
-
comment_timestamp
|
| 128 |
-
comment_upvotes
|
| 129 |
-
comment_permalink
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
"CommentID": comment_id,
|
| 134 |
-
"CommentAuthor": comment_author,
|
| 135 |
-
"CommentBody": comment_body,
|
| 136 |
-
"CommentTimestamp": comment_timestamp,
|
| 137 |
-
"CommentUpvotes": comment_upvotes,
|
| 138 |
-
"CommentPermalink": comment_permalink,
|
| 139 |
-
"replies": [] # No replies for this comment
|
| 140 |
-
}
|
| 141 |
-
comments.append(comment)
|
| 142 |
|
| 143 |
yield post_id, {
|
| 144 |
"id": post_id,
|
|
@@ -153,6 +130,3 @@ class NewDataset(GeneratorBasedBuilder):
|
|
| 153 |
"post_permalink": post_permalink,
|
| 154 |
"comments": comments
|
| 155 |
}
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
| 74 |
|
| 75 |
comments = []
|
| 76 |
|
| 77 |
+
# Iterate over each unique comment ID
|
| 78 |
+
for comment_id in group['CommentID'].unique():
|
| 79 |
+
comment_data = group[group['CommentID'] == comment_id].iloc[0]
|
| 80 |
+
|
| 81 |
+
comment_author = comment_data['CommentAuthor']
|
| 82 |
+
comment_body = comment_data['CommentBody']
|
| 83 |
+
comment_timestamp = comment_data['CommentTimestamp']
|
| 84 |
+
comment_upvotes = comment_data['CommentUpvotes']
|
| 85 |
+
comment_permalink = comment_data['CommentPermalink']
|
| 86 |
+
|
| 87 |
+
# Get all replies for the current comment
|
| 88 |
+
replies = []
|
| 89 |
+
reply_group = df[df['CommentID'] == comment_id]
|
| 90 |
+
for _, reply_data in reply_group.iterrows():
|
| 91 |
+
reply_id = reply_data['ReplyID']
|
| 92 |
+
reply_author = reply_data['ReplyAuthor']
|
| 93 |
+
reply_body = reply_data['ReplyBody']
|
| 94 |
+
reply_timestamp = reply_data['ReplyTimestamp']
|
| 95 |
+
reply_upvotes = reply_data['ReplyUpvotes']
|
| 96 |
+
reply_permalink = reply_data['ReplyPermalink']
|
| 97 |
+
|
| 98 |
+
reply = {
|
| 99 |
+
"ReplyID": reply_id,
|
| 100 |
+
"ReplyAuthor": reply_author,
|
| 101 |
+
"ReplyBody": reply_body,
|
| 102 |
+
"ReplyTimestamp": reply_timestamp,
|
| 103 |
+
"ReplyUpvotes": reply_upvotes,
|
| 104 |
+
"ReplyPermalink": reply_permalink
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
}
|
| 106 |
+
replies.append(reply)
|
| 107 |
+
|
| 108 |
+
# Add comment with its replies to the list
|
| 109 |
+
comment = {
|
| 110 |
+
"CommentID": comment_id,
|
| 111 |
+
"CommentAuthor": comment_author,
|
| 112 |
+
"CommentBody": comment_body,
|
| 113 |
+
"CommentTimestamp": comment_timestamp,
|
| 114 |
+
"CommentUpvotes": comment_upvotes,
|
| 115 |
+
"CommentPermalink": comment_permalink,
|
| 116 |
+
"replies": replies
|
| 117 |
+
}
|
| 118 |
+
comments.append(comment)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
yield post_id, {
|
| 121 |
"id": post_id,
|
|
|
|
| 130 |
"post_permalink": post_permalink,
|
| 131 |
"comments": comments
|
| 132 |
}
|
|
|
|
|
|
|
|
|