Skip to content

Commit

Permalink
Merge c828d30 into 5f7c93f
Browse files Browse the repository at this point in the history
  • Loading branch information
woowahan-jaehoon committed Dec 7, 2020
2 parents 5f7c93f + c828d30 commit d123dca
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion konlpy/tag/_mecab.py
Expand Up @@ -2,6 +2,8 @@
from __future__ import absolute_import

import sys
import os
import subprocess

try:
from MeCab import Tagger
Expand Down Expand Up @@ -68,7 +70,19 @@ class Mecab():
.. _Eunjeon Project: http://eunjeon.blogspot.kr/
"""

def __init__(self, dicpath='/usr/local/lib/mecab/dic/mecab-ko-dic'):
def get_default_dicpath():
default_dicpath = '/usr/local/lib/mecab/dic/mecab-ko-dic'

mecab_config_path = os.path.join(sys.prefix, 'bin', 'mecab-config')
if os.path.isfile(mecab_config_path):
mecab_ko_dic_path = subprocess.check_output([
mecab_config_path, '--dicdir']).decode('utf-8').strip() + '/mecab-ko-dic'
if os.path.isdir(mecab_ko_dic_path):
default_dicpath = mecab_ko_dic_path

return default_dicpath

def __init__(self, dicpath=get_default_dicpath()):
self.dicpath = dicpath
try:
self.tagger = Tagger('-d %s' % dicpath)
Expand Down

0 comments on commit d123dca

Please sign in to comment.