質問編集履歴
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,5 +14,35 @@
|
|
14
14
|
|
15
15
|
### 試したこと
|
16
16
|
unidicやipadicで試しましたが,同じ結果になりました.
|
17
|
+
```python
|
18
|
+
import re
|
19
|
+
import time
|
20
|
+
import codecs
|
21
|
+
import MeCab
|
17
22
|
|
23
|
+
if __name__ == '__main__':
|
24
|
+
file = codecs.open("/content/dataset_kurashiki_spring_test.txt", 'r', 'utf-8') #ファイルを開いてファイルオブジェクトを取得(codecs.open())
|
25
|
+
documents = [document.strip() for document in file] #strip()で空白文字を削除
|
26
|
+
file.close()
|
18
27
|
|
28
|
+
# number of documents
|
29
|
+
N = len(documents)
|
30
|
+
print(N)
|
31
|
+
|
32
|
+
segList = []
|
33
|
+
for document in documents:
|
34
|
+
mecab = MeCab.Tagger()
|
35
|
+
#print(document)
|
36
|
+
mecab.parse('')
|
37
|
+
|
38
|
+
data = mecab.parse(document)
|
39
|
+
node = mecab.parseToNode(document)
|
40
|
+
#print(node)
|
41
|
+
|
42
|
+
while node:
|
43
|
+
if node.feature.split(",")[0] == u"名詞":
|
44
|
+
segList.append(node.surface)
|
45
|
+
|
46
|
+
node = node.next
|
47
|
+
print(segList)
|
48
|
+
```
|