# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # TODO: Address all TODOs and remove all explanatory comments """TODO: Add a description here.""" import csv import json import os from typing import List import datasets import logging import pandas as pd # TODO: Add BibTeX citation # Find for instance the citation on arxiv or on the dataset repo/website _CITATION = """\ @InProceedings{huggingface:dataset, title = {NC Crime Dataset}, author={huggingface, Inc. }, year={2024} } """ # TODO: Add description of the dataset here # You can copy an official description _DESCRIPTION = """\ The dataset, compiled from public police incident reports across various cities in North Carolina, covers a period from the early 2000s through to 2024. It is intended to facilitate the study of crime trends and patterns. """ # TODO: Add a link to an official homepage for the dataset here _HOMEPAGE = "" # TODO: Add the licence for the dataset here if you can find it _LICENSE = "" # TODO: Add link to the official dataset URLs here # The HuggingFace Datasets library doesn't host the datasets but only points to the original files. # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method) _URL = "" _URLS = "" class NCCrimeDataset(datasets.GeneratorBasedBuilder): """Dataset for North Carolina Crime Incidents.""" _URLS = _URLS VERSION = datasets.Version("1.0.0") def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "year": datasets.Value("int64"), "city": datasets.Value("string"), "crime_major_category": datasets.Value("string"), "crime_detail": datasets.Value("string"), "latitude": datasets.Value("float64"), "longitude": datasets.Value("float64"), "occurance_time": datasets.Value("string"), "clear_status": datasets.Value("string"), "incident_address": datasets.Value("string"), "notes": datasets.Value("string"), }), citation=_CITATION, ) def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]: # Download and extract the data file downloaded_file_path = dl_manager.download_and_extract( "https://drive.google.com/file/d/1Se-B8Y-SdU0caZzGJyX_0YW44TZwaq3l/view?usp=sharing") # Return a list of split generators return [ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_file_path}), datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_file_path}), datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_file_path}), ] def _generate_examples(self, filepath): # Read the CSV file df = pd.read_csv(filepath) # Iterate over the rows and yield examples for i, row in df.iterrows(): yield i, { "year": int(row["year"]), "city": row["city"], "crime_major_category": row["crime_major_category"], "crime_detail": row["crime_detail"], "latitude": float(row["latitude"]), "longitude": float(row["longitude"]), "occurance_time": row["occurance_time"], "clear_status": row["clear_status"], "incident_address": row["incident_address"], "notes": row["notes"], }