前提
MeCabでのカタカナを連続して取得したい.
実現したいこと
- MeCabを用いて,カタカナを途中で分割することなく,連続して取得したい.
発生している問題
例えば,ライトアップでは「ライト」「アップ」と解析されてしまう.
これを「ライトアップ」として取得したいのですが,辞書を改良するしかないのでしょうか.
試したこと
unidicやipadicで試しましたが,同じ結果になりました.
python
1import re 2import time 3import codecs 4import MeCab 5 6if __name__ == '__main__': 7 file = codecs.open("/content/dataset_kurashiki_spring_test.txt", 'r', 'utf-8') #ファイルを開いてファイルオブジェクトを取得(codecs.open()) 8 documents = [document.strip() for document in file] #strip()で空白文字を削除 9 file.close() 10 11 # number of documents 12 N = len(documents) 13 print(N) 14 15 segList = [] 16 for document in documents: 17 mecab = MeCab.Tagger() 18 #print(document) 19 mecab.parse('') 20 21 data = mecab.parse(document) 22 node = mecab.parseToNode(document) 23 #print(node) 24 25 while node: 26 if node.feature.split(",")[0] == u"名詞": 27 segList.append(node.surface) 28 29 node = node.next 30 print(segList)
回答2件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2022/12/06 12:52