yes-man-today commited on
Commit
4e7e1de
1 Parent(s): 50a2c02
Files changed (1) hide show
  1. regulatory_comments.py +70 -17
regulatory_comments.py CHANGED
@@ -80,27 +80,80 @@ class RegComments(datasets.GeneratorBasedBuilder):
80
  ),
81
  ]
82
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  def _generate_examples(self, filepath):
84
- """This function returns the examples in the raw (text) form."""
85
- print("enter generate")
86
- key = 0
87
- with open(filepath, 'r', encoding='utf-8') as f:
88
- data = json.load(f)
89
- for docket in data:
90
- docket_id = docket["id"]
91
- docket_title = docket["title"]
92
- docket_context = docket["context"]
93
- docket_purpose = docket.get("purpose", "unspecified")
94
  docket_keywords = docket.get("keywords", [])
95
- comments = docket["comments"]
96
- print(f'this is in the docket in data{type(comments)}')
 
 
 
 
 
 
 
 
 
 
 
97
 
98
  yield key, {
99
  "id": docket_id,
100
  "title": docket_title,
101
  "context": docket_context,
102
- "purpose": docket_purpose,
103
- "keywords": docket_keywords,
104
- "comments": comments
105
- }
106
- key += 1
 
 
 
 
 
 
 
 
 
80
  ),
81
  ]
82
 
83
+ # def _generate_examples(self, filepath):
84
+ # """This function returns the examples in the raw (text) form."""
85
+ # print("enter generate")
86
+ # key = 0
87
+ # with open(filepath, 'r', encoding='utf-8') as f:
88
+ # data = json.load(f)
89
+ # for docket in data:
90
+ # docket_id = docket["id"]
91
+ # docket_title = docket["title"]
92
+ # docket_context = docket["context"]
93
+ # docket_purpose = docket.get("purpose", "unspecified")
94
+ # docket_keywords = docket.get("keywords", [])
95
+ # comments = docket["comments"]
96
+ # # for comment in docket["comments"]:
97
+ # # comment_data = {
98
+ # # "text": comment["text"],
99
+ # # "comment_id": comment["comment_id"],
100
+ # # "comment_url": comment["comment_url"],
101
+ # # "comment_date": comment["comment_date"],
102
+ # # "comment_title": comment["comment_title"],
103
+ # # "commenter_fname": comment["commenter_fname"],
104
+ # # "commenter_lname": comment["commenter_lname"],
105
+ # # "comment_length": comment["comment_length"]
106
+ # # }
107
+ # # comments.append(comment_data)
108
+
109
+ # yield key, {
110
+ # "id": docket_id,
111
+ # "title": docket_title,
112
+ # "context": docket_context,
113
+ # "purpose": docket_purpose,
114
+ # "keywords": docket_keywords,
115
+ # "comments": comments
116
+ # }
117
+ # key += 1
118
  def _generate_examples(self, filepath):
119
+ """Generates examples from a JSON file."""
120
+ print("Generating examples...")
121
+ with open(filepath, 'r', encoding='utf-8') as file:
122
+ data = json.load(file)
123
+ for key, docket in enumerate(data):
124
+ docket_id = docket.get("id", f"missing_id_{key}")
125
+ docket_title = docket.get("title", "No Title")
126
+ docket_context = docket.get("context", "No Context")
127
+ docket_purpose = docket.get("purpose", "Unspecified")
 
128
  docket_keywords = docket.get("keywords", [])
129
+
130
+ # Process comments
131
+ comments = docket.get("comments", [])
132
+
133
+ # Extracting fields from each comment
134
+ comment_texts = [comment.get("text", "").strip() for comment in comments]
135
+ comment_ids = [comment.get("comment_id", "") for comment in comments]
136
+ comment_urls = [comment.get("comment_url", "") for comment in comments]
137
+ comment_dates = [comment.get("comment_date", "") for comment in comments]
138
+ comment_titles = [comment.get("comment_title", "") for comment in comments]
139
+ commenter_fnames = [comment.get("commenter_fname", "") for comment in comments]
140
+ commenter_lnames = [comment.get("commenter_lname", "") for comment in comments]
141
+ comment_lengths = [comment.get("comment_length", 0) for comment in comments]
142
 
143
  yield key, {
144
  "id": docket_id,
145
  "title": docket_title,
146
  "context": docket_context,
147
+ "purpose": docket_purpose,
148
+ "keywords": docket_keywords,
149
+ "comments": {
150
+ "text": comment_texts,
151
+ "comment_id": comment_ids,
152
+ "comment_url": comment_urls,
153
+ "comment_date": comment_dates,
154
+ "comment_title": comment_titles,
155
+ "commenter_fname": commenter_fnames,
156
+ "commenter_lname": commenter_lnames,
157
+ "comment_length": comment_lengths
158
+ }
159
+ }