├── LICENSE ├── README.md └── sourcing_sprint ├── app.py ├── catalogue ├── __init__.py ├── catalogue_forms.py ├── catalogue_utils.py └── geography.py ├── entries ├── .gitignore ├── ksucca_king_saud_university_corpus_of_classical_arabic.json ├── le_monde_newspaper.json └── masakhane.json ├── entry_submitted_by └── .gitignore ├── guide.md ├── resources ├── .gitignore ├── bcp47.json ├── country_center_coordinates.json ├── country_mappings.json ├── country_regions.json ├── file_formats.json ├── language_lists.json ├── licenses.json ├── pii_categories.json ├── primary_source_taxonomy.json └── programming_languages.json └── streamlit_form.py /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BigScience Data Sourcing Code 2 | 3 | This directory gathers the tools developed by the Data Sourcing Working Group 4 | 5 | ## First Sourcing Sprint: October 2021 6 | 7 | The code for the input form can be found in `sourcing_sprint/streamlit_form.py` 8 | 9 | The code for the exploration tool can be found in `sourcing_sprint/streamlit_explore.py` 10 | 11 | The resource entries can be found in `sourcing_sprint/resources` (one folder per language, one `.jsonl` file per resource) 12 | -------------------------------------------------------------------------------- /sourcing_sprint/app.py: -------------------------------------------------------------------------------- 1 | import json 2 | import re 3 | from datetime import datetime 4 | from os.path import join as pjoin 5 | 6 | import streamlit as st 7 | from streamlit_folium import folium_static 8 | 9 | from catalogue import ( 10 | app_categories, 11 | can_save, 12 | countries, 13 | filter_catalogue_visualization, 14 | filter_entry, 15 | form_availability, 16 | form_custodian, 17 | form_general_info_add, 18 | form_languages_add, 19 | form_languages_val, 20 | form_media, 21 | form_processed_from_primary, 22 | form_source_category, 23 | load_catalogue, 24 | make_choro_map, 25 | region_tree, 26 | select_entry_val, 27 | ) 28 | 29 | ################## 30 | ## streamlit 31 | ################## 32 | st.set_page_config( 33 | page_title="BigScience Language Resource Catalogue Input Form", 34 | page_icon="https://avatars.githubusercontent.com/u/82455566", 35 | layout="wide", 36 | initial_sidebar_state="auto", 37 | ) 38 | 39 | query_params = st.experimental_get_query_params() 40 | 41 | page_description = """ 42 | # BigScience Data Catalogue 43 | 44 | This application serves as the landing page for the **Catalogue of Language Data and Resources** 45 | that is being built and maintained as part of the [BigScience workshop](https://bigscience.huggingface.co/). 46 | 47 | The Catalogue app currently supports the following three functionalities: 48 | - **Add a new entry**: This form can be used to add a new entry to the BigScience Data Sourcing Catalogue. To do so, enter add your name and email 49 | then fill out the form according to the [**instructions.**](https://github.com/bigscience-workshop/data_sourcing/blob/master/sourcing_sprint/guide.md#guide-to-submitting-sources-to-the-bigscience-data-sourcing-hackathon) 50 | - **Explore the current catalogue**: This page lets you explore the current catalogue and the geographical distribution of the entries. 51 | - **Validate an existing entry**: Use this functionality to verify or add information to an existing entry. 52 | 53 | Choose which functionality you want to make use of below. 54 | """ 55 | 56 | page_modes = { 57 | "add": "Add a new entry", 58 | "viz": "Explore the current catalogue", 59 | "val": "Validate an existing entry", 60 | } 61 | 62 | 63 | def main(): 64 | if "save_state" not in st.session_state: 65 | st.session_state.save_state = {} 66 | 67 | st.sidebar.markdown(page_description, unsafe_allow_html=True) 68 | pages = { 69 | "add": add_page, 70 | "viz": viz_page, 71 | "val": val_page, 72 | } 73 | app_mode = st.sidebar.radio( 74 | label="App mode:", 75 | options=list(page_modes.keys()), 76 | format_func=lambda x: page_modes[x], 77 | index=list(page_modes).index(query_params.get("mode", ["add"])[0]), 78 | ) 79 | submission_info_dict = { 80 | "entry_uid": "", 81 | "submitted_by": "", 82 | "submitted_email": "", 83 | "submitted_date": "", 84 | "validated_by": "", 85 | "validated_date": "", 86 | } 87 | with st.sidebar.expander("User information", expanded=app_mode != "viz"): 88 | user_name = st.text_input(label="Name of submitter:") 89 | user_email = st.text_input(label="Email:") 90 | if app_mode == "add": 91 | submission_info_dict["submitted_by"] = user_name 92 | submission_info_dict["submitted_email"] = user_email 93 | else: 94 | submission_info_dict["validated_by"] = user_name 95 | st.markdown( 96 | "[Privacy policy](https://github.com/bigscience-workshop/data_sourcing/wiki/Required-User-Information-and-Privacy-Policy)" 97 | ) 98 | st.markdown("#### BigScience Catalogue of Language Data and Resources\n---\n") 99 | pages[app_mode](submission_info_dict) 100 | 101 | 102 | ################## 103 | ## SECTION: Add a new entry 104 | ################## 105 | def add_page(submission_info_dict): 106 | entry_dict = { 107 | "uid": "", # Unique Identifier string to link information and refer to the entry 108 | "type": "", # in ["Primary source", "Language dataset", "Language organization"] 109 | "description": { 110 | "name": "", 111 | "description": "", 112 | "homepage": "", # optional 113 | "validated": True, # no need to have a second person validate this part 114 | }, 115 | "languages": { 116 | "language_names": [], 117 | "language_comments": "", 118 | "language_locations": [], 119 | "validated": False, 120 | }, 121 | "custodian": { # for Primary source or Language daset - data owner or custodian 122 | "name": "", 123 | "in_catalogue": "", 124 | "type": "", 125 | "location": "", 126 | "contact_name": "", 127 | "contact_email": "", 128 | "contact_submitter": False, 129 | "additional": "", 130 | "validated": False, 131 | }, 132 | } 133 | catalogue = [entry_ls[-1] for entry_ls in load_catalogue()] # get latest update 134 | st.markdown("### Entry Category, Name, ID, Homepage, Description") 135 | form_general_info_add(entry_dict, app_categories) 136 | st.markdown("### Entry Languages and Locations") 137 | form_languages_add(entry_dict, app_categories, countries, region_tree) 138 | st.markdown("### Entry Representative, Owner, or Custodian") 139 | form_custodian(entry_dict, app_categories, countries, catalogue, "add") 140 | if entry_dict["type"] in ["primary", "processed"]: 141 | st.markdown("### Availability of the Resource: Procuring, Licenses, PII") 142 | form_availability(entry_dict, app_categories, "add") 143 | if entry_dict["type"] == "primary": 144 | st.markdown("### Primary Source Type") 145 | form_source_category(entry_dict, app_categories, "add") 146 | if entry_dict["type"] == "processed": 147 | st.markdown("### Primary Sources of the Processed Dataset") 148 | form_processed_from_primary(entry_dict, app_categories, catalogue, "add") 149 | if entry_dict["type"] in ["primary", "processed"]: 150 | st.markdown("### Media type, format, size, and processing needs") 151 | form_media(entry_dict, app_categories, "add") 152 | st.markdown("### Review and Save Entry") 153 | with st.expander("Show current entry", expanded=True): 154 | st.markdown( 155 | "Do not forget to **save your entry** to the BigScience Data Catalogue!\n\nOnce you are done, please press the button below - this will either record the entry or tell you if there's anything you need to change first." 156 | ) 157 | if st.button("Save entry to catalogue"): 158 | good_to_save, save_message = can_save( 159 | entry_dict, submission_info_dict, True 160 | ) 161 | if good_to_save: 162 | submission_info_dict["entry_uid"] = entry_dict["uid"] 163 | submission_info_dict["submitted_date"] = datetime.now().strftime( 164 | "%m/%d/%Y, %H:%M:%S" 165 | ) 166 | json.dump( 167 | entry_dict, 168 | open( 169 | pjoin("entries", f"{entry_dict['uid']}.json"), 170 | "w", 171 | encoding="utf-8", 172 | ), 173 | indent=2, 174 | ) 175 | json.dump( 176 | submission_info_dict, 177 | open( 178 | pjoin("entry_submitted_by", f"{entry_dict['uid']}.json"), 179 | "w", 180 | encoding="utf-8", 181 | ), 182 | indent=2, 183 | ) 184 | else: 185 | st.markdown("##### Unable to save\n" + save_message) 186 | st.markdown(f"You are entering a new resource of type: *{entry_dict['type']}*") 187 | st.write(entry_dict) 188 | st.markdown( 189 | "You can also download the entry as a `json` file with the following button:" 190 | ) 191 | st.download_button( 192 | label="Download entry dictionary", 193 | data=json.dumps(entry_dict, indent=2), 194 | file_name="default_entry_name.json" 195 | if entry_dict["uid"] == "" 196 | else f"{entry_dict['uid']}.json", 197 | ) 198 | # save 199 | for k, v in st.session_state.items(): 200 | if k != "save_state": 201 | st.session_state.save_state[k] = v 202 | 203 | 204 | ################## 205 | ## SECTION: Explore the current catalogue 206 | ################## 207 | def viz_page(submission_info_dict): 208 | catalogue = [entry_ls[-1] for entry_ls in load_catalogue()] # get latest update 209 | filtered_catalogue = filter_catalogue_visualization(catalogue, app_categories) 210 | with st.expander("Map of entries", expanded=True): 211 | entry_location_type = st.radio( 212 | label="I want to visualize", 213 | options=[ 214 | "Where the organizations or data custodians are located", 215 | "Where the language data creators are located", 216 | ], 217 | key="viz_show_location_type", 218 | ) 219 | show_by_org = ( 220 | entry_location_type 221 | == "Where the organizations or data custodians are located" 222 | ) 223 | filtered_counts = {} 224 | for entry in filtered_catalogue: 225 | locations = ( 226 | [entry["custodian"]["location"]] 227 | if show_by_org 228 | else entry["languages"]["language_locations"] 229 | ) 230 | # be as specific as possible 231 | locations = [ 232 | loc 233 | for loc in locations 234 | if not any([l in region_tree.get(loc, []) for l in locations]) 235 | ] 236 | for loc in locations: 237 | filtered_counts[loc] = filtered_counts.get(loc, 0) + 1 238 | world_map = make_choro_map(filtered_counts) 239 | folium_static(world_map, width=1150, height=600) 240 | with st.expander("View selected resources", expanded=False): 241 | st.write("You can further select locations to select entries from here:") 242 | filter_region_choices = sorted( 243 | set( 244 | [ 245 | loc 246 | for entry in filtered_catalogue 247 | for loc in ( 248 | [entry["custodian"]["location"]] 249 | if show_by_org 250 | else entry["languages"]["language_locations"] 251 | ) 252 | ] 253 | ) 254 | ) 255 | filter_locs = st.multiselect( 256 | "View entries from the following locations:", 257 | options=filter_region_choices, 258 | key="viz_select_location", 259 | ) 260 | filter_loc_dict = ( 261 | {"custodian": {"location": filter_locs}} 262 | if show_by_org 263 | else {"languages": {"language_locations": filter_locs}} 264 | ) 265 | filtered_catalogue_by_loc = [ 266 | entry 267 | for entry in filtered_catalogue 268 | if filter_entry(entry, filter_loc_dict) 269 | ] 270 | view_entry = st.selectbox( 271 | label="Select an entry to see more detail:", 272 | options=filtered_catalogue_by_loc, 273 | format_func=lambda entry: f"{entry['uid']} | {entry['description']['name']} -- {entry['description']['description']}", 274 | key="viz_select_entry", 275 | ) 276 | st.markdown( 277 | f"##### *Type:* {view_entry['type']} *UID:* {view_entry['uid']} - *Name:* {view_entry['description']['name']}\n\n{view_entry['description']['description']}" 278 | ) 279 | 280 | 281 | ################## 282 | ## SECTION: Validate an existing entry 283 | ################## 284 | def val_page(submission_info_dict): 285 | st.markdown("### Entry selection") 286 | catalogue = load_catalogue() # all updates to flag already validated 287 | entry_dict = select_entry_val(catalogue, app_categories) 288 | st.markdown("### Entry Languages and Locations") 289 | if "languages" in entry_dict: 290 | form_languages_val(entry_dict, app_categories, countries, region_tree) 291 | if "custodian" in entry_dict: 292 | st.markdown("### Entry Representative, Owner, or Custodian") 293 | form_custodian( 294 | entry_dict, 295 | app_categories, 296 | countries, 297 | [entry_ls[-1] for entry_ls in catalogue], 298 | "val", 299 | ) 300 | if "availability" in entry_dict: 301 | st.markdown("### Availability of the Resource: Procuring, Licenses, PII") 302 | form_availability(entry_dict, app_categories, "val") 303 | if "source_category" in entry_dict and entry_dict["type"] == "primary": 304 | st.markdown("### Primary Source Type") 305 | form_source_category(entry_dict, app_categories, "val") 306 | if "processed_from_primary" in entry_dict and entry_dict["type"] == "processed": 307 | st.markdown("### Primary Sources of the Processed Dataset") 308 | form_processed_from_primary( 309 | entry_dict, app_categories, [entry_ls[-1] for entry_ls in catalogue], "val" 310 | ) 311 | if "media" in entry_dict and entry_dict["type"] in ["primary", "processed"]: 312 | st.markdown("### Media type, format, size, and processing needs") 313 | form_media(entry_dict, app_categories, "val") 314 | st.markdown("### Review and Save Entry") 315 | with st.expander("Show current entry", expanded=True): 316 | st.markdown( 317 | "Do not forget to **save your work** to the BigScience Data Catalogue!\n\nOnce you are done, please press the button below - this will either record the entry or tell you if there's anything you need to change first." 318 | ) 319 | if st.button("Save validated entry to catalogue"): 320 | good_to_save, save_message = can_save( 321 | entry_dict, submission_info_dict, False 322 | ) 323 | if good_to_save: 324 | validation_info_dict = json.load( 325 | open( 326 | pjoin("entry_submitted_by", f"{entry_dict['uid']}.json"), 327 | encoding="utf-8", 328 | ) 329 | ) 330 | validation_info_dict["validated_by"] = submission_info_dict[ 331 | "validated_by" 332 | ] 333 | validation_info_dict["validated_date"] = datetime.now().strftime( 334 | "%m/%d/%Y, %H:%M:%S" 335 | ) 336 | friendly_date = re.sub( 337 | r"[^\w\s]", "_", validation_info_dict["validated_date"] 338 | ).replace(" ", "_") 339 | json.dump( 340 | entry_dict, 341 | open( 342 | pjoin( 343 | "entries", 344 | f"{entry_dict['uid']}-validated-{friendly_date}.json", 345 | ), 346 | "w", 347 | encoding="utf-8", 348 | ), 349 | indent=2, 350 | ) 351 | json.dump( 352 | validation_info_dict, 353 | open( 354 | pjoin( 355 | "entry_submitted_by", 356 | f"{entry_dict['uid']}-validated-{friendly_date}.json", 357 | ), 358 | "w", 359 | encoding="utf-8", 360 | ), 361 | indent=2, 362 | ) 363 | else: 364 | st.markdown("##### Unable to save\n" + save_message) 365 | st.markdown(f"You are validating a resource of type: *{entry_dict['type']}*") 366 | st.write(entry_dict) 367 | st.markdown( 368 | "You can also download the entry as a `json` file with the following button:" 369 | ) 370 | st.download_button( 371 | label="Download entry dictionary", 372 | data=json.dumps(entry_dict, indent=2), 373 | file_name="default_entry_name.json" 374 | if entry_dict["uid"] == "" 375 | else f"{entry_dict['uid']}.json", 376 | ) 377 | 378 | 379 | if __name__ == "__main__": 380 | main() 381 | -------------------------------------------------------------------------------- /sourcing_sprint/catalogue/__init__.py: -------------------------------------------------------------------------------- 1 | from .catalogue_forms import ( 2 | filter_catalogue_visualization, 3 | filter_entry, 4 | form_availability, 5 | form_custodian, 6 | form_general_info_add, 7 | form_languages_add, 8 | form_languages_val, 9 | form_media, 10 | form_processed_from_primary, 11 | form_source_category, 12 | select_entry_val, 13 | ) 14 | from .catalogue_utils import app_categories, can_save, load_catalogue 15 | from .geography import countries, make_choro_map, region_tree 16 | -------------------------------------------------------------------------------- /sourcing_sprint/catalogue/catalogue_utils.py: -------------------------------------------------------------------------------- 1 | import json 2 | from glob import glob 3 | from os.path import isfile 4 | from os.path import join as pjoin 5 | 6 | import streamlit as st 7 | 8 | app_categories = { 9 | "entry_types": { 10 | "primary": "Primary source", 11 | "processed": "Processed language dataset", 12 | "organization": "Language organization or advocate", 13 | }, 14 | # 15 | "language_lists": json.load( 16 | open("resources/language_lists.json", encoding="utf-8") 17 | ), 18 | "programming_languages": [ 19 | x 20 | for x in json.load( 21 | open("resources/programming_languages.json", encoding="utf-8") 22 | )["itemListElement"] 23 | ], 24 | "languages_bcp47": [ 25 | x 26 | for x in json.load(open("resources/bcp47.json", encoding="utf-8"))["subtags"] 27 | if x["type"] == "language" 28 | ], 29 | # 30 | "custodian_types": [ 31 | "A private individual", 32 | "A commercial entity", 33 | "A library, museum, or archival institute", 34 | "A university or research institution", 35 | "A nonprofit/NGO (other)", 36 | "A government organization", 37 | ], 38 | "pii_categories": json.load( 39 | open("resources/pii_categories.json", encoding="utf-8") 40 | ), 41 | "licenses": json.load(open("resources/licenses.json", encoding="utf-8")), 42 | "primary_taxonomy": json.load( 43 | open("resources/primary_source_taxonomy.json", encoding="utf-8") 44 | ), 45 | "file_formats": json.load(open("resources/file_formats.json", encoding="utf-8")), 46 | } 47 | 48 | 49 | def load_catalogue(): 50 | catalogue_list = [ 51 | (fname.split("/")[-1], json.load(open(fname, encoding="utf-8"))) 52 | for fname in glob("entries/*.json") 53 | if not "-validated-" in fname 54 | ] 55 | for fname, dct in catalogue_list: 56 | dct["fname"] = fname 57 | catalogue = dict( 58 | [ 59 | ( 60 | "", 61 | [ 62 | { 63 | "uid": "", 64 | "fname": "", 65 | "type": "", 66 | "description": { 67 | "name": "", 68 | "description": "", 69 | }, 70 | } 71 | ], 72 | ) 73 | ] 74 | + [(dct["uid"], [dct]) for _, dct in catalogue_list] 75 | ) 76 | for fname in glob("entries/*-validated-*.json"): 77 | uid, date_str = fname.split("/")[-1][:-5].split("-validated-") 78 | entry_dct = json.load(open(fname, encoding="utf-8")) 79 | entry_dct["update_time"] = date_str 80 | entry_dct["fname"] = fname.split("/")[-1] 81 | catalogue[uid] += [entry_dct] 82 | catalogue[uid] = sorted( 83 | catalogue[uid], key=lambda x: x.get("update_time", "00") 84 | ) 85 | return list(catalogue.values()) 86 | 87 | 88 | def can_save(entry_dct, submission_dct, adding_mode): 89 | if adding_mode and ( 90 | entry_dct["uid"] == "" or isfile(pjoin("entries", f"{entry_dct['uid']}.json")) 91 | ): 92 | return ( 93 | False, 94 | f"There is already an entry with `uid` {entry_dct['uid']}, you need to give your entry a different one before saving. You can look at the entry with this `uid` by switching to the **Validate an existing entry** mode of this app in the left sidebar.", 95 | ) 96 | if adding_mode and ( 97 | submission_dct["submitted_by"] == "" or submission_dct["submitted_email"] == "" 98 | ): 99 | return ( 100 | False, 101 | f"Please enter a name (or pseudonym) and email in the left sidebar before submitting this entry. [Privacy policy](https://github.com/bigscience-workshop/data_sourcing/wiki/Required-User-Information-and-Privacy-Policy)", 102 | ) 103 | if not adding_mode and submission_dct["validated_by"] == "": 104 | return ( 105 | False, 106 | f"Please enter a name (or pseudonym) in the left sidebar before validating this entry.", 107 | ) 108 | if not adding_mode and not all( 109 | [v.get("validated", False) for k, v in entry_dct.items() if isinstance(v, dict)] 110 | ): 111 | unvalidated = [ 112 | k 113 | for k, v in entry_dct.items() 114 | if isinstance(v, dict) and not v.get("validated", False) 115 | ] 116 | return False, f"Some of the fields haven't been validated: {unvalidated}" 117 | else: 118 | return True, "" 119 | -------------------------------------------------------------------------------- /sourcing_sprint/catalogue/geography.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | import folium 4 | import pandas as pd 5 | from folium import Marker 6 | from folium.plugins import MarkerCluster 7 | from jinja2 import Template 8 | 9 | regions, countries, region_tree = json.load( 10 | open("resources/country_regions.json", encoding="utf-8") 11 | ) 12 | country_centers = json.load( 13 | open("resources/country_center_coordinates.json", encoding="utf-8") 14 | ) 15 | country_mappings = json.load(open("resources/country_mappings.json", encoding="utf-8")) 16 | 17 | WORLD_GEO_URL = "https://raw.githubusercontent.com/python-visualization/folium/master/examples/data/world-countries.json" 18 | 19 | ICON_CREATE_FUNCTIOM = """ 20 | function(cluster) { 21 | var markers = cluster.getAllChildMarkers(); 22 | var sum = 0; 23 | for (var i = 0; i < markers.length; i++) { 24 | sum += markers[i].options.props.resources; 25 | } 26 | 27 | return L.divIcon({ 28 | html: '' + sum + '', 29 | className: 'marker-cluster marker-cluster-small', 30 | iconSize: new L.Point(20, 20) 31 | }); 32 | } 33 | """ 34 | 35 | 36 | class MarkerWithProps(Marker): 37 | _template = Template( 38 | """ 39 | {% macro script(this, kwargs) %} 40 | var {{this.get_name()}} = L.marker( 41 | [{{this.location[0]}}, {{this.location[1]}}], 42 | { 43 | icon: new L.Icon.Default(), 44 | {%- if this.draggable %} 45 | draggable: true, 46 | autoPan: true, 47 | {%- endif %} 48 | {%- if this.props %} 49 | props : {{ this.props }} 50 | {%- endif %} 51 | } 52 | ) 53 | .addTo({{this._parent.get_name()}}); 54 | {% endmacro %} 55 | """ 56 | ) 57 | 58 | def __init__( 59 | self, location, popup=None, tooltip=None, icon=None, draggable=False, props=None 60 | ): 61 | super(MarkerWithProps, self).__init__( 62 | location=location, 63 | popup=popup, 64 | tooltip=tooltip, 65 | icon=icon, 66 | draggable=draggable, 67 | ) 68 | self.props = json.loads(json.dumps(props)) 69 | 70 | 71 | def get_region_center(region_name): 72 | latitudes = [] 73 | longitudes = [] 74 | for name in region_tree[region_name]: 75 | if name in region_tree: 76 | region_latitudes, region_longitudes = get_region_center(name) 77 | latitudes += region_latitudes 78 | longitudes += region_longitudes 79 | elif name in country_centers or name in country_mappings["to_center"]: 80 | country_center = country_centers[ 81 | country_mappings["to_center"].get(name, name) 82 | ] 83 | latitudes += [float(country_center["latitude"])] 84 | longitudes += [float(country_center["longitude"])] 85 | return latitudes, longitudes 86 | 87 | 88 | def get_region_countries(region_name): 89 | countries = [] 90 | for name in region_tree[region_name]: 91 | if name in region_tree: 92 | countries += get_region_countries(name) 93 | else: 94 | countries += [name] 95 | return countries 96 | 97 | 98 | def make_choro_map(resource_counts, marker_thres=0): 99 | world_map = folium.Map(tiles="cartodbpositron", location=[0, 0], zoom_start=1.5) 100 | marker_cluster = MarkerCluster(icon_create_function=ICON_CREATE_FUNCTIOM) 101 | marker_cluster.add_to(world_map) 102 | for name, count in resource_counts.items(): 103 | if name in country_centers or name in country_mappings["to_center"]: 104 | country_center = country_centers[ 105 | country_mappings["to_center"].get(name, name) 106 | ] 107 | MarkerWithProps( 108 | location=[country_center["latitude"], country_center["longitude"]], 109 | popup=f"{'Region' if name in region_tree else 'Country'} : {name}
\n Resources : {count}
", 110 | props={"name": name, "resources": count}, 111 | ).add_to(marker_cluster) 112 | # put a pin at the center of the region 113 | elif name in region_tree: 114 | latitudes, longitudes = get_region_center(name) 115 | if len(latitudes) > 0: 116 | lat = sum(latitudes) / len(latitudes) 117 | lon = sum(longitudes) / len(longitudes) 118 | MarkerWithProps( 119 | location=[lat, lon], 120 | popup=f"{'Region' if name in region_tree else 'Country'} : {name}
\n Resources : {count}
", 121 | props={"name": name, "resources": count}, 122 | ).add_to(marker_cluster) 123 | # for choropleth, add counts to all countries in a region 124 | choropleth_counts = {} 125 | for loc_name in list(resource_counts.keys()): 126 | if loc_name in region_tree: 127 | for country_name in get_region_countries(loc_name): 128 | choropleth_counts[country_name] = ( 129 | choropleth_counts.get(country_name, 0) + resource_counts[loc_name] 130 | ) 131 | else: 132 | choropleth_counts[loc_name] = ( 133 | choropleth_counts.get(loc_name, 0) + resource_counts[loc_name] 134 | ) 135 | df_resource_counts = pd.DataFrame( 136 | [ 137 | (country_mappings["to_outline"].get(n, n), c) 138 | for n, c in choropleth_counts.items() 139 | ], 140 | columns=["Name", "Resources"], 141 | ) 142 | folium.Choropleth( 143 | geo_data=WORLD_GEO_URL, 144 | name="resource map", 145 | data=df_resource_counts, 146 | columns=["Name", "Resources"], 147 | key_on="feature.properties.name", 148 | fill_color="PuRd", 149 | nan_fill_color="white", 150 | ).add_to(world_map) 151 | return world_map 152 | -------------------------------------------------------------------------------- /sourcing_sprint/entries/.gitignore: -------------------------------------------------------------------------------- 1 | */*.jsonl 2 | 3 | -------------------------------------------------------------------------------- /sourcing_sprint/entries/ksucca_king_saud_university_corpus_of_classical_arabic.json: -------------------------------------------------------------------------------- 1 | { 2 | "uid": "ksucca_king_saud_university_corpus_of_classical_arabic", 3 | "type": "processed", 4 | "description": { 5 | "name": "KSUCCA King Saud University Corpus of Classical Arabic", 6 | "description": "King Saud University Corpus of Classical Arabic (KSUCCA) is a pioneering 50 million tokens annotated corpus of Classical Arabic texts from the period of pre-Islamic era until the fourth Hijri century (equivalent to the period from the seventh until early eleventh century CE), which is the period of pure classical Arabic. The main aim of this corpus is to be used for studying the distributional lexical semantics of The Quran words. However, it can be used for other research purposes, such as:\n\u2022 Arabic linguistics, which includes: lexical, morphological, syntactic, semantic and pragmatic research.\n\u2022 Arabic computational linguistics, which includes: lexical, morphological, syntactic, semantic and pragmatic research including their various applications.\n\u2022 Arabic language teaching for both Arabs and non Arabs.\n\u2022 Artificial intelligence.\n\u2022 Natural language processing.\n\u2022 Information retrieval.\n\u2022 Question answering.\n\u2022 Machine translation.", 7 | "homepage": "https://sourceforge.net/projects/ksucca-corpus/", 8 | "validated": true 9 | }, 10 | "languages": { 11 | "language_names": [ 12 | "Arabic", 13 | "ar-CLS" 14 | ], 15 | "language_comments": "Historical Arabic texts from the seventh until early eleventh century CE", 16 | "language_locations": [ 17 | "Northern Africa", 18 | "Western Asia" 19 | ], 20 | "validated": false 21 | }, 22 | "custodian": { 23 | "name": "King Saud University", 24 | "type": "A university or research institution", 25 | "location": "Saudi Arabia", 26 | "contact_name": "Maha Alrabiah", 27 | "contact_email": "msrabiah@gmail.com", 28 | "contact_submitter": true, 29 | "additional": "https://www.ksu.edu.sa/en/", 30 | "validated": false 31 | }, 32 | "availability": { 33 | "procurement": { 34 | "for_download": "Yes - it has a direct download link or links", 35 | "download_url": "https://sourceforge.net/projects/ksucca-corpus/", 36 | "download_email": "" 37 | }, 38 | "licensing": { 39 | "has_licenses": "Yes", 40 | "license_text": "", 41 | "license_properties": [ 42 | "open license", 43 | "non-commercial use" 44 | ], 45 | "license_list": [ 46 | "cc-by-nc-2.0: Creative Commons Attribution Non Commercial 2.0 Generic" 47 | ] 48 | }, 49 | "pii": { 50 | "has_pii": "No", 51 | "generic_pii_likely": "", 52 | "generic_pii_list": [], 53 | "numeric_pii_likely": "", 54 | "numeric_pii_list": [], 55 | "sensitive_pii_likely": "", 56 | "sensitive_pii_list": [], 57 | "no_pii_justification_class": "other", 58 | "no_pii_justification_text": "historical texts that are more than 100 years old" 59 | }, 60 | "validated": false 61 | }, 62 | "processed_from_primary": { 63 | "from_primary": "Taken from primary source", 64 | "primary_availability": "Yes - their documentation/homepage/description is available", 65 | "primary_license": "Yes - the source material has an open license that allows re-use", 66 | "primary_types": [ 67 | "books/book publisher" 68 | ], 69 | "validated": false 70 | }, 71 | "media": { 72 | "category": [ 73 | "text" 74 | ], 75 | "text_format": [ 76 | "plain text" 77 | ], 78 | "audiovisual_format": [], 79 | "image_format": [], 80 | "text_is_transcribed": "No", 81 | "instance_type": "book", 82 | "instance_count": "10010,000", 84 | "validated": false 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /sourcing_sprint/entries/le_monde_newspaper.json: -------------------------------------------------------------------------------- 1 | { 2 | "uid": "le_monde_newspaper", 3 | "type": "primary", 4 | "description": { 5 | "name": "Le Monde Newspaper", 6 | "description": "Le Monde is a French daily afternoon newspaper. It is the main publication of Le Monde Group and reported an average circulation of 323,039 copies per issue in 2009, about 40,000 of which were sold abroad. It has had its own website since 19 December 1995, and is often the only French newspaper easily obtainable in non-French-speaking countries. It is considered one of the French newspapers of record, along with Lib\u00e9ration, and Le Figaro. It should not be confused with the monthly publication Le Monde diplomatique, of which Le Monde has 51% ownership, but which is editorially independent. A Reuters Institute poll in 2021 in France found that \"Le Monde is the most trusted national newspaper\".", 7 | "homepage": "https://www.lemonde.fr/", 8 | "validated": true 9 | }, 10 | "languages": { 11 | "language_names": [ 12 | "French" 13 | ], 14 | "language_comments": "", 15 | "language_locations": [ 16 | "France" 17 | ], 18 | "validated": false 19 | }, 20 | "custodian": { 21 | "name": "Le Monde Group", 22 | "type": "A commercial entity", 23 | "location": "France", 24 | "contact_name": "Sacha Morard", 25 | "contact_email": "droitsdauteur@lemonde.fr", 26 | "contact_submitter": true, 27 | "additional": "https://fr.wikipedia.org/wiki/Groupe_Le_Monde", 28 | "validated": false 29 | }, 30 | "availability": { 31 | "procurement": { 32 | "for_download": "No - we would need to spontaneously reach out to the current owners/custodians", 33 | "download_url": "morard@lemonde.fr", 34 | "download_email": "" 35 | }, 36 | "licensing": { 37 | "has_licenses": "Yes", 38 | "license_text": "https://moncompte.lemonde.fr/cgv#ancre_propriete\n\nLe Monde est titulaire des droits de propri\u00e9t\u00e9 intellectuelle sur tous les \u00e9l\u00e9ments qui composent ses publications, ses Produits et/ou Services et ses supports de communication, tels que texte, photographie, image, infographie, dessins, logo, enregistrement phonographique ou vid\u00e9ographique, format \u00e9ditorial, charte graphique, programme informatique ou toute autre cr\u00e9ation ou \u0153uvre prot\u00e9geable, ou s\u2019est vu conc\u00e9der les licences n\u00e9cessaires sur les droits de propri\u00e9t\u00e9 intellectuelle y aff\u00e9rents.\n\nQu\u2019ils soient accessibles gratuitement ou non, toute reproduction, repr\u00e9sentation, diffusion, traduction ou exploitation totale ou partielle, de quelque nature que ce soit et par quelque moyen que ce soit, de l\u2019un quelconque de ces \u00e9l\u00e9ments, sans l\u2019autorisation \u00e9crite et pr\u00e9alable du Monde, est strictement interdite et constituerait, au regard des articles L. 335-2 du Code de la propri\u00e9t\u00e9 intellectuelle, un d\u00e9lit de contrefa\u00e7on passible de trois ans d\u2019emprisonnement et 300 000 \u20ac d\u2019amende.\n\nLe Monde est en outre propri\u00e9taire exclusif des marques qu\u2019il a d\u00e9pos\u00e9es ou exploite r\u00e9guli\u00e8rement. Leur reproduction, usage ou apposition sans l\u2019autorisation \u00e9crite et pr\u00e9alable du Monde, est strictement interdite et constituerait un acte de contrefa\u00e7on engageant la responsabilit\u00e9 civile de son auteur au titre de l\u2019article L. 716-1 du Code de la propri\u00e9t\u00e9 intellectuelle.\n\nL\u2019utilisation ou l\u2019achat d\u2019un Produit et/ou Service par un Utilisateur et/ou Client ne saurait conf\u00e9rer \u00e0 celui-ci comme \u00e0 quiconque, sur les \u00e9l\u00e9ments prot\u00e9g\u00e9s susvis\u00e9s, un droit autre que celui d\u2019un usage strictement personnel, non collectif et non marchand. Pour toute demande d\u2019autorisation relative aux \u00e9l\u00e9ments de propri\u00e9t\u00e9 intellectuelle du Monde, merci de contacter le service commercial du Monde \u00e0 l\u2019adresse \u00e9lectronique suivante : droitsdauteur@lemonde.fr.", 39 | "license_properties": [ 40 | "copyright - all rights reserved" 41 | ], 42 | "license_list": [ 43 | "other: Other license" 44 | ] 45 | }, 46 | "pii": { 47 | "has_pii": "Yes", 48 | "generic_pii_likely": "very likely", 49 | "generic_pii_list": [ 50 | "names", 51 | "dates (birth, death, etc.)" 52 | ], 53 | "numeric_pii_likely": "somewhat likely", 54 | "numeric_pii_list": [ 55 | "telephone numbers" 56 | ], 57 | "sensitive_pii_likely": "very likely", 58 | "sensitive_pii_list": [ 59 | "political opinions", 60 | "racial or ethnic origin", 61 | "health-related data", 62 | "religious or philosophical beliefs" 63 | ], 64 | "no_pii_justification_class": "", 65 | "no_pii_justification_text": "" 66 | }, 67 | "validated": false 68 | }, 69 | "source_category": { 70 | "category_type": "collection", 71 | "category_web": "", 72 | "category_media": "news articles", 73 | "validated": false 74 | }, 75 | "media": { 76 | "category": [ 77 | "text" 78 | ], 79 | "text_format": [ 80 | "plain text", 81 | "HTML", 82 | "PDF" 83 | ], 84 | "audiovisual_format": [], 85 | "image_format": [], 86 | "text_is_transcribed": "No", 87 | "instance_type": "article", 88 | "instance_count": "10K