File size: 4,053 Bytes
cf8583d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ed83b3
cf8583d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e37e279
 
 
 
 
 
 
 
 
 
 
 
cf8583d
 
e37e279
 
cf8583d
 
 
 
 
 
 
8d40bb9
cf8583d
 
 
 
 
 
 
 
 
 
e37e279
cf8583d
 
 
ed60683
cf8583d
fa3f923
cad4cab
cf8583d
 
a14cef8
cf8583d
 
ed60683
cf8583d
 
708dd64
cf8583d
 
 
8d40bb9
cf8583d
 
 
 
 
 
 
 
 
3624e47
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# 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]:
        # Use the raw GitHub link to download the CSV file
        downloaded_file_path = dl_manager.download_and_extract(
        "https://raw.githubusercontent.com/zening-wang2023/NC-Crime-Dataset/main/Cary_new.csv")

        # Return a list of split generators
        return [
            datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_file_path})
        ]


    def _generate_examples(self, filepath):
        # Read the CSV file
        df = pd.read_csv(filepath)  ## just for test
        # 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"],
        }