1

我正在使用wordsegmentpython 库来标记我的文本,如下所示:

from wordsegment import load, segment
tweet = 'Sobering stats: 110,000 homes worth $20B in flood-affected areas in Baton Rouge region, #lawx 
 ... via @theadvocatebr'
print(segment(tweet))

但是,我遇到了一个我无法理解的奇怪错误,无法修复:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-2-a4734f82b340> in <module>
      1 from wordsegment import load, segment
      2 tweet = 'Sobering stats: 110,000 homes worth $20B in flood-affected areas in Baton Rouge region, #lawx via @theadvocatebr'
----> 3 print(segment(tweet))

~\Anaconda3\lib\site-packages\wordsegment\__init__.py in segment(self, text)
    165     def segment(self, text):
    166         "Return list of words that is the best segmenation of `text`."
--> 167         return list(self.isegment(text))
    168 
    169 

~\Anaconda3\lib\site-packages\wordsegment\__init__.py in isegment(self, text)
    151         for offset in range(0, len(clean_text), size):
    152             chunk = clean_text[offset:(offset + size)]
--> 153             _, chunk_words = search(prefix + chunk)
    154             prefix = ''.join(chunk_words[-5:])
    155             del chunk_words[-5:]

~\Anaconda3\lib\site-packages\wordsegment\__init__.py in search(text, previous)
    138                     yield (prefix_score + suffix_score, [prefix] + suffix_words)
    139 
--> 140             return max(candidates())
    141 
    142         # Avoid recursion limit issues by dividing text into chunks, segmenting

ValueError: max() arg is an empty sequence

我在 Windows 10 上使用以下内容:

  • Python3
  • 蟒蛇3
  • wordgemt==1.3.0

有关如何解决此问题的任何提示?这是图书馆的错误吗?

4

1 回答 1

1

请在“from wordsegment import load, segment”之后添加“load()”这对我有用。

截屏

于 2020-03-15T08:18:15.860 回答