Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mecab: Using found mecab-ko-dic path #336

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion konlpy/tag/_mecab.py
Original file line number Diff line number Diff line change
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