{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Create wordcloud with Arabic\nGenerating a wordcloud from Arabic text\n\nDependencies:\n- bidi.algorithm\n- arabic_reshaper\n\nDependencies installation:\npip install python-bidi arabic_reshape\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import os\nimport codecs\nfrom wordcloud import WordCloud\nimport arabic_reshaper\nfrom bidi.algorithm import get_display\n\n# get data directory (using getcwd() is needed to support running example in generated IPython notebook)\nd = os.path.dirname(__file__) if \"__file__\" in locals() else os.getcwd()\n\n# Read the whole text.\nf = codecs.open(os.path.join(d, 'arabicwords.txt'), 'r', 'utf-8')\n\n# Make text readable for a non-Arabic library like wordcloud\ntext = arabic_reshaper.reshape(f.read())\ntext = get_display(text)\n\n# Generate a word cloud image\nwordcloud = WordCloud(font_path='fonts/NotoNaskhArabic/NotoNaskhArabic-Regular.ttf').generate(text)\n\n# Export to an image\nwordcloud.to_file(\"arabic_example.png\")"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.13.5"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}