Keegan Skeate
commited on
Commit
·
ab43142
1
Parent(s):
4f0b638
📜Cannabis Tests dataset docs + loading script
Browse files- README.md +239 -1
- cannabis_tests.py +181 -0
README.md
CHANGED
@@ -1,3 +1,241 @@
|
|
1 |
---
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
annotations_creators:
|
3 |
+
- expert-generated
|
4 |
+
language_creators:
|
5 |
+
- expert-generated
|
6 |
+
license:
|
7 |
+
- cc-by-4.0
|
8 |
+
pretty_name: cannabis_tests
|
9 |
+
size_categories:
|
10 |
+
- 1K<n<10K
|
11 |
+
source_datasets:
|
12 |
+
- original
|
13 |
+
tags:
|
14 |
+
- cannabis
|
15 |
+
- lab results
|
16 |
+
- tests
|
17 |
---
|
18 |
+
|
19 |
+
# Cannabis Tests, Curated by Cannlytics
|
20 |
+
|
21 |
+
## Table of Contents
|
22 |
+
- [Table of Contents](#table-of-contents)
|
23 |
+
- [Dataset Description](#dataset-description)
|
24 |
+
- [Dataset Summary](#dataset-summary)
|
25 |
+
- [Dataset Structure](#dataset-structure)
|
26 |
+
- [Data Instances](#data-instances)
|
27 |
+
- [Data Fields](#data-fields)
|
28 |
+
- [Data Splits](#data-splits)
|
29 |
+
- [Dataset Creation](#dataset-creation)
|
30 |
+
- [Curation Rationale](#curation-rationale)
|
31 |
+
- [Source Data](#source-data)
|
32 |
+
- [Personal and Sensitive Information](#personal-and-sensitive-information)
|
33 |
+
- [Considerations for Using the Data](#considerations-for-using-the-data)
|
34 |
+
- [Social Impact of Dataset](#social-impact-of-dataset)
|
35 |
+
- [Discussion of Biases](#discussion-of-biases)
|
36 |
+
- [Other Known Limitations](#other-known-limitations)
|
37 |
+
- [Additional Information](#additional-information)
|
38 |
+
- [Dataset Curators](#dataset-curators)
|
39 |
+
- [License](#license)
|
40 |
+
- [Citation](#citation)
|
41 |
+
- [Contributions](#contributions)
|
42 |
+
|
43 |
+
## Dataset Description
|
44 |
+
|
45 |
+
- **Homepage:** <https://cannlytics.com>
|
46 |
+
- **Repository:** <https://huggingface.co/datasets/cannlytics/cannabis_tests>
|
47 |
+
- **Point of Contact:** <[email protected]>
|
48 |
+
|
49 |
+
### Dataset Summary
|
50 |
+
|
51 |
+
This dataset is a collection of public cannabis lab test results parsed by CoADoc, a certificate of analysis (COA) parsing tool.
|
52 |
+
|
53 |
+
## Dataset Structure
|
54 |
+
|
55 |
+
The dataset is partitioned into the various sources of lab results.
|
56 |
+
|
57 |
+
| Source | Observations |
|
58 |
+
|--------|--------------|
|
59 |
+
| Raw Gardens | 2,810 |
|
60 |
+
| MCR Labs | Coming soon! |
|
61 |
+
| PSI Labs | Coming soon! |
|
62 |
+
| SC Labs | Coming soon! |
|
63 |
+
|
64 |
+
### Data Instances
|
65 |
+
|
66 |
+
You can load the lab test data from the various sources:
|
67 |
+
|
68 |
+
```py
|
69 |
+
from datasets import load_dataset
|
70 |
+
|
71 |
+
# Load Raw Garden lab test data.
|
72 |
+
dataset = 'cannlytics/cannabis_tests'
|
73 |
+
rawgarden_data = load_dataset(dataset, 'rawgarden')
|
74 |
+
```
|
75 |
+
|
76 |
+
### Data Fields
|
77 |
+
|
78 |
+
Below is a non-exhaustive list of fields, used to standardize the various data that are encountered, that you may expect encounter in the parsed COA data.
|
79 |
+
|
80 |
+
| Field | Example| Description |
|
81 |
+
|-------|-----|-------------|
|
82 |
+
| `analyses` | ["cannabinoids"] | A list of analyses performed on a given sample. |
|
83 |
+
| `{analysis}_method` | "HPLC" | The method used for each analysis. |
|
84 |
+
| `{analysis}_status` | "pass" | The pass, fail, or N/A status for pass / fail analyses. |
|
85 |
+
| `coa_urls` | [{"url": "", "filename": ""}] | A list of certificate of analysis (CoA) URLs. |
|
86 |
+
| `date_collected` | 2022-04-20T04:20 | An ISO-formatted time when the sample was collected. |
|
87 |
+
| `date_tested` | 2022-04-20T16:20 | An ISO-formatted time when the sample was tested. |
|
88 |
+
| `date_received` | 2022-04-20T12:20 | An ISO-formatted time when the sample was received. |
|
89 |
+
| `distributor` | "Your Favorite Dispo" | The name of the product distributor, if applicable. |
|
90 |
+
| `distributor_address` | "Under the Bridge, SF, CA 55555" | The distributor address, if applicable. |
|
91 |
+
| `distributor_street` | "Under the Bridge" | The distributor street, if applicable. |
|
92 |
+
| `distributor_city` | "SF" | The distributor city, if applicable. |
|
93 |
+
| `distributor_state` | "CA" | The distributor state, if applicable. |
|
94 |
+
| `distributor_zipcode` | "55555" | The distributor zip code, if applicable. |
|
95 |
+
| `distributor_license_number` | "L2Stat" | The distributor license number, if applicable. |
|
96 |
+
| `images` | [{"url": "", "filename": ""}] | A list of image URLs for the sample. |
|
97 |
+
| `lab_results_url` | "https://cannlytics.com/results" | A URL to the sample results online. |
|
98 |
+
| `producer` | "Grow Tent" | The producer of the sampled product. |
|
99 |
+
| `producer_address` | "3rd & Army, SF, CA 55555" | The producer's address. |
|
100 |
+
| `producer_street` | "3rd & Army" | The producer's street. |
|
101 |
+
| `producer_city` | "SF" | The producer's city. |
|
102 |
+
| `producer_state` | "CA" | The producer's state. |
|
103 |
+
| `producer_zipcode` | "55555" | The producer's zipcode. |
|
104 |
+
| `producer_license_number` | "L2Calc" | The producer's license number. |
|
105 |
+
| `product_name` | "Blue Rhino Pre-Roll" | The name of the product. |
|
106 |
+
| `lab_id` | "Sample-0001" | A lab-specific ID for the sample. |
|
107 |
+
| `product_type` | "flower" | The type of product. |
|
108 |
+
| `batch_number` | "Order-0001" | A batch number for the sample or product. |
|
109 |
+
| `metrc_ids` | ["1A4060300002199000003445"] | A list of relevant Metrc IDs. |
|
110 |
+
| `metrc_lab_id` | "1A4060300002199000003445" | The Metrc ID associated with the lab sample. |
|
111 |
+
| `metrc_source_id` | "1A4060300002199000003445" | The Metrc ID associated with the sampled product. |
|
112 |
+
| `product_size` | 2000 | The size of the product in milligrams. |
|
113 |
+
| `serving_size` | 1000 | An estimated serving size in milligrams. |
|
114 |
+
| `servings_per_package` | 2 | The number of servings per package. |
|
115 |
+
| `sample_weight` | 1 | The weight of the product sample in grams. |
|
116 |
+
| `results` | [{...},...] | A list of results, see below for result-specific fields. |
|
117 |
+
| `status` | "pass" | The overall pass / fail status for all contaminant screening analyses. |
|
118 |
+
| `total_cannabinoids` | 14.20 | The analytical total of all cannabinoids measured. |
|
119 |
+
| `total_thc` | 14.00 | The analytical total of THC and THCA. |
|
120 |
+
| `total_cbd` | 0.20 | The analytical total of CBD and CBDA. |
|
121 |
+
| `total_terpenes` | 0.42 | The sum of all terpenes measured. |
|
122 |
+
| `sample_id` | "{sha256-hash}" | A generated ID to uniquely identify the `producer`, `product_name`, and `date_tested`. |
|
123 |
+
| `strain_name` | "Blue Rhino" | A strain name, if specified. Otherwise, can be attempted to be parsed from the `product_name`. |
|
124 |
+
|
125 |
+
Each result can contain the following fields.
|
126 |
+
|
127 |
+
| Field | Example| Description |
|
128 |
+
|-------|--------|-------------|
|
129 |
+
| `analysis` | "pesticides" | The analysis used to obtain the result. |
|
130 |
+
| `key` | "pyrethrins" | A standardized key for the result analyte. |
|
131 |
+
| `name` | "Pyrethrins" | The lab's internal name for the result analyte |
|
132 |
+
| `value` | 0.42 | The value of the result. |
|
133 |
+
| `mg_g` | 0.00000042 | The value of the result in milligrams per gram. |
|
134 |
+
| `units` | "ug/g" | The units for the result `value`, `limit`, `lod`, and `loq`. |
|
135 |
+
| `limit` | 0.5 | A pass / fail threshold for contaminant screening analyses. |
|
136 |
+
| `lod` | 0.01 | The limit of detection for the result analyte. Values below the `lod` are typically reported as `ND`. |
|
137 |
+
| `loq` | 0.1 | The limit of quantification for the result analyte. Values above the `lod` but below the `loq` are typically reported as `<LOQ`. |
|
138 |
+
| `status` | "pass" | The pass / fail status for contaminant screening analyses. |
|
139 |
+
|
140 |
+
### Data Splits
|
141 |
+
|
142 |
+
The data is split into training, validation, and test data. Training data is used for training your models. Validation data is used for evaluating your trained models, to help you determine a final model. Test data is used to evaluate your final model.
|
143 |
+
|
144 |
+
## Dataset Creation
|
145 |
+
|
146 |
+
### Curation Rationale
|
147 |
+
|
148 |
+
Certificates of analysis (CoAs) are abundant for cannabis cultivators, processors, retailers, and consumers too, but the data is often locked away. Rich, valuable laboratory data so close, yet so far away! CoADoc puts these vital data points in your hands by parsing PDFs and URLs, finding all the data, standardizing the data, and cleanly returning the data to you.
|
149 |
+
|
150 |
+
### Source Data
|
151 |
+
|
152 |
+
| Data Source | URL |
|
153 |
+
|-------------|-----|
|
154 |
+
| MCR Labs Test Results | <https://reports.mcrlabs.com> |
|
155 |
+
| PSI Labs Test Results | <https://results.psilabs.org/test-results/> |
|
156 |
+
| Raw Garden Test Results | <https://rawgarden.farm/lab-results/> |
|
157 |
+
| SC Labs Test Results | <https://client.sclabs.com/> |
|
158 |
+
|
159 |
+
#### Initial Data Collection and Normalization
|
160 |
+
|
161 |
+
| Algorithm | URL |
|
162 |
+
|-----------|-----|
|
163 |
+
| MCR Labs Data Collection Routine | <https://github.com/cannlytics/cannlytics/tree/main/ai/curation/get_mcr_labs_data> |
|
164 |
+
| PSI Labs Data Collection Routine | <https://github.com/cannlytics/cannlytics/tree/main/ai/curation/get_psi_labs_data> |
|
165 |
+
| SC Labs Data Collection Routine | <https://github.com/cannlytics/cannlytics/tree/main/ai/curation/get_sc_labs_data> |
|
166 |
+
| Raw Garden Data Collection Routine | <https://github.com/cannlytics/cannlytics/tree/main/ai/curation/get_rawgarden_data> |
|
167 |
+
|
168 |
+
### Personal and Sensitive Information
|
169 |
+
|
170 |
+
The dataset includes public addresses and contact information for related cannabis licensees. It is important to take care to use these data points in a legal manner.
|
171 |
+
|
172 |
+
## Considerations for Using the Data
|
173 |
+
|
174 |
+
### Social Impact of Dataset
|
175 |
+
|
176 |
+
Arguably, there is substantial social impact that could result from the study of cannabis, therefore, researchers and data consumers alike should take the utmost care in the use of this dataset.
|
177 |
+
|
178 |
+
### Discussion of Biases
|
179 |
+
|
180 |
+
Cannlytics is a for-profit data and analytics company that primarily serves cannabis businesses. The data are not randomly collected and thus sampling bias should be taken into consideration.
|
181 |
+
|
182 |
+
### Other Known Limitations
|
183 |
+
|
184 |
+
The data represents only a subset of the population of cannabis lab results. Non-standard values are coded as follows.
|
185 |
+
|
186 |
+
| Actual | Coding |
|
187 |
+
|--------|--------|
|
188 |
+
| `'ND'` | `0.000000001` |
|
189 |
+
| `'No detection in 1 gram'` | `0.000000001` |
|
190 |
+
| `'Negative/1g'` | `0.000000001` |
|
191 |
+
| '`PASS'` | `0.000000001` |
|
192 |
+
| `'<LOD'` | `0.00000001` |
|
193 |
+
| `'< LOD'` | `0.00000001` |
|
194 |
+
| `'<LOQ'` | `0.0000001` |
|
195 |
+
| `'< LOQ'` | `0.0000001` |
|
196 |
+
| `'<LLOQ'` | `0.0000001` |
|
197 |
+
| `'≥ LOD'` | `10001` |
|
198 |
+
| `'NR'` | `None` |
|
199 |
+
| `'N/A'` | `None` |
|
200 |
+
| `'na'` | `None` |
|
201 |
+
| `'NT'` | `None` |
|
202 |
+
## Additional Information
|
203 |
+
|
204 |
+
### Dataset Curators
|
205 |
+
|
206 |
+
Curated by [🔥Cannlytics](https://cannlytics.com)<br>
|
207 | |
208 |
+
|
209 |
+
### License
|
210 |
+
|
211 |
+
```
|
212 |
+
Copyright (c) 2022 Cannlytics and the Cannabis Data Science Team
|
213 |
+
|
214 |
+
The files associated with this dataset are licensed under a
|
215 |
+
Creative Commons Attribution 4.0 International license.
|
216 |
+
|
217 |
+
You can share, copy and modify this dataset so long as you give
|
218 |
+
appropriate credit, provide a link to the CC BY license, and
|
219 |
+
indicate if changes were made, but you may not do so in a way
|
220 |
+
that suggests the rights holder has endorsed you or your use of
|
221 |
+
the dataset. Note that further permission may be required for
|
222 |
+
any content within the dataset that is identified as belonging
|
223 |
+
to a third party.
|
224 |
+
```
|
225 |
+
|
226 |
+
### Citation
|
227 |
+
|
228 |
+
Please cite the following if you use the code examples in your research:
|
229 |
+
|
230 |
+
```bibtex
|
231 |
+
@misc{cannlytics2022,
|
232 |
+
title={Cannabis Data Science},
|
233 |
+
author={Skeate, Keegan and O'Sullivan-Sutherland, Candace},
|
234 |
+
journal={https://github.com/cannlytics/cannabis-data-science},
|
235 |
+
year={2022}
|
236 |
+
}
|
237 |
+
```
|
238 |
+
|
239 |
+
### Contributions
|
240 |
+
|
241 |
+
Thanks to [🔥Cannlytics](https://cannlytics.com), [@candy-o](https://github.com/candy-o), [@keeganskeate](https://github.com/keeganskeate), [The CESC](https://thecesc.org), and the entire [Cannabis Data Science Team](https://meetup.com/cannabis-data-science/members) for their contributions.
|
cannabis_tests.py
ADDED
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Cannabis Tests
|
3 |
+
Copyright (c) 2022 Cannlytics
|
4 |
+
|
5 |
+
Authors:
|
6 |
+
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
+
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
+
Created: 9/10/2022
|
9 |
+
Updated: 9/10/2022
|
10 |
+
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
+
"""
|
12 |
+
import json
|
13 |
+
import datasets # pip install datasets
|
14 |
+
|
15 |
+
# Citation for using the dataset.
|
16 |
+
CANNABIS_TESTS_CITATION = """\
|
17 |
+
@inproceedings{cannlytics2022cannabis_tests,
|
18 |
+
author = {Skeate, Keegan and O'Sullivan-Sutherland, Candace},
|
19 |
+
title = {Cannabis Tests: Curated Cannabis Lab Test Results},
|
20 |
+
booktitle = {Cannabis Data Science},
|
21 |
+
month = {September},
|
22 |
+
year = {2022},
|
23 |
+
address = {United States of America},
|
24 |
+
publisher = {Cannlytics}
|
25 |
+
}
|
26 |
+
"""
|
27 |
+
CANNABIS_TESTS_DESCRIPTION = """\
|
28 |
+
Cannabis lab test results (https://cannlytics.com/data/tests) is a
|
29 |
+
dataset of curated cannabis lab test results.
|
30 |
+
"""
|
31 |
+
CANNABIS_TESTS_URL = 'https://huggingface.co/datasets/cannlytics/cannabis_tests'
|
32 |
+
|
33 |
+
# Raw Garden constants.
|
34 |
+
RAWGARDEN_DATA_URL = 'https://cannlytics.page.link/rawgarden'
|
35 |
+
RAWGARDEN_URL = 'https://github.com/cannlytics/cannlytics/tree/main/ai/curation/get_rawgarden_data'
|
36 |
+
RAWGARDEN_DESCRIPTION = """\
|
37 |
+
Raw Garden lab test results (https://cannlytics.com/data/tests) is a
|
38 |
+
dataset of curated cannabis lab test results from Raw Garden, a large
|
39 |
+
cannabis processor in California.
|
40 |
+
"""
|
41 |
+
RAWGARDEN_FEATURES = []
|
42 |
+
|
43 |
+
# MCR Labs constants.
|
44 |
+
MCRLABS_DATA_URL = 'https://cannlytics.page.link/mcrlabs'
|
45 |
+
MCRLABS_URL = 'https://github.com/cannlytics/cannlytics/tree/main/ai/curation/get_mcr_labs_data'
|
46 |
+
MCRLABS_DESCRIPTION = """\
|
47 |
+
MCR Labs lab test results (https://cannlytics.com/data/tests) is a
|
48 |
+
dataset of curated cannabis lab test results from MCR Labs, a lab that
|
49 |
+
tests cannabis in Massachusetts.
|
50 |
+
"""
|
51 |
+
MCRLABS_FEATURES = []
|
52 |
+
|
53 |
+
# PSI Labs constants.
|
54 |
+
PSILABS_DATA_URL = 'https://cannlytics.page.link/psilabs'
|
55 |
+
PSILABS_URL = 'https://github.com/cannlytics/cannlytics/tree/main/ai/curation/get_psi_labs_data'
|
56 |
+
PSILABS_DESCRIPTION = """\
|
57 |
+
PSI Labs lab test results (https://cannlytics.com/data/tests) is a
|
58 |
+
dataset of curated cannabis lab test results from PSI Labs, a lab that
|
59 |
+
tests cannabis in Michigan.
|
60 |
+
"""
|
61 |
+
PSILABS_FEATURES = []
|
62 |
+
|
63 |
+
# SC Labs constants.
|
64 |
+
SCLABS_DATA_URL = 'https://cannlytics.page.link/sclabs'
|
65 |
+
SCLABS_URL = 'https://github.com/cannlytics/cannlytics/tree/main/ai/curation/get_sc_labs_data'
|
66 |
+
SCLABS_DESCRIPTION = """\
|
67 |
+
SC Labs lab test results (https://cannlytics.com/data/tests) is a
|
68 |
+
dataset of curated cannabis lab test results from SC Labs, a lab that
|
69 |
+
tests cannabis in California.
|
70 |
+
"""
|
71 |
+
SCLABS_FEATURES = []
|
72 |
+
|
73 |
+
|
74 |
+
class CannabisTestsConfig(datasets.BuilderConfig):
|
75 |
+
"""BuilderConfig for Cannabis Tests."""
|
76 |
+
|
77 |
+
def __init__(
|
78 |
+
self,
|
79 |
+
features,
|
80 |
+
data_url,
|
81 |
+
citation,
|
82 |
+
url,
|
83 |
+
label_classes=('False', 'True'),
|
84 |
+
**kwargs
|
85 |
+
):
|
86 |
+
"""BuilderConfig for Cannabis Tests.
|
87 |
+
Args:
|
88 |
+
features (list[str]): A list of the features that will appear in
|
89 |
+
the feature dict. Should not include "label".
|
90 |
+
data_url (str): A URL to download the zip file from.
|
91 |
+
citation (str): A citation for the data set.
|
92 |
+
url (str): A URL for information about the data set.
|
93 |
+
label_classes (list[str]): The list of classes for the label if
|
94 |
+
the label is present as a string. Non-string labels will be
|
95 |
+
cast to either 'False' or 'True'.
|
96 |
+
**kwargs: Keyword arguments forwarded to super.
|
97 |
+
"""
|
98 |
+
super(CannabisTestsConfig, self).__init__(version=datasets.Version("1.0.2"), **kwargs)
|
99 |
+
self.features = features
|
100 |
+
self.label_classes = label_classes
|
101 |
+
self.data_url = data_url
|
102 |
+
self.citation = citation
|
103 |
+
self.url = url
|
104 |
+
|
105 |
+
|
106 |
+
class CannabisTests(datasets.GeneratorBasedBuilder):
|
107 |
+
"""The Cannabis Tests dataset."""
|
108 |
+
|
109 |
+
VERSION = datasets.Version('1.0.0')
|
110 |
+
|
111 |
+
BUILDER_CONFIGS = [
|
112 |
+
CannabisTestsConfig(
|
113 |
+
name='rawgarden',
|
114 |
+
description=RAWGARDEN_DESCRIPTION,
|
115 |
+
features=RAWGARDEN_FEATURES,
|
116 |
+
data_url=RAWGARDEN_DATA_URL,
|
117 |
+
citation=CANNABIS_TESTS_CITATION,
|
118 |
+
url=RAWGARDEN_URL,
|
119 |
+
),
|
120 |
+
CannabisTestsConfig(
|
121 |
+
name='mcrlabs',
|
122 |
+
description=MCRLABS_DESCRIPTION,
|
123 |
+
features=MCRLABS_FEATURES,
|
124 |
+
data_url=MCRLABS_DATA_URL,
|
125 |
+
citation=CANNABIS_TESTS_CITATION,
|
126 |
+
url=MCRLABS_URL,
|
127 |
+
),
|
128 |
+
CannabisTestsConfig(
|
129 |
+
name='psilabs',
|
130 |
+
description=PSILABS_DESCRIPTION,
|
131 |
+
features=PSILABS_FEATURES,
|
132 |
+
data_url=PSILABS_DATA_URL,
|
133 |
+
citation=CANNABIS_TESTS_CITATION,
|
134 |
+
url=PSILABS_URL,
|
135 |
+
),
|
136 |
+
CannabisTestsConfig(
|
137 |
+
name='sclabs',
|
138 |
+
description=SCLABS_DESCRIPTION,
|
139 |
+
features=SCLABS_FEATURES,
|
140 |
+
data_url=SCLABS_DATA_URL,
|
141 |
+
citation=CANNABIS_TESTS_CITATION,
|
142 |
+
url=SCLABS_URL,
|
143 |
+
),
|
144 |
+
]
|
145 |
+
|
146 |
+
DEFAULT_CONFIG_NAME = 'rawgarden'
|
147 |
+
|
148 |
+
def _info(self):
|
149 |
+
features = {feature: datasets.Value('string') for feature in self.config.features}
|
150 |
+
|
151 |
+
# TODO: Define all numeric features.
|
152 |
+
# features['span1_index'] = datasets.Value('int32')
|
153 |
+
|
154 |
+
# TODO: Define all image features.
|
155 |
+
|
156 |
+
# TODO: Define all sequence features.
|
157 |
+
# features["answers"] = datasets.features.Sequence(
|
158 |
+
# {"text": datasets.Value("string"), "answer_start": datasets.Value("int32"),}
|
159 |
+
# )
|
160 |
+
|
161 |
+
return datasets.DatasetInfo(
|
162 |
+
citation=CANNABIS_TESTS_CITATION,
|
163 |
+
description=CANNABIS_TESTS_DESCRIPTION,
|
164 |
+
features=features,
|
165 |
+
homepage=CANNABIS_TESTS_URL,
|
166 |
+
supervised_keys=None,
|
167 |
+
)
|
168 |
+
|
169 |
+
def _generate_examples(self, filepath):
|
170 |
+
"""This function returns the examples in raw (text) form."""
|
171 |
+
with open(filepath, encoding='utf-8') as f:
|
172 |
+
for line in f:
|
173 |
+
row = json.loads(line)
|
174 |
+
product_name = row.get('product_name', '').strip()
|
175 |
+
for i, result in enumerate(row['results']):
|
176 |
+
_id = str(i)
|
177 |
+
yield _id, {
|
178 |
+
'product_name': product_name,
|
179 |
+
'analyte': result.get('key', ''),
|
180 |
+
'value': result.get('value', 0),
|
181 |
+
}
|