Datasets:
Upload reddit_climate_comment.py
Browse files- reddit_climate_comment.py +87 -56
reddit_climate_comment.py
CHANGED
|
@@ -18,67 +18,98 @@ class NewDataset(GeneratorBasedBuilder):
|
|
| 18 |
def _info(self):
|
| 19 |
return DatasetInfo(
|
| 20 |
description=_DESCRIPTION,
|
| 21 |
-
features=Features({
|
| 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 |
homepage=_HOMEPAGE,
|
| 50 |
)
|
| 51 |
def _split_generators(self, dl_manager):
|
| 52 |
path = dl_manager.download_and_extract(_URL)
|
| 53 |
train_splits = SplitGenerator(name=Split.TRAIN, gen_kwargs={"filepath": path+"/climate_comments.json"})
|
| 54 |
return [train_splits]
|
| 55 |
-
def _generate_examples(self,
|
| 56 |
-
with open(
|
| 57 |
data = json.load(f)
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
def _info(self):
|
| 19 |
return DatasetInfo(
|
| 20 |
description=_DESCRIPTION,
|
| 21 |
+
features = Features({
|
| 22 |
+
"Posts": Sequence({
|
| 23 |
+
"PostID": Value("string"),
|
| 24 |
+
"PostTitle": Value("string"),
|
| 25 |
+
"PostAuthor": Value("string"),
|
| 26 |
+
"PostBody": Value("string"),
|
| 27 |
+
"PostUrl": Value("string"),
|
| 28 |
+
"PostPic": Value("string"),
|
| 29 |
+
"Subreddit": Value("string"),
|
| 30 |
+
"PostTimestamp": Value("string"),
|
| 31 |
+
"PostUpvotes": Value("int32"),
|
| 32 |
+
"PostPermalink": Value("string"),
|
| 33 |
+
"Comments": Sequence({
|
| 34 |
+
"CommentID": Value("string"),
|
| 35 |
+
"CommentAuthor": Value("string"),
|
| 36 |
+
"CommentBody": Value("string"),
|
| 37 |
+
"CommentTimestamp": Value("string"),
|
| 38 |
+
"CommentUpvotes": Value("int32"),
|
| 39 |
+
"CommentPermalink": Value("string"),
|
| 40 |
+
"Replies": Sequence({
|
| 41 |
+
"ReplyID": Value("string"),
|
| 42 |
+
"ReplyAuthor": Value("string"),
|
| 43 |
+
"ReplyBody": Value("string"),
|
| 44 |
+
"ReplyTimestamp": Value("string"),
|
| 45 |
+
"ReplyUpvotes": Value("int32"),
|
| 46 |
+
"ReplyPermalink": Value("string"),
|
| 47 |
+
})
|
| 48 |
+
})
|
| 49 |
+
})
|
| 50 |
+
}),
|
| 51 |
homepage=_HOMEPAGE,
|
| 52 |
)
|
| 53 |
def _split_generators(self, dl_manager):
|
| 54 |
path = dl_manager.download_and_extract(_URL)
|
| 55 |
train_splits = SplitGenerator(name=Split.TRAIN, gen_kwargs={"filepath": path+"/climate_comments.json"})
|
| 56 |
return [train_splits]
|
| 57 |
+
def _generate_examples(self, path):
|
| 58 |
+
with open(path, encoding="utf-8") as f:
|
| 59 |
data = json.load(f)
|
| 60 |
|
| 61 |
+
for post in data["Posts"]:
|
| 62 |
+
post_id = post["PostID"]
|
| 63 |
+
post_title = post["PostTitle"]
|
| 64 |
+
post_author = post["PostAuthor"]
|
| 65 |
+
post_body = post["PostBody"]
|
| 66 |
+
post_url = post["PostUrl"]
|
| 67 |
+
post_pic = post["PostPic"]
|
| 68 |
+
subreddit = post["Subreddit"]
|
| 69 |
+
post_timestamp = post["PostTimestamp"]
|
| 70 |
+
post_upvotes = int(post["PostUpvotes"])
|
| 71 |
+
post_permalink = post["PostPermalink"]
|
| 72 |
+
comments = post["Comments"]
|
| 73 |
+
|
| 74 |
+
for comment in comments:
|
| 75 |
+
comment_id = comment["CommentID"]
|
| 76 |
+
comment_author = comment["CommentAuthor"]
|
| 77 |
+
comment_body = comment["CommentBody"]
|
| 78 |
+
comment_timestamp = comment["CommentTimestamp"]
|
| 79 |
+
comment_upvotes = int(comment["CommentUpvotes"])
|
| 80 |
+
comment_permalink = comment["CommentPermalink"]
|
| 81 |
+
|
| 82 |
+
replies = comment.get("Replies", [])
|
| 83 |
+
for reply in replies:
|
| 84 |
+
reply_id = reply["ReplyID"]
|
| 85 |
+
reply_author = reply["ReplyAuthor"]
|
| 86 |
+
reply_body = reply["ReplyBody"]
|
| 87 |
+
reply_timestamp = reply["ReplyTimestamp"]
|
| 88 |
+
reply_upvotes = int(reply["ReplyUpvotes"])
|
| 89 |
+
reply_permalink = reply["ReplyPermalink"]
|
| 90 |
+
|
| 91 |
+
yield f"{post_id}_{comment_id}_{reply_id}", {
|
| 92 |
+
"post_id": post_id,
|
| 93 |
+
"post_title": post_title,
|
| 94 |
+
"post_author": post_author,
|
| 95 |
+
"post_body": post_body,
|
| 96 |
+
"post_url": post_url,
|
| 97 |
+
"post_pic": post_pic,
|
| 98 |
+
"subreddit": subreddit,
|
| 99 |
+
"post_timestamp": post_timestamp,
|
| 100 |
+
"post_upvotes": post_upvotes,
|
| 101 |
+
"post_permalink": post_permalink,
|
| 102 |
+
"comment_id": comment_id,
|
| 103 |
+
"comment_author": comment_author,
|
| 104 |
+
"comment_body": comment_body,
|
| 105 |
+
"comment_timestamp": comment_timestamp,
|
| 106 |
+
"comment_upvotes": comment_upvotes,
|
| 107 |
+
"comment_permalink": comment_permalink,
|
| 108 |
+
"reply_id": reply_id,
|
| 109 |
+
"reply_author": reply_author,
|
| 110 |
+
"reply_body": reply_body,
|
| 111 |
+
"reply_timestamp": reply_timestamp,
|
| 112 |
+
"reply_upvotes": reply_upvotes,
|
| 113 |
+
"reply_permalink": reply_permalink,
|
| 114 |
+
}
|
| 115 |
+
|