0

I'm trying to tag POS but results returns me an error I don't even know what to do about :/ can anyone help me find out where went wrong..?

tagging pos

api = KhaiiiApi()
significant_tags = ['NNG', 'NNP', 'NNB', 'VV', 'VA', 'VX', 'MAG', 'MAJ', 'XSV', 'XSA']

def pos_text(texts):
    corpus = []
    for sent in texts:
        pos_tagged = ''
        for word in api.analyze(sent):
            for morph in word.morphs:
                if morph.tag in significant_tags:
                    pos_tagged += morph.lex + '/' + morph.tag + ' '
        corpus.append(pos_tagged.strip())
    return corpus

pos_post = pos_text(post_checked)

check pos_post status

 for i in range(0, 10):
    print(pos_post[i])

the error message :/

KhaiiiExcept                              Traceback (most recent call last)
<ipython-input-102-f58ea9e1df6f> in <module>
     15     return corpus
     16 
---> 17 pos_post = pos_text(post_checked)
     18 
     19 # check pos_post status

<ipython-input-102-f58ea9e1df6f> in pos_text(texts)
      8     for sent in texts:
      9         pos_tagged = ''
---> 10         for word in api.analyze(sent):
     11             for morph in word.morphs:
     12                 if morph.tag in significant_tags:

/opt/anaconda3/lib/python3.7/site-packages/khaiii/khaiii.py in analyze(self, in_str, opt_str)
    224                                            opt_str.encode('UTF-8'))
    225         if not results:
--> 226             raise KhaiiiExcept(self._last_error())
    227         words = self._make_words(in_str, results)
    228         self._free_results(results)

KhaiiiExcept: 

screenshot of the error message

the error message

kunif
  • 4,060
  • 2
  • 10
  • 30
  • 1
    What is the library `khaiii` that you seem to be using ? I cannot find it in [pypi](https://pypi.org/) – ygorg Mar 01 '21 at 14:20
  • it's the morpheme analyzer developed by Kakao..! below is the github link of the provider...! https://github.com/kakao/khaiii – chocoscone Mar 02 '21 at 04:47
  • I think the probem is linked to `for sent in texts:` where `sent` might be None or empty. – ygorg Mar 02 '21 at 09:41
  • I found out where the error was and you were so right! post_checked is a list of string and there were empty spaces within the list. that's where the for loop stopped I think :/ definitely not something I would've guessed out of the error message thanks for helping me out!!! – chocoscone Mar 03 '21 at 14:57

0 Answers0