ro-h commited on
Commit
80a0d7a
1 Parent(s): 2ac10ff

Upload regulatory_comments.py

Browse files
Files changed (1) hide show
  1. regulatory_comments.py +122 -0
regulatory_comments.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # TODO: Address all TODOs and remove all explanatory comments
15
+ """TODO: Add a description here."""
16
+
17
+
18
+ import csv
19
+ import json
20
+ import os
21
+ import datasets
22
+
23
+
24
+ _DESCRIPTION = """\
25
+ United States governmental agencies often make proposed regulations open to the public for comment.
26
+ This project will use Regulation.gov public API to aggregate and clean public comments for dockets
27
+ related to Medication Assisted Treatment for Opioid Use Disorders.
28
+
29
+ The dataset will contain docket metadata, docket text-content, comment metadata, and comment text-content.
30
+ """
31
+
32
+ _HOMEPAGE = "https://www.regulations.gov/"
33
+
34
+
35
+ # TODO: Add link to the official dataset URLs here
36
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
37
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
38
+ _URLS = "https://huggingface.co/datasets/ro-h/regulatory_comments/blob/main/temp.csv"
39
+
40
+
41
+ # TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
42
+ class RegComments(datasets.GeneratorBasedBuilder):
43
+
44
+ VERSION = datasets.Version("1.1.0")
45
+
46
+ # This is an example of a dataset with multiple configurations.
47
+ # If you don't want/need to define several sub-sets in your dataset,
48
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
49
+
50
+ # If you need to make complex sub-parts in the datasets with configurable options
51
+ # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
52
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
53
+
54
+ # You will be able to load one or the other configurations in the following list with
55
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
56
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
57
+
58
+ #my_dataset[comment_id] = dict(
59
+ # comment_url = comment['links']['self'],
60
+ # comment_text = comment_data['data']['attributes']['comment'],
61
+ # commenter_name = comment_data['data']['attributes'].get('firstName', '') + " " + comment_data['data']['attributes'].get('lastName', '')
62
+ # ) #use pandas
63
+
64
+ def _info(self):
65
+ features = datasets.Features(
66
+ {"docket_agency": datasets.Value("string"),
67
+ "docket_title": datasets.Value("string"),
68
+ "comment_id": datasets.Value("string"),
69
+ "comment_date": datasets.Value("date"),
70
+ "comment_link": datasets.Value("string"),
71
+ "comment_title": datasets.Value("string"),
72
+ "commenter_name": datasets.Value("string"),
73
+ "comment_length": datasets.Value("int"),
74
+ "comment_text": datasets.Value("string"),
75
+ }
76
+ )
77
+
78
+
79
+ return datasets.DatasetInfo(
80
+ # This is the description that will appear on the datasets page.
81
+ description=_DESCRIPTION,
82
+ # This defines the different columns of the dataset and their types
83
+ features=features, # Here we define them above because they are different between the two configurations
84
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
85
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
86
+ # supervised_keys=("sentence", "label"),
87
+ # Homepage of the dataset for documentation
88
+ homepage=_HOMEPAGE
89
+ )
90
+
91
+ def _split_generators(self, dl_manager):
92
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
93
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
94
+
95
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
96
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
97
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
98
+ urls = _URLS[self.config.name]
99
+ data_dir = dl_manager.download_and_extract(urls)
100
+ return [datasets.SplitGenerator(name=datasets.Split.TRAIN,
101
+ # These kwargs will be passed to _generate_examples
102
+ gen_kwargs={
103
+ "filepath": os.path.join(data_dir, "train.csv"),
104
+ "split": "train",
105
+ },),]
106
+
107
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
108
+ def _generate_examples(self, filepath):
109
+ with open(filepath, encoding="utf-8") as f:
110
+ reader = csv.DictReader(f)
111
+ for key, row in enumerate(reader):
112
+ yield key, {
113
+ "docket_agency": row["docket_agency"],
114
+ "docket_title": row["docket_title"],
115
+ "comment_id": row["comment_id"],
116
+ "comment_date": row["comment_date"],
117
+ "comment_link": row["comment_link"],
118
+ "comment_title": row["comment_title"],
119
+ "commenter_name": row["commenter_name"],
120
+ "comment_length": int(row["comment_length"]),
121
+ "comment_text": row["comment_text"],
122
+ }