Skip to main content

FarsiWordCloud README

Overview

The FarsiWordCloud class is a specialized extension of the Fonts class designed to generate word clouds in Farsi (Persian) text. It handles text reshaping and bidirectional text rendering to ensure that Farsi text is correctly displayed in the word cloud.

Installation

To use the FarsiWordCloud class, you need to have the following libraries installed:

  • matplotlib
  • wordcloud
  • arabic_reshaper
  • bidi

You can install these libraries using pip:

pip install matplotlib wordcloud arabic-reshaper python-bidi

Usage

Here is an example of how to use the FarsiWordCloud class:

from FarsiWordCloud import FarsiWordCloud

# Sample text in Farsi
text = "سلام  این یک تست برای ایجاد واژه‌ابری است."

# Create an instance of FarsiWordCloud
wordcloud = FarsiWordCloud(
    text=text,
    font_name="BYekan",  # Specify the font name from the available fonts
    width=800,
    height=400,
    background_color='white',
    max_font_size=250,
    min_font_size=10
)

# Generate the word cloud
wordcloud.generate_wordcloud()

# Display the word cloud
wordcloud.show_wordcloud()

# Save the word cloud to a file
wordcloud.save_wordcloud(filename='farsi_wordcloud.png')

Methods

  • text: The Farsi text to be used for generating the word cloud.
  • font_name: The name of the font to be used. This should be one of the fonts listed in the info.json file.
  • width: The width of the word cloud image (in pixels).
  • height: The height of the word cloud image (in pixels).
  • background_color: The background color of the word cloud.
  • max_font_size: The maximum font size for the words in the word cloud.
  • min_font_size: The minimum font size for the words in the word cloud.

reshape_text(self)

Reshapes and reorders the Farsi text to ensure correct display. This method uses the arabic_reshaper library to reshape the text and the bidi library to handle bidirectional text.

generate_wordcloud(self)

Generates the word cloud from the reshaped text. This method creates a WordCloud object with the specified parameters and generates the word cloud image.

show_wordcloud(self)

Displays the generated word cloud using matplotlib. If the word cloud has not been generated yet, this method will call generate_wordcloud() first.

save_wordcloud(self, filename='wordcloud.png')

Saves the generated word cloud to a file. The default filename is wordcloud.png, but you can specify a different filename if desired.

Fonts

The FarsiWordCloud class relies on a set of fonts specified in the fonts/info.json file. Ensure that the font files listed in this file are available in the fonts/files/ directory.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Release files for farsi-wordcloud 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for farsi-wordcloud 0.1.0
File Size Uploaded
farsi_wordcloud-0.1.0.tar.gz 2.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for farsi-wordcloud 0.1.0
File Interpreter ABI Platform
farsi_wordcloud-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 5.0 kB

Release files / farsi_wordcloud-0.1.0.tar.gz

Download URL farsi_wordcloud-0.1.0.tar.gz
Size 2.6 kB
Tags Source
SHA-256 checksum
How to use checksums
16f260939fa1a40b5d1e916cdbe30bc008cbfd2a5e3ca9a505797eb6c80a5dee
BLAKE2b-256 checksum
How to use checksums
321f0897e7802608f370562868ffa69c5c37da95eadde7c357df247ce5384315
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.4

Release files / farsi_wordcloud-0.1.0-py3-none-any.whl

Download URL farsi_wordcloud-0.1.0-py3-none-any.whl
Size 2.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a64a52dbd8fc1e190358fb7ad547cbe36aab81c2542964a26b07ddc1e2c6549
BLAKE2b-256 checksum
How to use checksums
d9ec656e1e398c0472dc9a3043adf60fc9950d72133f868c22e108d700c41800
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page