-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpers.py
102 lines (82 loc) · 3.01 KB
/
pers.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
#!/usr/bin/python
import re
import csv
likes={}
dislikes={}
user={}
line = ""
for key, val in csv.reader(open("likes.csv")):
likes[key] = val
for key, val in csv.reader(open("dislikes.csv")):
dislikes[key] = val
for key, val in csv.reader(open("user.csv")):
user[key] = val
while True:
line = input()
if (line=="stop"):
break
searchObj = re.search( r'(.*) is my (best|favourite) (.*)', line, re.M|re.I)
if searchObj:
print ("searchObj.group() : ", searchObj.group())
print ("searchObj.group(1) : ", searchObj.group(1))
print ("searchObj.group(2) : ", searchObj.group(2))
print ("searchObj.group(3) : ", searchObj.group(3))
likes[searchObj.group(3)]=searchObj.group(1)
continue
searchObj= re.search( r'my (best|favourite) (.*) is (.*)', line, re.M|re.I)
if searchObj:
print ("searchObj.group() : ", searchObj.group())
print ("searchObj.group(1) : ", searchObj.group(1))
print ("searchObj.group(2) : ", searchObj.group(2))
print ("searchObj.group(3) : ", searchObj.group(3))
likes[searchObj.group(2)]=searchObj.group(3)
continue
searchObj= re.search( r'i (like|love) (.*) (.*)', line, re.M|re.I)
if searchObj:
print ("searchObj.group() : ", searchObj.group())
print ("searchObj.group(1) : ", searchObj.group(1))
print ("searchObj.group(2) : ", searchObj.group(2))
print ("searchObj.group(3) : ", searchObj.group(3))
likes[searchObj.group(3)]=searchObj.group(2)
continue
searchObj = re.search( r'i (hate|donot like| don\'t like|dont like) (.*) (.*)', line, re.M|re.I)
if searchObj:
print ("searchObj.group() : ", searchObj.group())
print ("searchObj.group(1) : ", searchObj.group(1))
print ("searchObj.group(2) : ", searchObj.group(2))
print ("searchObj.group(3) : ", searchObj.group(3))
dislikes[searchObj.group(3)]=searchObj.group(2)
continue
searchObj = re.search( r'my (name) is (.*)', line, re.M|re.I)
if searchObj:
print ("searchObj.group() : ", searchObj.group())
print ("searchObj.group(1) : ", searchObj.group(1))
print ("searchObj.group(2) : ", searchObj.group(2))
user[searchObj.group(1)]=searchObj.group(2)
continue
searchObj = re.search( r'my (.*)\'s name is (.*)', line, re.M|re.I)
if searchObj:
print ("searchObj.group() : ", searchObj.group())
print ("searchObj.group(1) : ", searchObj.group(1))
print ("searchObj.group(2) : ", searchObj.group(2))
user[searchObj.group(1)]=searchObj.group(2)
continue
searchObj = re.search( r'my (.*) is (.*)', line, re.M|re.I)
if searchObj:
print ("searchObj.group() : ", searchObj.group())
print ("searchObj.group(1) : ", searchObj.group(1))
print ("searchObj.group(2) : ", searchObj.group(2))
user[searchObj.group(1)]=searchObj.group(2)
continue
w = csv.writer(open("likes.csv", "w"))
for key, val in likes.items():
w.writerow([key, val])
w = csv.writer(open("dislikes.csv", "w"))
for key, val in dislikes.items():
w.writerow([key, val])
w = csv.writer(open("user.csv", "w"))
for key, val in user.items():
w.writerow([key, val])
print (likes)
print (dislikes)
print (user)