質問編集履歴

2

ご回答いただいたコードを完成させ実行した結果の追記

2018/09/01 01:40

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -118,6 +118,96 @@
118
118
 
119
119
 
120
120
 
121
+ ###ご回答いただいたコードを完成させ実行した結果
122
+
123
+ ご回答いただいたコード
124
+
125
+ ```python
126
+
127
+ import sys
128
+
129
+ import MeCab
130
+
131
+ import mojimoji
132
+
133
+
134
+
135
+ STOP_POS = {
136
+
137
+ ('名詞', '副詞可能', '*'),
138
+
139
+ ('名詞', '非自立', '副詞可能'),
140
+
141
+ ('名詞', '非自立', '一般'),
142
+
143
+ ('名詞', '接尾', '副詞可能'),
144
+
145
+ ('名詞', '接尾', '助数詞'),
146
+
147
+ ('名詞', '数', '*'),
148
+
149
+ }
150
+
151
+
152
+
153
+ def han2zen(text):
154
+
155
+ text = mojimoji.han_to_zen(text)
156
+
157
+ return text
158
+
159
+
160
+
161
+ def extractKeyword(text):
162
+
163
+ tagger = MeCab.Tagger('-Ochasen')
164
+
165
+ tagger.parse('')
166
+
167
+ node = tagger.parseToNode(han2zen(text))
168
+
169
+ keywords = []
170
+
171
+ while node:
172
+
173
+ features = tuple(node.feature.split(","))
174
+
175
+ if features[0] == u"名詞" and features[:3] not in STOP_POS:
176
+
177
+ keywords.append(node.surface)
178
+
179
+ elif features[0] == u"形容詞" and features[1] == u"自立":
180
+
181
+ keywords.append(node.surface)
182
+
183
+ elif features[0] == u"動詞" and features[1] == u"自立":
184
+
185
+ keywords.append(node.surface)
186
+
187
+ node = node.next
188
+
189
+ return keywords
190
+
191
+
192
+
193
+ text = "ドライ・アムネシア・バラ(切り花)"
194
+
195
+ extractKeyword(text)
196
+
197
+ ```
198
+
199
+
200
+
201
+ 結果
202
+
203
+ ```
204
+
205
+ ['ドライ・アムネシア・バラ', '切り花']
206
+
207
+ ````
208
+
209
+
210
+
121
211
  ### 補足情報(FW/ツールのバージョンなど)
122
212
 
123
213
  Python3.6

1

誤字脱字

2018/09/01 01:40

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -17,8 +17,6 @@
17
17
  text = "ドライ・アムネシア・バラ(切花)"
18
18
 
19
19
  ['ドライ', 'アムネシア', 'バラ', '切花']
20
-
21
- ```
22
20
 
23
21
  ```
24
22