Johnnyeee commited on
Commit
3495eca
1 Parent(s): fd3f8bb

Update Yelpdata_663.py

Browse files
Files changed (1) hide show
  1. Yelpdata_663.py +5 -66
Yelpdata_663.py CHANGED
@@ -1,64 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
- """yelp_dataset.ipynb
3
-
4
- Automatically generated by Colaboratory.
5
-
6
- Original file is located at
7
- https://colab.research.google.com/drive/14UtK4YCjMSx4cVbUb9NBRHviWZg07dtY
8
- """
9
-
10
- # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
11
- #
12
- # Licensed under the Apache License, Version 2.0 (the "License");
13
- # you may not use this file except in compliance with the License.
14
- # You may obtain a copy of the License at
15
- #
16
- # http://www.apache.org/licenses/LICENSE-2.0
17
- #
18
- # Unless required by applicable law or agreed to in writing, software
19
- # distributed under the License is distributed on an "AS IS" BASIS,
20
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
- # See the License for the specific language governing permissions and
22
- # limitations under the License.
23
- # TODO: Address all TODOs and remove all explanatory comments
24
- """TODO: Add a description here."""
25
-
26
-
27
- import csv
28
- import json
29
- import os
30
- from typing import List
31
- import datasets
32
- import logging
33
- import pandas as pd
34
-
35
- # TODO: Add BibTeX citation
36
- # Find for instance the citation on arxiv or on the dataset repo/website
37
- _CITATION = """\
38
- @InProceedings{huggingface:dataset,
39
- title = {A great new dataset},
40
- author={huggingface, Inc.
41
- },
42
- year={2020}
43
- }
44
- """
45
-
46
- # TODO: Add description of the dataset here
47
- # You can copy an official description
48
- _DESCRIPTION = """\
49
- This dataset encompasses a wealth of information from the Yelp platform,
50
- detailing user reviews, business ratings, and operational specifics across a diverse array of local establishments.
51
- """
52
-
53
- # TODO: Add a link to an official homepage for the dataset here
54
- _HOMEPAGE = "https://www.yelp.com/dataset/download"
55
-
56
- # TODO: Add the licence for the dataset here if you can find it
57
- _LICENSE = "https://s3-media0.fl.yelpcdn.com/assets/srv0/engineering_pages/f64cb2d3efcc/assets/vendor/Dataset_User_Agreement.pdf"
58
-
59
- # TODO: Add link to the official dataset URLs here
60
- # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
61
- # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
62
  import json
63
  import datasets
64
 
@@ -113,7 +52,11 @@ class YelpDataset(datasets.GeneratorBasedBuilder):
113
 
114
  # Load businesses and filter for restaurants
115
  with open(business_path, encoding="utf-8") as f:
116
- businesses = {line['business_id']: line for line in (json.loads(line) for line in f) if "Restaurants" in line.get("categories", "")}
 
 
 
 
117
 
118
  # Generate examples
119
  with open(review_path, encoding="utf-8") as f:
@@ -131,7 +74,3 @@ class YelpDataset(datasets.GeneratorBasedBuilder):
131
  "text": review['text'],
132
  "date": review['date'],
133
  }
134
-
135
-
136
-
137
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import json
2
  import datasets
3
 
 
52
 
53
  # Load businesses and filter for restaurants
54
  with open(business_path, encoding="utf-8") as f:
55
+ businesses = {}
56
+ for line in f:
57
+ business = json.loads(line)
58
+ if business.get("categories") and "Restaurants" in business["categories"]:
59
+ businesses[business['business_id']] = business
60
 
61
  # Generate examples
62
  with open(review_path, encoding="utf-8") as f:
 
74
  "text": review['text'],
75
  "date": review['date'],
76
  }