質問編集履歴
1
ご回答を受けて試したことと問題の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -166,6 +166,96 @@
|
|
166
166
|
|
167
167
|
|
168
168
|
|
169
|
+
### ご回答を受けて試したことと問題
|
170
|
+
|
171
|
+
wordsを質問の配列ではなく、大規模データ6000単語などにすると読み込まれて
|
172
|
+
|
173
|
+
words_to_synonymとしては正しく一覧が表示されるのですが、直積で数値を出す時に
|
174
|
+
|
175
|
+
```
|
176
|
+
|
177
|
+
if deg_similarity > 0:
|
178
|
+
|
179
|
+
```
|
180
|
+
|
181
|
+
の部分でエラーが出てしまうという問題に直面しています。
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
```python
|
188
|
+
|
189
|
+
#wordsは大規模データ6000単語の配列
|
190
|
+
|
191
|
+
import itertools
|
192
|
+
|
193
|
+
words_to_synonym = {}
|
194
|
+
|
195
|
+
for word in words:
|
196
|
+
|
197
|
+
synonyms = wn.synsets(word, lang='eng')
|
198
|
+
|
199
|
+
if synonyms:
|
200
|
+
|
201
|
+
words_to_synonym[word] = synonyms[0]
|
202
|
+
|
203
|
+
print(words_to_synonym)
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
words_matrix = {word: {} for word in words_to_synonym}
|
208
|
+
|
209
|
+
it = itertools.product(words_to_synonym.items(), repeat=2)
|
210
|
+
|
211
|
+
for (word_x, synonym_x), (word_y, synonym_y) in it:
|
212
|
+
|
213
|
+
if word_x is word_y:
|
214
|
+
|
215
|
+
continue
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
deg_similarity = synonym_x.path_similarity(synonym_y)
|
220
|
+
|
221
|
+
if deg_similarity > 0:
|
222
|
+
|
223
|
+
words_matrix[word_x][word_y] = deg_similarity
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
print(words_matrix)
|
228
|
+
|
229
|
+
```
|
230
|
+
|
231
|
+
エラー文
|
232
|
+
|
233
|
+
```
|
234
|
+
|
235
|
+
TypeError Traceback (most recent call last)
|
236
|
+
|
237
|
+
<ipython-input-43-182db5f47e02> in <module>()
|
238
|
+
|
239
|
+
8
|
240
|
+
|
241
|
+
9 deg_similarity = synonym_x.path_similarity(synonym_y)
|
242
|
+
|
243
|
+
---> 10 if deg_similarity > 0:
|
244
|
+
|
245
|
+
11 words_matrix[word_x][word_y] = deg_similarity
|
246
|
+
|
247
|
+
12
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
TypeError: '>' not supported between instances of 'NoneType' and 'int'
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
```
|
256
|
+
|
257
|
+
|
258
|
+
|
169
259
|
|
170
260
|
|
171
261
|
### 補足情報(FW/ツールのバージョンなど)
|