質問編集履歴

1

書式の改善

2020/09/17 14:09

投稿

oshoring
oshoring

スコア1

test CHANGED
File without changes
test CHANGED
@@ -42,100 +42,268 @@
42
42
 
43
43
  ### 該当のソースコード
44
44
 
45
-
45
+ google_kensaku.py
46
+
47
+ ![![イメージ説明](2157f8c4c5a6887454e983488a340b5c.png)![![イメージ説明](042bee8d5a2c5d76a1f9a2c41dae3604.png)]![イメージ説明](8c727c5de1d4686892e55d52554e6202.png)![イメージ説明](9644e638373524aa2fedae9e4d61ee26.png)![イメージ説明](d1f7b4a9191b386e049004746e1a02b3.png)![イメージ説明](f7957165903c1d37e6e786eb0238eabd.png)![イメージ説明](9fc9196279dbd7c4ce489abe2a3d9b50.png)
46
48
 
47
49
  ```Python
48
50
 
49
- google_kensaku.py
50
-
51
-
52
-
53
- def wadai_suitei(keys,words):
54
-
55
- dt = datetime.date.today()
56
-
57
- #name =
58
-
59
- with open('log/{0}{1}_log.txt'.format(dt,name), 'r',encoding='utf-8') as f:
60
-
61
- if len(keys)>0:
62
-
63
- wadais = keizoku_judge(keys,words)
64
-
65
- if not wadais:
66
-
67
- wadais = [words[0]]
68
-
69
- return wadais
70
-
71
- elif len(keys) == 0:
72
-
73
- for wadai_out in f:
74
-
75
- wadais2 = keizoku_judge2(wadai_out,words)
76
-
77
- if not wadais:
78
-
79
- wadais2 = [words[0]]
80
-
81
- return wadais2
51
+
52
+
53
+ demo.py
54
+
55
+
56
+
57
+ import maeshori
58
+
59
+ import MeCab_mrphs
60
+
61
+ import make_sentence_list
62
+
63
+ import reply
64
+
65
+ import google_kensaku
66
+
67
+ import datetime
68
+
69
+ from zatsuyou import *
70
+
71
+
72
+
73
+ dt_now = datetime.datetime.now()
74
+
75
+ dt = datetime.date.today()
76
+
77
+ print('S:名前を入力してください')
78
+
79
+ name = input('U:')
80
+
81
+ print('S:こんにちは')
82
+
83
+ print('S:何かお話ししましょうか')
84
+
85
+ path = 'log/{0}{1}_log.txt'.format(dt,name)
86
+
87
+ with open(path, mode='a') as f:
88
+
89
+ f.write("\n{0}{1} log start\n".format(dt_now,name))
90
+
91
+ f.write("S:名前を入力してください\n")
92
+
93
+ f.write("U:{}\n".format(name))
94
+
95
+ f.write("S:こんにちは\n")
96
+
97
+ f.write("S:何かお話ししましょうか\n\n\n")
98
+
99
+
100
+
101
+ wadai_num=0
102
+
103
+ p_wadai=[]
104
+
105
+ hatsuwa_wadai=[]
106
+
107
+ last_out=""
108
+
109
+ while 1:
110
+
111
+
112
+
113
+ wadai=[]
114
+
115
+ kanren_out=""
116
+
117
+ wadai_out=""
118
+
119
+ kanren_out_original=""
120
+
121
+ handan_kijun=""
122
+
123
+ keitaiso = []
124
+
125
+ u = input("U:")
126
+
127
+ if u == '':
128
+
129
+ continue
130
+
131
+
132
+
133
+ with open(path, mode='a') as f:
134
+
135
+ f.write("U:{} ".format(u))
136
+
137
+
138
+
139
+ u = maeshori.re_replace(u)
140
+
141
+
142
+
143
+ keitaiso = MeCab_mrphs.input2mrphs(u)
144
+
145
+
146
+
147
+ words,kd_flag=make_sentence_list.make_words_list(keitaiso,hatsuwa_wadai)
148
+
149
+
150
+
151
+ if words:
152
+
153
+ hatsuwa_wadai,kanrenbun=google_kensaku.in2kanrenbun(hatsuwa_wadai,words,u)
154
+
155
+
156
+
157
+ w_f=0
158
+
159
+ if len(p_wadai)==len(hatsuwa_wadai):
160
+
161
+ wadai_num=0
162
+
163
+ for i,w in enumerate(p_wadai):
164
+
165
+ if p_wadai[i]==hatsuwa_wadai[i]:
166
+
167
+ wadai_num=wadai_num+1
168
+
169
+ if wadai_num==len(p_wadai):
170
+
171
+ w_f=1
172
+
173
+
174
+
175
+ if len(hatsuwa_wadai)==2:
176
+
177
+ wadai_out="話題は「{}」と「{}」".format(hatsuwa_wadai[0],hatsuwa_wadai[1])
178
+
179
+ elif len(hatsuwa_wadai)==1:
180
+
181
+ wadai_out="話題は「{}」".format(hatsuwa_wadai[0])
182
+
183
+ print("({})".format(wadai_out))
184
+
185
+
186
+
187
+
188
+
189
+ if kanrenbun[1] and kanrenbun[0]==last_out:
190
+
191
+ kanren_out=kanrenbun[1]
192
+
193
+ last_out=kanrenbun[1]
194
+
195
+ #print(kanrenbun[3])
196
+
197
+ handan_kijun=kanrenbun[3]
198
+
199
+ kanren_out_original=kanrenbun[1]
82
200
 
83
201
  else:
84
202
 
203
+ kanren_out=kanrenbun[0]
204
+
205
+ last_out=kanrenbun[0]
206
+
207
+ #print(kanrenbun[2])
208
+
209
+ handan_kijun=kanrenbun[2]
210
+
211
+ kanren_out_original=kanrenbun[0]
212
+
213
+ if kd_flag==1:
214
+
215
+ #kanren_out="そうなのですか。" + kanren_out
216
+
217
+ a=0
218
+
219
+
220
+
221
+ kanren_out=reply.make_kanrenbun(kanren_out)
222
+
223
+
224
+
225
+ if len(hatsuwa_wadai)==1 and w_f==0:
226
+
227
+ #kanren_out = kanren_out + "\nS:" + hatsuwa_wadai[0] + "はどうでしたか?"
228
+
229
+ a=0
230
+
231
+ elif len(hatsuwa_wadai)==1 and w_f==1:
232
+
233
+ kanren_out = hatsuwa_wadai[0] + "が好きなのですか?"
234
+
235
+ elif len(hatsuwa_wadai)==2 and w_f==1:
236
+
237
+ kanren_out = "そうなのですか。\nS: 何か、違う話もしませんか?"
238
+
239
+ if kd_flag==2:
240
+
85
- print("***w_flag error***")
241
+ kanren_out="何かあったのですか? NO NOUN ERROR"
242
+
86
-
243
+ else:
244
+
245
+ kanren_out="何かあったのですか? NO NOUN ERROR"
246
+
247
+
248
+
249
+ p_wadai=hatsuwa_wadai
250
+
251
+
252
+
253
+ temp_rep = reply.make_temp_rep(u)
254
+
255
+
256
+
257
+ if temp_rep !="":
258
+
259
+ rep='S:{}'.format(temp_rep)
260
+
261
+ else:
262
+
263
+ rep="S:"+kanren_out
264
+
265
+
266
+
267
+
268
+
269
+ print(rep)
270
+
271
+
272
+
273
+ with open(path, mode='a') as f:
274
+
87
- print("フラグがなんかバグってます")
275
+ f.write("\n")
276
+
88
-
277
+ if temp_rep =="":
278
+
279
+ f.write("----------------------------------------------\n")
280
+
89
- print("******************")
281
+ f.write("入力文は「{}」\n".format(u))
90
-
282
+
91
- wadai = [words[0]]
283
+ f.write("推定された{}\n".format(wadai_out))
284
+
92
-
285
+ f.write("関連文は「{}」\n".format(kanren_out_original))
286
+
93
- return wadai
287
+ if len(handan_kijun)==3:
288
+
289
+ f.write("意味の近い単語は「{}」と「{}」({})\n".format(handan_kijun[0],handan_kijun[1],handan_kijun[2]))
290
+
291
+ f.write("出力文は「{}」\n".format(kanren_out))
292
+
293
+ f.write("----------------------------------------------\n")
294
+
295
+ f.write("{}\n\n\n".format(rep))
296
+
297
+
298
+
299
+ if u == 'さようなら' or u == 'またね':
300
+
301
+ break
302
+
303
+
94
304
 
95
305
  ```
96
306
 
97
- ```Python
98
-
99
-
100
-
101
- demo.py
102
-
103
-
104
-
105
- import google_kensaku
106
-
107
- import datetime
108
-
109
-
110
-
111
- dt_now = datetime.datetime.now()
112
-
113
- dt = datetime.date.today()
114
-
115
- print('S:名前を入力してください')
116
-
117
- name = input('U:')
118
-
119
- print('S:こんにちは')
120
-
121
- print('S:何かお話ししましょうか')
122
-
123
- path = 'log/{0}{1}_log.txt'.format(dt,name)
124
-
125
- with open(path, mode='a') as f:
126
-
127
- f.write("\n{0}{1} log start\n".format(dt_now,name))
128
-
129
- f.write("S:名前を入力してください\n")
130
-
131
- f.write("U:{}\n".format(name))
132
-
133
- f.write("S:こんにちは\n")
134
-
135
- f.write("S:何かお話ししましょうか\n\n\n")
136
-
137
- ```
138
-
139
307
 
140
308
 
141
309
  ### 試したこと