AssertionError不允许在python中使用wordcloud并且不运行

时间:2019-11-13 08:04:36

标签: python word-cloud

我尝试用python制作波斯语Wordcloud。我运行程序包但出现错误。我尝试使用正则表达式并从文本中删除一些unicode,但无法正常工作。文字是波斯语,我是从Twitter抓取的。 这是我的代码:

import matplotlib.pyplot as plt
import matplotlib as mpl
%matplotlib inline

from persian_wordcloud.wordcloud import PersianWordCloud, add_stop_words
from wordcloud import STOPWORDS as EN_STOPWORDS3

stopwords = EN_STOPWORDS
wordcloud = PersianWordCloud(
    only_persian=True,
    max_words=100,
    stopwords=stopwords,
    margin=0,
    width=800,
    height=800,
    min_font_size=1,
    max_font_size=500,
    background_color="white"
).generate(All_Khashm_str)


plt.figure(figsize=(15,15))
image = wordcloud.to_image()
imgplot = plt.imshow(image)
plt.show()

并收到此错误:

AssertionError                            Traceback (most recent call last)
<ipython-input-40-f8bfa84af8e1> in <module>
     11     max_font_size=500,
     12     background_color="white"
---> 13 ).generate(All_Khashm_str)
     14 
     15 

~/.local/lib/python3.6/site-packages/persian_wordcloud/wordcloud.py in generate(self, text)
    142         """
    143         # reshape persian words
--> 144         text = get_display(arabic_reshaper.reshape(text))
    145         return self.generate_from_text(text)
    146 

~/.local/lib/python3.6/site-packages/bidi/algorithm.py in get_display(unicode_or_str, encoding, upper_is_rtl, base_dir, debug)
    646     resolve_weak_types(storage, debug)
    647     resolve_neutral_types(storage, debug)
--> 648     resolve_implicit_levels(storage, debug)
    649     reorder_resolved_levels(storage, debug)
    650     apply_mirroring(storage, debug)

~/.local/lib/python3.6/site-packages/bidi/algorithm.py in resolve_implicit_levels(storage, debug)
    464             # only those types are allowed at this stage
    465             assert _ch['type'] in ('L', 'R', 'EN', 'AN'),\
--> 466                     '%s not allowed here' % _ch['type']
    467 
    468             if _embedding_direction(_ch['level']) == 'L':

AssertionError:  not allowed here

感谢您的帮助。这是错误吗?

0 个答案:

没有答案