首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wordsegement python库: ValueError: max() arg是一个空序列

wordsegement python库: ValueError: max() arg是一个空序列
EN

Stack Overflow用户
提问于 2020-02-17 11:47:19
回答 1查看 393关注 0票数 1

我使用wordsegment python库对文本进行标记,如下所示:

代码语言:javascript
复制
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))

然而,我遇到了一个奇怪的错误,我无法理解没有修复:

代码语言:javascript
复制
---------------------------------------------------------------------------
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
  • anaconda3
  • wordsegemt==1.3.0

对于如何解决这个问题有什么建议吗?是图书馆的窃听器吗?

EN

回答 1

Stack Overflow用户

发布于 2020-03-15 08:18:15

请在“从load段导入加载,段”之后添加"load()“,这对我有效。

屏幕截图

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60261766

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档