-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
164 lines (156 loc) · 3.26 KB
/
app.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
from flask import Flask, render_template,url_for,request, redirect
import re,json
app = Flask(__name__)
app.config.from_object('config');
@app.route('/')
def index():
w_dict ={
'terserah' ,
'aku ga apa-apa',
'gue jelek banget',
'ga usah ga perlu',
'lo berubah banget',
'cie selamat ya',
'oke, aku yang salah',
'aku belum mau pacaran'
}
return render_template('depan.html', kode = w_dict)
@app.route('/say', methods=['GET', 'POST'])
def say():
diction = [{
"kode": "terserah",
"subject": [{
"kata": "pengertian"
}, {
"kata": "makan"
}, {
"kata": "tempat"
}, {
"kata": "peka"
}],
"predikat": [{
"kata": "kok kamu ga pengertian"
}, {
"kata": "aku ga mau makan disini"
}, {
"kata": "gue ga suka tempat ini"
}, {
"kata": "ga peka"
}]
},
{
"kode": "aku ga apa-apa",
"subject": [{
"kata": "sakit"
}, {
"kata": "jahat"
}, {
"kata": "hibur"
}, {
"kata": "minta"
}],
"predikat": [{
"kata": "sakit banget rasanya"
}, {
"kata": "jahat banget"
}, {
"kata": "hibur aku dong"
}, {
"kata": "minta maaf kek"
}]
},
{
"kode": "gue jelek banget",
"subject": [{
"kata": "cantik"
}],
"predikat": [{
"kata": "bilang dong gue cantik"
}]
},
{
"kode": "ga usah ga perlu",
"subject": [{
"kata": "bantu"
}, {
"kata": "cuek"
}, {
"kata": "perlu"
}, {
"kata": "peduli"
}],
"predikat": [{
"kata": "bantuin kek"
}, {
"kata": "cuek banget"
}, {
"kata": "iya perlu lah"
}, {
"kata": "kamu gak peduli sama aku"
}]
},
{
"kode": "berubah banget",
"subject": [{
"kata": "kangen"
}],
"predikat": [{
"kata": "kangen lo yang dulu"
}]
},
{
"kode": "selamat ya",
"subject": [{
"kata": "enak banget"
}],
"predikat": [{
"kata": "enak banget lo, coba gue aja"
}]
},
{
"kode": "aku yang salah",
"subject": [{
"kata": "egois"
}, {
"kata": "salah"
}],
"predikat": [{
"kata": "dasar egois"
}, {
"kata": "ini semua salahmu"
}]
},
{
"kode": "belum mau pacaran",
"subject": [{
"kata": "pengen punya pacar"
}],
"predikat": [{
"kata": "aku pengen punya pacar, tapi bukan (yang kayak) kamu"
}]
}]
rule =''
if request.method == 'POST':
g_code = request.form['g_code']
g_say = request.form['g_say']
count = 0
n_count = 0
for w_dict in diction:
if w_dict['kode'] == g_code:
for k_dict in w_dict['subject']:
rule = r''+k_dict['kata']
found = re.search(rule,g_say)
if found:
count += 1
else:
n_count += 1
else:
pass
else:
pass
# return redirect(url_for(''))
print count
print n_count
return render_template('say.html')
if __name__ == '__main__':
app.run(debug = True)