-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv_loader.py
69 lines (63 loc) · 1.46 KB
/
csv_loader.py
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
import csv
categories = {
'Transportation': {
'value': 0,
'subcategory': {
'Means of transport': 0,
'Transportation Infrastructure': 1,
'Transportation Services': 2,
}
},
'Accommodation': {
'value': 1,
'subcategory': {
'First class accommodation': 3,
'Second class accommodation': 4,
}
},
'Attraction': {
'value': 2,
'subcategory': {
'Culture & Tradition': 5,
'Scenic': 6,
'Exhibition entertainment': 7,
'Live entertainment': 8,
'Shopping': 9,
'Adventure tours and activities': 10,
}
},
'Service and Ancillary': {
'value': 3,
'subcategory': {
'Information & Guiding': 11,
'Catering Service': 12,
'Facility': 13,
}
},
'Tourism broker': {
'value': 4,
'subcategory': {
'Tourism agent & operator': 14,
}
}
}
tweets = []
with open('tweets-category.csv', encoding="iso-8859-1") as tweet_file:
reader = csv.DictReader(tweet_file)
for row in reader:
tweet = {
'text': row['Tweet'],
'subcategory': categories[row['Category']]['subcategory'][row['Subcategory']],
'category': categories[row['Category']]['value']
}
tweets.append(tweet)
test_tweets = []
with open('test-tweets-category.csv', encoding="iso-8859-1") as test_tweet_file:
reader = csv.DictReader(test_tweet_file)
for row in reader:
tweet = {
'text': row['Tweet'],
'subcategory': categories[row['Category']]['subcategory'][row['Subcategory']],
'category': categories[row['Category']]['value']
}
test_tweets.append(tweet)