### Install Qalsadi Requirements Source: https://github.com/linuxscout/qalsadi/blob/master/README.md Install all necessary dependencies for Qalsadi by referencing the requirements.txt file. This is typically done after cloning the repository. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install Qalsadi in Editable Mode Source: https://github.com/linuxscout/qalsadi/blob/master/docs/CONTRIBUTING.md Install the Qalsadi package in editable mode with development dependencies. This allows for immediate changes to be reflected. ```bash pip install -e .[dev] ``` -------------------------------- ### Install Qalsadi Python Package Source: https://github.com/linuxscout/qalsadi/blob/master/README.md Use pip to install the Qalsadi library. This is the primary method for adding Qalsadi to your Python environment. ```bash pip install qalsadi ``` -------------------------------- ### Lemmatize Arabic Text with Qalsadi Source: https://github.com/linuxscout/qalsadi/blob/master/README.md Demonstrates how to lemmatize Arabic text using the Qalsadi library. Includes examples for single words, full texts, and returning part-of-speech tags. Ensure the `qalsadi.lemmatizer` module is imported. ```python >>> import qalsadi.lemmatizer >>> text = u"""هل تحتاج إلى ترجمة كي تفهم خطاب الملك؟ اللغة \"الكلاسيكية\" (الفصحى) موجودة في كل اللغات وكذلك اللغة \"الدارجة\" .. الفرنسية التي ندرس في المدرسة ليست الفرنسية التي يستخدمها الناس في شوارع باريس .. وملكة بريطانيا لا تخطب بلغة شوارع لندن .. لكل مقام مقال""" >>> lemmer = qalsadi.lemmatizer.Lemmatizer() >>> # lemmatize a word ... lemmer.lemmatize("يحتاج") 'احتاج' >>> # lemmatize a word with a specific pos >>> lemmer.lemmatize("وفي") 'في' >>> lemmer.lemmatize("وفي", pos="v") 'وفى' ``` ```python >>> lemmas = lemmer.lemmatize_text(text) >>> print(lemmas) ['هل', 'احتاج', 'إلى', 'ترجمة', 'كي', 'تفهم', 'خطاب', 'ملك', '؟', 'لغة', '"', 'كلاسيكي', '"(', 'فصحى', ')', 'موجود', 'في', 'كل', 'لغة', 'ذلك', 'لغة', '"', 'دارج', '"..', 'فرنسي', 'التي', 'درس', 'في', 'مدرسة', 'ليست', 'فرنسي', 'التي', 'استخدم', 'ناس', 'في', 'شوارع', 'باريس', '..', 'ملك', 'بريطانيا', 'لا', 'خطب', 'بلغة', 'شوارع', 'دنو', '..', 'كل', 'مقام', 'مقالي'] ``` ```python >>> # lemmatize a text and return lemma pos ... lemmas = lemmer.lemmatize_text(text, return_pos=True) >>> print(lemmas) [('هل', 'stopword'), ('احتاج', 'verb'), ('إلى', 'stopword'), ('ترجمة', 'noun'), ('كي', 'stopword'), ('تفهم', 'noun'), ('خطاب', 'noun'), ('ملك', 'noun'), '؟', ('لغة', 'noun'), '"', ('كلاسيكي', 'noun'), '"(', ('فصحى', 'noun'), ')', ('موجود', 'noun'), ('في', 'stopword'), ('كل', 'stopword'), ('لغة', 'noun'), ('ذلك', 'stopword'), ('لغة', 'noun'), '"', ('دارج', 'noun'), '"..', ('فرنسي', 'noun'), ('التي', 'stopword'), ('درس', 'verb'), ('في', 'stopword'), ('مدرسة', 'noun'), ('ليست', 'stopword'), ('فرنسي', 'noun'), ('التي', 'stopword'), ('استخدم', 'verb'), ('ناس', 'noun'), ('في', 'stopword'), ('شوارع', 'noun'), ('باريس', 'all'), '..', ('ملك', 'noun'), ('بريطانيا', 'noun'), ('لا', 'stopword'), ('خطب', 'verb'), ('بلغة', 'noun'), ('شوارع', 'noun'), ('دنو', 'verb'), '..', ('كل', 'stopword'), ('مقام', 'noun'), ('مقالي', 'noun')] ``` ```python >>> # Get vocalized output lemmas >>> lemmer.set_vocalized_lemma() >>> lemmas = lemmer.lemmatize_text(text) >>> print(lemmas) ['هَلْ', 'اِحْتَاجَ', 'إِلَى', 'تَرْجَمَةٌ', 'كَيْ', 'تَفَهُّمٌ', 'خَطَّابٌ', 'مَلَكٌ', '؟', 'لُغَةٌ', '"', 'كِلاَسِيكِيٌّ', '"(', 'فُصْحَى', ')', 'مَوْجُودٌ', 'فِي', 'كُلَّ', 'لُغَةٌ', 'ذَلِكَ', 'لُغَةٌ', '"', 'دَارِجٌ', '"..', 'فَرَنْسِيّ', 'الَّتِي', 'دَرَسَ', 'فِي', 'مَدْرَسَةٌ', 'لَيْسَتْ', 'فَرَنْسِيّ', 'الَّتِي', 'اِسْتَخْدَمَ', 'نَاسٌ', 'فِي', 'شَوَارِعٌ', 'باريس', '..', 'مَلَكٌ', 'برِيطانِيا', 'لَا', 'خَطَبَ', 'بَلَغَةٌ', 'شَوَارِعٌ', 'أَدَانَ', '..', 'كُلَّ', 'مَقَامٌ', 'مَقَالٌ'] ``` ```python >>> # get all lemmas for each word text >>> lemmas = lemmer.lemmatize_text(text, all=True) >>> lemmas [['هل', 'وهل', 'هال'], ['احتاج'], ['إلى'], ['ترجمة'], ['كي'], ['تف', 'أفهم', 'فهم', 'تفهم'], ['خاطب', 'خطاب'], ['مالك', 'ملك'], ['؟'], ['لغة'], ['"'], ['كلاسيكي'], ['"('], ['فصحى'], [')'], ['موجود'], ['في'], ['أكل', 'كال', 'كل', 'وكل'], ['لغة'], ['كذلك', 'ذل'], ['لغة'], ['"'], ['دارج'], ['"..'], ['فرنسة', 'فرنسي'], ['التي'], ['درس'], ['في'], ['مدرس', 'مدرسة'], ['يس', 'ليست', 'لاس', 'ليس'], ['فرنسة', 'فرنسي'], ['التي'], ['استخدم'], ['ناس'], ['في'], ['شارع'], ['باريس'], ['..'], ['مالك', 'ملك', 'ملكة'], ['بريطانيا', 'بريطاني'], ['لا'], ['خطب'], ['بالغ', 'لغة', 'بلغة'], ['شارع'], ['دن', 'دنى', 'دان', 'ناد', 'دنو', 'أدنى', 'أدان', 'دنا', 'ودن'], ['..'], ['كل'], ['مقام'], ['مقالي', 'مقال']] ``` -------------------------------- ### Set Up Virtual Environment Source: https://github.com/linuxscout/qalsadi/blob/master/docs/CONTRIBUTING.md Create and activate a Python virtual environment for development. This isolates project dependencies. ```bash python3 -m venv venv source venv/bin/activate ``` -------------------------------- ### Display Morphology Analysis Results Source: https://github.com/linuxscout/qalsadi/blob/master/README.md Initializes the analyzer and formatter, then displays the main fields of the morphology analysis results in a table format. Requires importing qalsadi.analex and qalsadi.resultformatter. ```python import qalsadi.analex as qa from qalsadi.resultformatter import ResultFormatter text = "لا يحمل الحقد من تعلو به الرتب" analyzer = qa.Analex() results = analyzer.check_text(text) formatter = ResultFormatter(result) # Use main fields display formatter.set_used_fields("main") print(formatter.as_table()) ``` -------------------------------- ### Clone the Qalsadi Repository Source: https://github.com/linuxscout/qalsadi/blob/master/docs/CONTRIBUTING.md Clone your forked repository to your local machine. Navigate into the cloned directory. ```bash git clone https://github.com/linuxscout/qalsadi.git cd qalsadi ``` -------------------------------- ### Configure Pickle Cache Source: https://github.com/linuxscout/qalsadi/blob/master/README.md Set up a pickle cache for the Analex analyzer, specifying the path for the cache file. Cache usage can be enabled. ```python >> > import qalsadi.analex >> > from qalsadi.cachemanager.cache_pickle import Cache >> > analyzer = qalsadi.analex.Analex() >> > # configure cacher >> > # configure path used to store the cache >> > path = 'cache/qalsadiCache.pickle' >> > cacher = Cache(path) >> > analyzer.set_cacher(cacher) >> > # to enable the use of cacher >> > analyzer.enable_allow_cache_use() ``` -------------------------------- ### Configure CodernityDB Cache Source: https://github.com/linuxscout/qalsadi/blob/master/README.md Set up a CodernityDB cache for the Analex analyzer, specifying the directory for the database. Cache usage can be enabled. ```python >> > import qalsadi.analex >> > from qalsadi.cachemanager.cache_codernity import Cache >> > analyzer = qalsadi.analex.Analex() >> > # configure cacher >> > # configure path used to store the cache >> > path = 'cache' >> > cacher = Cache(path) >> > analyzer.set_cacher(cacher) >> > # to enable the use of cacher >> > analyzer.enable_allow_cache_use() ``` -------------------------------- ### Configure Pickledb Cache Source: https://github.com/linuxscout/qalsadi/blob/master/README.md Configure a pickledb cache for the Analex analyzer, providing the path for the database file. Cache usage can be enabled. ```python >> > import qalsadi.analex >> > from qalsadi.cachemanager.cache_pickledb import Cache >> > analyzer = qalsadi.analex.Analex() >> > # configure cacher >> > # configure path used to store the cache >> > path = 'cache/qalsadiCache.pickledb' >> > cacher = Cache(path) >> > analyzer.set_cacher(cacher) >> > # to enable the use of cacher >> > analyzer.enable_allow_cache_use() ``` -------------------------------- ### Format Code with Black Source: https://github.com/linuxscout/qalsadi/blob/master/docs/CONTRIBUTING.md Use the Black code formatter to ensure adherence to PEP8 style guidelines. Apply it to the 'qalsadi/' and 'tests/' directories. ```bash black qalsadi/ tests/ ``` -------------------------------- ### Run Unit Tests Source: https://github.com/linuxscout/qalsadi/blob/master/docs/CONTRIBUTING.md Execute the project's unit tests using Python's unittest module or pytest. Tests are located in the 'tests/' directory. ```bash python3 -m unittest discover tests ``` ```bash pytest ``` -------------------------------- ### Format Morphology Analysis Results as Table Source: https://github.com/linuxscout/qalsadi/blob/master/README.md Demonstrates how to format morphology analysis results into different table formats using the `as_table` method. The `tablefmt` parameter accepts values from the `tabulate` library. ```python # other table format print(formatter.as_table(tablefmt="github")) # tablefmt can table all values from tabulate libray # "plain" (default), "grid", "pipe" (Markdown), "html", "latex", "tsv" ``` -------------------------------- ### Configure Cache using Factory Method Source: https://github.com/linuxscout/qalsadi/blob/master/README.md Use the Cache_Factory to create and configure different cache types. Specify the cache type and the path for persistent caches. ```python >> > import qalsadi.analex >> > from qalsadi.cachemanager.cache_factory import Cache_Factory >> > analyzer = qalsadi.analex.Analex() >> > # list available cache names >> > Cache_Factory.list() ['', 'memory', 'pickle', 'pickledb', 'codernity'] >> > # configure cacher >> > # configure path used to store the cache >> > path = 'cache/qalsasicache.pickledb' >> > cacher = Cache_Factory.factory("pickledb", path) >> > analyzer.set_cacher(cacher) >> > # to enable the use of cacher >> > analyzer.enable_allow_cache_use() ``` -------------------------------- ### Configure Memory Cache Source: https://github.com/linuxscout/qalsadi/blob/master/README.md Instantiate and set a memory cache for the Analex analyzer. Cache usage can be enabled or disabled. ```python >> > import qalsadi.analex >> > analyzer = qalsadi.analex.Analex() >> > # configure cacher >> > import qalsadi.cachemanager >> > cacher = qalsadi.cache.cache.Cache() >> > analyzer.set_cacher(cacher) >> > # to enable the use of cacher >> > analyzer.enable_allow_cache_use() >> > # to disable the use of cacher >> > analyzer.disable_allow_cache_use() ``` -------------------------------- ### Save Morphology Analysis Results to Files Source: https://github.com/linuxscout/qalsadi/blob/master/README.md Illustrates how to save morphology analysis results directly to CSV, JSON, and XML files. ```python formatter.as_csv("output/results.csv") formatter.to_json("output/results.json") formatter.to_xml("output/results.xml") ``` -------------------------------- ### Add Customizable Fields to Morphology Analysis Display Source: https://github.com/linuxscout/qalsadi/blob/master/README.md Demonstrates how to add custom fields to the display in addition to a predefined profile. Invalid field names are ignored. ```python profile = "main" # other values: "roots", "lemmas", "inflect" formatter.set_used_fields(profile, additional_fields=["root","INVALID"]) ``` -------------------------------- ### Commit and Push Changes Source: https://github.com/linuxscout/qalsadi/blob/master/docs/CONTRIBUTING.md Commit your changes with a descriptive message and push the branch to your remote repository. Ensure tests pass and code is formatted. ```bash git commit -m "Add feature: describe it" git push origin feature/my-new-feature ``` -------------------------------- ### BibTeX Citation for 'Towards An Open Platform For Arabic Language Processing' Source: https://github.com/linuxscout/qalsadi/blob/master/docs/Readme.md Use this BibTeX entry to cite Taha Zerrouki's work on an open platform for Arabic language processing, relevant for academic references. ```bibtex @thesis{zerrouki2020towards, title={Towards An Open Platform For Arabic Language Processing}, author={Zerrouki, Taha}, year={2020} } ``` -------------------------------- ### Format Morphology Analysis Results to Different Formats Source: https://github.com/linuxscout/qalsadi/blob/master/README.md Shows how to convert morphology analysis results into CSV, JSON, and XML formats using dedicated methods. ```python print(formatter.as_csv()) print(formatter.as_json()) print(formatter.as_xml()) ``` -------------------------------- ### Morphology Analysis of Arabic Text with Qalsadi Source: https://github.com/linuxscout/qalsadi/blob/master/README.md Performs morphology analysis on Arabic text using the `Analex` class from the `qalsadi.analex` module. This snippet checks the grammatical structure of a given sentence. ```python import qalsadi.analex as qa text = "لا يحمل الحقد من تعلو به الرتب" analyzer = qa.Analex() result = analyzer.check_text(text) print(result) ```