-
Notifications
You must be signed in to change notification settings - Fork 0
/
code1.py
117 lines (87 loc) · 3.36 KB
/
code1.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
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
109
110
111
112
113
114
115
import csv
'''
with open('DataTrain.csv', 'wb') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=',',
quoting=csv.QUOTE_MINIMAL)
spamwriter.writerow(["ID", "GAREN SPCAE","DOCK","CAPITAL","ROYAL MARKET","GUARDING TOWER","RIVER","RENOVATION","BEDROOM","DINING","BATHROOM","pay","SORCERER","BLESSINGS","TREE","KNIGHT KING"])
'''
DIC = {"ID": "0000", "GARDEN SPACE" : "1","DOCK" : "0.0","Capital" : "0.0","Royal Market":"0.0","Guarding Tower" : "0.0","River" : "0.0","Renovation":"0.0","bedroom":"0","dining rooms":"0","bathroom":"0","pay":"1","sorcerer":"1","blessings":"0","tree":"0","Knights house" : "0.0"}
csvfile = open('DataTrain.csv', 'wb')
spamwriter = csv.writer(csvfile, delimiter=',',
quoting=csv.QUOTE_MINIMAL)
f = open("Bob.txt","r")
data = f.readlines()
def row(Dic):
lst = []
for key in DIC:
if key in Dic:
lst.append(Dic[key])
else :
lst.append(DIC[key])
return lst
def lol1(strng):
if "House ID" in strng:
for word in strng:
if word == "6e*":
return {"ID" : word}
elif "There is no space for garden" in strng:
return {"GARDEN SPACE" : "0"}
elif "Dock" in strng:
for word in strng:
if word == "*.*":
return {"DOCK" : word}
elif "Capital" in strng:
for word in strng:
if word == "*.*":
return {"Capital" : word}
elif "Royal Market" in strng:
for word in strng:
if word == "*.*":
return {"Royal Market" : word}
elif "Guarding Tower" in strng:
for word in strng:
if word == "*.*":
return {"Guarding Tower" : word}
elif "River" in strng:
for word in strng:
if word == "*.*":
return {"River" : word}
elif "did not undergo renovation" in strng:
return {"Renovation" : "0"}
elif "underwent renovation upon Mighty King's command" in strng:
return {"Renovation" : "1"}
elif "bedroom" in strng:
for word in strng:
if isDigit(word):
return {"bedroom":word}
elif "dining rooms" in strng:
for word in strng:
if isdigit(word):
return {"dining rooms":word}
elif "bathrooms" in strng:
for word in strng:
if isdigit(word):
return {"bathrooms":word}
elif "King couldn't pay his visit to the house" in strng:
return {"pay":"0"}
elif "Sorcerer couldn't curse this house" in strng:
return {"sorcerer" :"0"}
elif "blessings" in strng:
for word in strng:
if isdigit(word):
return {"blessings":word}
elif "Holy tree stands tall beside the house" in strng:
return {"tree":"1"}
elif "Distance from Knight's house" in strng:
for word in strng:
if word == "*.*":
return {"Knights house" : word}
dic = {}
for line in data:
if line == "" and dic != {}:
spamwriter.writerow(row(dic))
dic = {}
break
#print line
dic1 = lol1(line)
#dic.update(dic1)