Datasets:
1T Conte
commited on
Commit
•
1af5c58
1
Parent(s):
623d399
fix: metadata
Browse files- README.md +1 -0
- convert.py +6 -3
README.md
CHANGED
@@ -18,6 +18,7 @@ dataset_info:
|
|
18 |
dtype:
|
19 |
class_label:
|
20 |
names:
|
|
|
21 |
'1': 1 star
|
22 |
'2': 2 stars
|
23 |
'3': 3 stars
|
|
|
18 |
dtype:
|
19 |
class_label:
|
20 |
names:
|
21 |
+
'0': null
|
22 |
'1': 1 star
|
23 |
'2': 2 stars
|
24 |
'3': 3 stars
|
convert.py
CHANGED
@@ -104,14 +104,14 @@ def parse_file(filename):
|
|
104 |
colon_pos = line.find(":")
|
105 |
if colon_pos == -1:
|
106 |
entry["product/category"] = CATEGORIES[filename]
|
107 |
-
yield entry
|
108 |
entry = {}
|
109 |
continue
|
110 |
e_name = line[:colon_pos]
|
111 |
rest = line[colon_pos + 2 :]
|
112 |
entry[e_name] = rest
|
113 |
|
114 |
-
yield entry
|
115 |
|
116 |
|
117 |
def clean(entry):
|
@@ -119,12 +119,15 @@ def clean(entry):
|
|
119 |
Clean the entry
|
120 |
"""
|
121 |
|
|
|
|
|
|
|
122 |
if entry["product/price"] == "unknown":
|
123 |
entry["product/price"] = None
|
124 |
else:
|
125 |
entry["product/price"] = float(entry["product/price"])
|
126 |
|
127 |
-
entry["review/score"] = int(entry["review/score"])
|
128 |
entry["review/time"] = int(entry["review/time"])
|
129 |
entry["product/category"] = CATEGORIES_LIST.index(entry["product/category"])
|
130 |
|
|
|
104 |
colon_pos = line.find(":")
|
105 |
if colon_pos == -1:
|
106 |
entry["product/category"] = CATEGORIES[filename]
|
107 |
+
yield clean(entry)
|
108 |
entry = {}
|
109 |
continue
|
110 |
e_name = line[:colon_pos]
|
111 |
rest = line[colon_pos + 2 :]
|
112 |
entry[e_name] = rest
|
113 |
|
114 |
+
yield clean(entry)
|
115 |
|
116 |
|
117 |
def clean(entry):
|
|
|
119 |
Clean the entry
|
120 |
"""
|
121 |
|
122 |
+
if not entry:
|
123 |
+
return entry
|
124 |
+
|
125 |
if entry["product/price"] == "unknown":
|
126 |
entry["product/price"] = None
|
127 |
else:
|
128 |
entry["product/price"] = float(entry["product/price"])
|
129 |
|
130 |
+
entry["review/score"] = int(float(entry["review/score"]))
|
131 |
entry["review/time"] = int(entry["review/time"])
|
132 |
entry["product/category"] = CATEGORIES_LIST.index(entry["product/category"])
|
133 |
|