cathw commited on
Commit
593feea
1 Parent(s): 1599c2a

Upload reddit_climate_comment.py

Browse files
Files changed (1) hide show
  1. reddit_climate_comment.py +41 -67
reddit_climate_comment.py CHANGED
@@ -74,71 +74,48 @@ class NewDataset(GeneratorBasedBuilder):
74
 
75
  comments = []
76
 
77
- # Check if 'ParentCommentID' column exists
78
- if 'ParentCommentID' in df.columns:
79
- # Iterate over each unique comment ID
80
- for comment_id in group['CommentID'].unique():
81
- comment_data = group[group['CommentID'] == comment_id].iloc[0]
82
-
83
- comment_author = comment_data['CommentAuthor']
84
- comment_body = comment_data['CommentBody']
85
- comment_timestamp = comment_data['CommentTimestamp']
86
- comment_upvotes = comment_data['CommentUpvotes']
87
- comment_permalink = comment_data['CommentPermalink']
88
-
89
- # Get all replies for the current comment
90
- replies = []
91
- reply_group = df[df['ParentCommentID'] == comment_id]
92
- for _, reply_data in reply_group.iterrows():
93
- reply_id = reply_data['ReplyID']
94
- reply_author = reply_data['ReplyAuthor']
95
- reply_body = reply_data['ReplyBody']
96
- reply_timestamp = reply_data['ReplyTimestamp']
97
- reply_upvotes = reply_data['ReplyUpvotes']
98
- reply_permalink = reply_data['ReplyPermalink']
99
-
100
- reply = {
101
- "ReplyID": reply_id,
102
- "ReplyAuthor": reply_author,
103
- "ReplyBody": reply_body,
104
- "ReplyTimestamp": reply_timestamp,
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
- comments.append(comment)
121
- else:
122
- # If 'ParentCommentID' column does not exist, assume no nested comments
123
- for _, comment_data in group.iterrows():
124
- comment_id = comment_data['CommentID']
125
- comment_author = comment_data['CommentAuthor']
126
- comment_body = comment_data['CommentBody']
127
- comment_timestamp = comment_data['CommentTimestamp']
128
- comment_upvotes = comment_data['CommentUpvotes']
129
- comment_permalink = comment_data['CommentPermalink']
130
-
131
- # Add comment without replies
132
- comment = {
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
  }