A tiny wrapper around `wordcloud.WordCloud` to support Arabic WordCloud
Project description
✨ May, 17 2020 ✨
ar_wordcloud
A tiny wrapper around wordcloud.WordCloud
to support WordCloud with Arabic text.
Installation:
$ pip install ar_wordcloud
Usage:
Also, see the notebook example.
Import and instantiate the main class:
from ar_wordcloud import ArabicWordCloud
awc = ArabicWordCloud(background_color="white")
Then, either build a word cloud from a raw text string:
t = 'أهلاً وسهلا، اللغة العربية جميلة'
wc = awc.from_text(t)
wc.to_file('hello.png')
Or, build a word cloud from a dictionary:
d = {"مرحبا": 12, "برمج": 8, "من": 10, "رمضان كريم": 15, "العيد قرب": 12, "اهلين": 1, "كورونا": 3}
dict_wc = awc.from_dict(d, ignore_stopwords=True)
awc.plot(dict_wc, title="كل عام وانتم بخير", width=2, height=2)
Or, read text from a file:
wc = awc.from_file('examples/arabic.txt')
wc.to_file('examples/arabic.png')
Also, you can use a mask:
from ar_wordcloud import ArabicWordCloud
from ar_wordcloud.utils import read_mask_image
mask_img = read_mask_image() # NOTE: pass `mask_img_url` param to use a different mask, the default is a heart
awc = ArabicWordCloud(background_color="white", mask=mask_img, contour_width=4)
awc.from_file('examples/arabic.txt').to_image()
TODO:
- support mask plots
- clean input text (remove punct .. etc)
- support input from file e.g.
awc.from_file(fname)
- browse available fonts and select favorite
- fix English font
- cli support
PRs are welcome, thanks 🙏
Credit: this repo was born from the discussion in this PR.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ar_wordcloud-0.0.3.tar.gz
(675.2 kB
view details)
Built Distribution
File details
Details for the file ar_wordcloud-0.0.3.tar.gz
.
File metadata
- Download URL: ar_wordcloud-0.0.3.tar.gz
- Upload date:
- Size: 675.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.18.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5a841eeb563cdb90d2650b2d1b709cfe9739953fa2c0057619d723a7c25bcf4 |
|
MD5 | 9a17afe6991b57de5efac2cbb3460b27 |
|
BLAKE2b-256 | a8affecb55aebe26b8b2884d14fc9c0b521ecc0b5db86e3c670465d9fb475bed |
File details
Details for the file ar_wordcloud-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: ar_wordcloud-0.0.3-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.18.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dd972e603b2d49eba4566dd9ebcb258c74ae901601cefecc038a5179f16c6be |
|
MD5 | 11c6a4a2beddefe4f4863fa9b0e8d451 |
|
BLAKE2b-256 | 2e2316b50f419db4f152a56116ddc9bfb3eba60be3d80dd189f76e105e40a03b |