From 05e234ed53fcfb247f06e33a4a5c860a6af05124 Mon Sep 17 00:00:00 2001 From: "Steve (Gadget) Barnes" Date: Thu, 30 Jul 2020 08:58:54 +0100 Subject: [PATCH 1/4] Update emoji.py Addresss #576 --- examples/emoji.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/emoji.py b/examples/emoji.py index ab949cab..66e7d983 100755 --- a/examples/emoji.py +++ b/examples/emoji.py @@ -24,7 +24,7 @@ d = path.dirname(__file__) if "__file__" in locals() else os.getcwd() # It is important to use io.open to correctly load the file as UTF-8 -text = io.open(path.join(d, 'happy-emoji.txt')).read() +text = io.open(path.join(d, 'happy-emoji.txt'), encoding='utf-8').read() # the regex used to detect words is a combination of normal words, ascii art, and emojis # 2+ consecutive letters (also include apostrophes), e.x It's From e493ea2005eee1e9787f5bb13c6b95502214dd9c Mon Sep 17 00:00:00 2001 From: "Steve (Gadget) Barnes" Date: Thu, 30 Jul 2020 09:00:07 +0100 Subject: [PATCH 2/4] Update parrot.py Address #576 --- examples/parrot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/parrot.py b/examples/parrot.py index 5bf31783..fc25b262 100644 --- a/examples/parrot.py +++ b/examples/parrot.py @@ -19,7 +19,7 @@ d = os.path.dirname(__file__) if "__file__" in locals() else os.getcwd() # load wikipedia text on rainbow -text = open(os.path.join(d, 'wiki_rainbow.txt')).read() +text = open(os.path.join(d, 'wiki_rainbow.txt'), encoding='utf-8').read() # load image. This has been modified in gimp to be brighter and have more saturation. parrot_color = np.array(Image.open(os.path.join(d, "parrot-by-jose-mari-gimenez2.jpg"))) From 657a53e12a438d76e3aa1722a85f8dfc35066c3d Mon Sep 17 00:00:00 2001 From: Steve Barnes Date: Thu, 30 Jul 2020 09:35:53 +0100 Subject: [PATCH 3/4] Updated wordcloud_cn.py to run #576 --- examples/wordcloud_cn.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/examples/wordcloud_cn.py b/examples/wordcloud_cn.py index c898727b..d9294559 100644 --- a/examples/wordcloud_cn.py +++ b/examples/wordcloud_cn.py @@ -12,9 +12,14 @@ at the same time using wordcloud with jieba very convenient """ -import jieba -jieba.enable_parallel(4) -# Setting up parallel processes :4 ,but unable to run on Windows +import sys +try: + import jieba +except ImportError: + sys.exit('For this example you need to pip install jieba') +if not sys.platform == 'win32': + jieba.enable_parallel(4) + # Setting up parallel processes :4 ,but unable to run on Windows from os import path from imageio import imread import matplotlib.pyplot as plt @@ -24,7 +29,8 @@ from wordcloud import WordCloud, ImageColorGenerator # get data directory (using getcwd() is needed to support running example in generated IPython notebook) -d = path.dirname(__file__) if "__file__" in locals() else os.getcwd() +d = path.dirname(path.abspath(__file__)) if "__file__" in locals() else path.abspath(os.getcwd()) +print(f"{d=} {__file__=}") stopwords_path = d + '/wc_cn/stopwords_cn_en.txt' # Chinese fonts must be set @@ -33,11 +39,13 @@ # the path to save worldcloud imgname1 = d + '/wc_cn/LuXun.jpg' imgname2 = d + '/wc_cn/LuXun_colored.jpg' +#print(f"{imgname1=} {path.exists(imgname1)}") +#print(f"{imgname2=} {path.exists(imgname2)}") # read the mask / color image taken from -back_coloring = imread(path.join(d, d + '/wc_cn/LuXun_color.jpg')) +back_coloring = imread(imgname2) # Read the whole text. -text = open(path.join(d, d + '/wc_cn/CalltoArms.txt')).read() +text = open(path.join(d, d + '/wc_cn/CalltoArms.txt'), encoding='utf-8').read() # if you want use wordCloud,you need it # add userdict by add_word() From 4ccfaab7519ee2784f006ad516cbd96d8d904c7f Mon Sep 17 00:00:00 2001 From: Steve Barnes Date: Thu, 30 Jul 2020 09:43:15 +0100 Subject: [PATCH 4/4] Removed python 3.8 style debug statements --- examples/wordcloud_cn.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/wordcloud_cn.py b/examples/wordcloud_cn.py index d9294559..d7388cf6 100644 --- a/examples/wordcloud_cn.py +++ b/examples/wordcloud_cn.py @@ -30,7 +30,6 @@ # get data directory (using getcwd() is needed to support running example in generated IPython notebook) d = path.dirname(path.abspath(__file__)) if "__file__" in locals() else path.abspath(os.getcwd()) -print(f"{d=} {__file__=}") stopwords_path = d + '/wc_cn/stopwords_cn_en.txt' # Chinese fonts must be set @@ -39,8 +38,6 @@ # the path to save worldcloud imgname1 = d + '/wc_cn/LuXun.jpg' imgname2 = d + '/wc_cn/LuXun_colored.jpg' -#print(f"{imgname1=} {path.exists(imgname1)}") -#print(f"{imgname2=} {path.exists(imgname2)}") # read the mask / color image taken from back_coloring = imread(imgname2)