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

Fix mecab parse problem #360

Merged
merged 1 commit into from
Oct 3, 2021
Merged

Fix mecab parse problem #360

merged 1 commit into from
Oct 3, 2021

Conversation

swyo
Copy link

@swyo swyo commented Jun 25, 2021

If input string has a strange word, mecab does not tokenize it.

This is because konlpy.tag._mecab.parse triggers Error as follows.

In [1]: from konlpy.tag import Mecab

In [2]: mc = Mecab()

In [3]: mc.morphs('_\u2028')

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-928619c63e3f> in <module>
----> 1 mc.morphs('_\u2028')

/usr/local/lib/python3.6/dist-packages/konlpy/tag/_mecab.py in morphs(self, phrase)
     84         """Parse phrase to morphemes."""
     85
---> 86         return [s for s, t in self.pos(phrase)]
     87
     88     def nouns(self, phrase):

/usr/local/lib/python3.6/dist-packages/konlpy/tag/_mecab.py in pos(self, phrase, flatten)
     76             if flatten:
     77                 result = self.tagger.parse(phrase)
---> 78                 return parse(result)
     79             else:
     80                 return [parse(self.tagger.parse(eojeol).decode('utf-8'))

/usr/local/lib/python3.6/dist-packages/konlpy/tag/_mecab.py in pos(self, phrase, flatten)
     76             if flatten:
     77                 result = self.tagger.parse(phrase)
---> 78                 return parse(result)
     79             else:
     80                 return [parse(self.tagger.parse(eojeol).decode('utf-8'))\

/usr/local/lib/python3.6/dist-packages/konlpy/tag/_mecab.py in parse(result, allattrs)
     30         return (s, t.split(',', 1)[0])
     31
---> 32     return [split(elem) for elem in result.splitlines()[:-1]]
     33
     34 class Mecab():

/usr/local/lib/python3.6/dist-packages/konlpy/tag/_mecab.py in <listcomp>(.0)
     30         return (s, t.split(',', 1)[0])
     31
---> 32     return [split(elem) for elem in result.splitlines()[:-1]]
     33
     34 class Mecab():

/usr/local/lib/python3.6/dist-packages/konlpy/tag/_mecab.py in split(elem)
     27     def split(elem):
     28         if not elem: return ('','SY')
---> 29         s, t = elem.split('\t')
     30         return (s, t.split(',', 1)[0])
     31

ValueError: not enough values to unpack (expected 2, got 1)

To fix this issue, I suggest this PR.

@minhoryang
Copy link
Member

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants