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')
Using a mask
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, scale=0.5)
awc.from_file('examples/arabic.txt').to_image()
Multiple fonts support
It's also possible to choose a different Arabic font:
from ar_wordcloud import ArabicWordCloud
awc = ArabicWordCloud(font='NotoSansArabic-ExtraBold.ttf')
t = f"عيدفطر2020 سعيد، كل عام وانتم بخير"
awc.from_text(t).to_image()
# To see the available fonts:
print(awc.fonts.available_fonts)
If the entered font name is not correct, there'll be a friendly assertion message:
AssertionError: بالله أتأكد ان اسم الخط المُدخل صحيح
Please make sure the selected font name is correct!
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.
Metadata
Release files for ar_wordcloud 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| ar_wordcloud-0.0.4.tar.gz | 545.8 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ar_wordcloud-0.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 552.1 kB
Release files / ar_wordcloud-0.0.4.tar.gz
| Download URL | ar_wordcloud-0.0.4.tar.gz |
|---|---|
| Size | 545.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
80b5cafca6fae4f940853bfc9606bc738bbfcd215cbd638353bd981173acb86b
|
|
BLAKE2b-256 checksum How to use checksums |
335b7c18da129cae10f53d1a9e7a5228632e9e17515906c6738c4ae3ccdfc91d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.18.4
|
Release files / ar_wordcloud-0.0.4-py3-none-any.whl
| Download URL | ar_wordcloud-0.0.4-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b2b22d5cabe705cc38a4f0135ceab66df3b5958551934a8e33a641e90fbff4fc
|
|
BLAKE2b-256 checksum How to use checksums |
d86f174754e845e9e9795efdc8b54189ffd4a781ab11b72f539e1525f0a68be9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.18.4
|
Security for ar_wordcloud 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.