mecab_ner
Table of Contents
- Features
- Installation
- Quick start
- Simple Example
- Practical Example
Features
- Python library to get NER using Mecab
- Infer NER from Data dictionary
Installation
Download using pip via pypi.
$ pip install 'python-mecab-ner' --upgrade
(Mac/homebrew users may need to use pip3
)
Simple Example
from python_mecab_ner.mecab_ner import MecabNer
mecab_ner = MecabNer()
test_sentence = "아이유의 금요일에 만나요를 들으면서 신촌 딸기를 먹을래"
mecab_ner.parse(test_sentence)
mecab_ner.morphs(test_sentence)
mecab_ner.ners(test_sentence)
Practical Example
- Set
data path
for your work File name
will become entity set category large
Data Directory
# Directory
root/
word_dir.py
data/
programming.txt
public.txt
Data File
- Data file must be
txt
format and first line should start your small category First line
will become entity set category small
- data/programming.txt
#인공지능
파이썬
딥러닝
머신 러닝
자연어 처리
버트
#백엔드
로그
http통신
- data/place.txt
#hospital
병원
Results
- on example code 1
('자연어 로그', 'programming', '백엔드')
is infered ner from vocab 로그
in data file. - on example code 2
('서울대병원', 'place', 'hospital')
is infered ner from vocab 병원
in data file. - if you don't want, set
MecabNer(infer=False)
from python_mecab_ner.mecab_ner import MecabNer
mecab_ner = MecabNer(ner_path="./data")
test_sentence = "자연어 처리를 위해 인공지능을 위한 파이썬을 공부하여 자연어와 관련된 일을 하고 있습니다. http 요청시 자연어 로그를 쌓는 것이 중요합니다."
mecab_ner.parse(test_sentence)
mecab_ner.morphs(test_sentence)
mecab_ner.ners(test_sentence)
test_sentence2 = "나는 서울대병원에 갈려고 합니다."
mecab_ner.parse(test_sentence2)
mecab_ner.morphs(test_sentence2)
mecab_ner.ners(test_sentence2)