質問編集履歴
5
sim.pyの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -60,7 +60,8 @@
|
|
60
60
|
def convWords2Synsets(wordList1, wordList2):
|
61
61
|
""" 単語リストを2つ受け取って概念リストのリストを返す """
|
62
62
|
import jwn_corpusreader
|
63
|
+
from nltk.corpus.reader.wordnet import WordNetCorpusReader
|
63
|
-
jwn =
|
64
|
+
jwn = WordNetCorpusReader('C:/LyricsWorkspace/nltk_data/corpora/wordnet', 'C:/LyricsWorkspace/WordNet/wnjpn-ok.tab') #英語WordNetと日本語WordNetを指定する
|
64
65
|
synLists = [[ ],[ ]]
|
65
66
|
wordLists = [wordList1, wordList2]
|
66
67
|
for i in [0,1]:
|
4
エラー文の変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -19,18 +19,24 @@
|
|
19
19
|
TagExamples.txt #入力ファイル1
|
20
20
|
WordExamples.txt #入力ファイル2
|
21
21
|
```
|
22
|
+
|
22
23
|
エラー文
|
23
24
|
```
|
24
25
|
$ python jwn_driver.py
|
25
26
|
Traceback (most recent call last):
|
26
27
|
File "jwn_driver.py", line 9, in <module>
|
27
28
|
synLists = sim.convWords2Synsets(wordLists[0], wordLists[1]) #概念リストを作成
|
28
|
-
File "/Users/
|
29
|
+
File "/Users/user/Desktop/wordnet/sim.py", line 20, in convWords2Synsets
|
29
|
-
jwn =
|
30
|
+
jwn = WordNetCorpusReader('C:/LyricsWorkspace/nltk_data/corpora/wordnet', 'C:/LyricsWorkspace/WordNet/wnjpn-ok.tab') #英語WordNetと日本語WordNetを指定する
|
31
|
+
File "/Users/username/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/nltk/corpus/reader/wordnet.py", line 1080, in __init__
|
32
|
+
encoding=self._ENCODING)
|
33
|
+
File "/Users/username/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/nltk/corpus/reader/api.py", line 84, in __init__
|
34
|
+
root = FileSystemPathPointer(root)
|
35
|
+
File "/Users/username/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/nltk/compat.py", line 221, in _decorator
|
36
|
+
return init_func(*args, **kwargs)
|
30
|
-
File "/Users/username/
|
37
|
+
File "/Users/username/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages/nltk/data.py", line 303, in __init__
|
31
|
-
WordNetCorpusReader.__init__(self, root)
|
32
|
-
|
38
|
+
raise IOError('No such file or directory: %r' % _path)
|
33
|
-
|
39
|
+
OSError: No such file or directory: '/Users/username/Desktop/wordnet/C:/LyricsWorkspace/nltk_data/corpora/wordnet'
|
34
40
|
```
|
35
41
|
|
36
42
|
### 該当のソースコード
|
3
エラー文の追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -19,7 +19,7 @@
|
|
19
19
|
TagExamples.txt #入力ファイル1
|
20
20
|
WordExamples.txt #入力ファイル2
|
21
21
|
```
|
22
|
-
|
22
|
+
エラー文
|
23
23
|
```
|
24
24
|
$ python jwn_driver.py
|
25
25
|
Traceback (most recent call last):
|
2
sim.pyのインデント修正、エラー文の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -23,12 +23,14 @@
|
|
23
23
|
```
|
24
24
|
$ python jwn_driver.py
|
25
25
|
Traceback (most recent call last):
|
26
|
-
File "jwn_driver.py", line
|
26
|
+
File "jwn_driver.py", line 9, in <module>
|
27
|
-
|
27
|
+
synLists = sim.convWords2Synsets(wordLists[0], wordLists[1]) #概念リストを作成
|
28
|
-
File "/Users/username/Desktop/wordnet/sim.py", line 19
|
28
|
+
File "/Users/username/Desktop/wordnet/sim.py", line 19, in convWords2Synsets
|
29
29
|
jwn = jwn_corpusreader.JapaneseWordNetCorpusReader('C:/LyricsWorkspace/nltk_data/corpora/wordnet', 'C:/LyricsWorkspace/WordNet/wnjpn-ok.tab') #英語WordNetと日本語WordNetを指定する
|
30
|
-
|
30
|
+
File "/Users/username/Desktop/wordnet/jwn_corpusreader.py", line 8, in __init__
|
31
|
-
|
31
|
+
WordNetCorpusReader.__init__(self, root)
|
32
|
+
TypeError: __init__() missing 1 required positional argument: 'omw_reader'
|
33
|
+
|
32
34
|
```
|
33
35
|
|
34
36
|
### 該当のソースコード
|
@@ -37,7 +39,7 @@
|
|
37
39
|
# -*- coding: utf-8 -*-
|
38
40
|
#英語WordNetから類似度を算出するモジュール
|
39
41
|
import codecs
|
40
|
-
|
42
|
+
|
41
43
|
def makeWordLists(fin1,fin2):
|
42
44
|
""" ファイル名を2つ受け取って単語リストのリストを返す """
|
43
45
|
fins = [fin1, fin2]
|
@@ -48,20 +50,20 @@
|
|
48
50
|
wordLists[i].append(line.strip("\r\n").strip("\n"))
|
49
51
|
f.close()
|
50
52
|
return wordLists
|
51
|
-
|
53
|
+
|
52
54
|
def convWords2Synsets(wordList1, wordList2):
|
53
55
|
""" 単語リストを2つ受け取って概念リストのリストを返す """
|
54
|
-
import jwn_corpusreader
|
56
|
+
import jwn_corpusreader
|
55
|
-
|
57
|
+
jwn = jwn_corpusreader.JapaneseWordNetCorpusReader('C:/LyricsWorkspace/nltk_data/corpora/wordnet', 'C:/LyricsWorkspace/WordNet/wnjpn-ok.tab') #英語WordNetと日本語WordNetを指定する
|
56
58
|
synLists = [[ ],[ ]]
|
57
59
|
wordLists = [wordList1, wordList2]
|
58
60
|
for i in [0,1]:
|
59
61
|
for j in range(len(wordLists[i])):
|
60
62
|
synLists[i].append(jwn.synsets(wordLists[i][j]))
|
61
63
|
return synLists
|
62
|
-
|
64
|
+
|
63
65
|
def calcSim(synList1,synList2):
|
64
|
-
|
66
|
+
""" 概念リストを2つ受け取って類似度の行列を返す """
|
65
67
|
import numpy as np
|
66
68
|
simMatrix = np.zeros( (len(synList1), len(synList2)))
|
67
69
|
for i in range(len(synList1)):
|
@@ -69,12 +71,12 @@
|
|
69
71
|
sims = [ ]
|
70
72
|
for syn1 in synList1[i]:
|
71
73
|
for syn2 in synList2[j]:
|
72
|
-
|
74
|
+
sims.append(syn1.path_similarity(syn2))
|
73
75
|
simMatrix[i,j] = max(sims)
|
74
76
|
return simMatrix
|
75
|
-
|
77
|
+
|
76
78
|
def writeSim(wordList1, wordList2, simMatrix,fout):
|
77
|
-
|
79
|
+
""" 単語リストを2つと類似度行列とファイル名を受け取ってファイルに出力する """
|
78
80
|
f = codecs.open(fout,'w', encoding="utf-8")
|
79
81
|
for i in range(len(wordList1)):
|
80
82
|
for j in range(len(wordList2)):
|
1
補足情報の追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -131,4 +131,8 @@
|
|
131
131
|
return results
|
132
132
|
else:
|
133
133
|
return None
|
134
|
-
```
|
134
|
+
```
|
135
|
+
|
136
|
+
### 補足情報(FW/ツールのバージョンなど)
|
137
|
+
オペレーティングシステム名(os.name):Mac OS
|
138
|
+
Python Python 3.6.3
|