/klpt

The Kurdish Language Processing Toolkit

Primary LanguagePythonOtherNOASSERTION

Kurdish Language Processing Toolkit

Build GitHub PyPI - Downloads Documentation Documentation PyPI version

Welcome / Hûn bi xêr hatin / بە خێر بێن! 🙂

Kurdish Language Processing Toolkit--KLPT is a natural language processing (NLP) toolkit in Python for the Kurdish language. The current version comes with four core modules, namely preprocess, stem, transliterate and tokenize and addresses basic language processing tasks such as text preprocessing, stemming, tokenization, spell-checking and morphological analysis for the Sorani and the Kurmanji dialects of Kurdish.

Install KLPT

  • Operating system: macOS / OS X · Linux · Windows (Cygwin, MinGW, Visual Studio)
  • Python version: Python 3.5+
  • Package managers: pip

pip

Using pip, KLPT releases are available as source packages and binary wheels. Please make sure that a compatible Python version is installed:

pip install klpt

All the data files including lexicons and morphological rules are also installed with the package.

Although KLPT is not dependent on any NLP toolkit, there is one important requirement, particularly for the stem module. That is cyhunspell which should be installed with a version >= 2.0.1.

About this version

Please note that KLPT is under development and some of the functionalities will appear in the future versions. You can find out regarding the progress of each task at the Projects section. In the current version, the following tasks are included:

Modules
Tasks Sorani (ckb) Kurmanji (kmr)
preprocess normalization ✓ (v0.1.0) ✓ (v0.1.0)
standardization ✓ (v0.1.0) ✓ (v0.1.0)
unification of numerals ✓ (v0.1.0) ✓ (v0.1.0)
tokenize word tokenization
✓ (v0.1.0) ✓ (v0.1.0)
MWE tokenization
✓ (v0.1.0) ✓ (v0.1.0)
sentence tokenization ✓ (v0.1.0) ✓ (v0.1.0)
transliterate Arabic to Latin ✓ (v0.1.0) ✓ (v0.1.0)
Latin to Arabic ✓ (v0.1.0) ✓ (v0.1.0)
Detection of u/w and î/y ✓ (v0.1.0) ✓ (v0.1.0)
Detection of Bizroke ( i )
stem morphological analysis ✓ (v0.1.0) ✓ (v0.1.1) 🆕
morphological generation ✓ (v0.1.0)
stemming
lemmatization
spell error detection and correction ✓ (v0.1.0)

Basic usage

Once the package is installed, you can import the toolkit as follows:

import klpt

In the following, a few examples are provided to work with various modules. Almost all the classes have three arguments in common:

  • dialect: the name of the dialect as Sorani or Kurmanji (ISO 639-3 code will be also added)
  • script: the script of your input text as "Arabic" or "Latin"
  • numeral: the type of the numerals as
    • Arabic [١٢٣٤٥٦٧٨٩٠]
    • Farsi [۱۲۳۴۵۶۷۸۹۰]
    • Latin [1234567890]

Preprocess

This module deals with normalizing scripts and orthographies by using writing conventions based on dialects and scripts. The goal is not to correct the orthography but to normalize the text in terms of the encoding and common writing rules. The input encoding should be in UTF-8 only. To this end, three functions are provided as follows:

  • normalize: deals with different encodings and unifies characters based on dialects and scripts
  • standardize: given a normalized text, it returns standardized text based on the Kurdish orthographies following recommendations for Kurmanji and Sorani
  • unify_numerals: conversion of the various types of numerals used in Kurdish texts

It is recommended that the output of this module be used as the input of subsequent tasks in an NLP pipeline.

>>> from klpt.preprocess import Preprocess

>>> preprocessor_ckb = Preprocess("Sorani", "Arabic", numeral="Latin")
>>> preprocessor_ckb.normalize("لە ســـاڵەکانی ١٩٥٠دا")
'لە ساڵەکانی 1950دا'
>>> preprocessor_ckb.standardize("راستە لەو ووڵاتەدا")
'ڕاستە لەو وڵاتەدا'
>>> preprocessor_ckb.unify_numerals("٢٠٢٠")
'2020'

>>> preprocessor_kmr = Preprocess("Kurmanji", "Latin")
>>> preprocessor_kmr.standardize("di sala 2018-an")
'di sala 2018an'
>>> preprocessor_kmr.standardize("hêviya")
'hêvîya'

Tokenization

This module focuses on the tokenization of both Kurmanji and Sorani dialects of Kurdish with the following functions:

  • word_tokenize: tokenization of texts into tokens (both multi-word expressions and single-word tokens).
  • mwe_tokenize: tokenization of texts by only taking compound forms into account
  • sent_tokenize: tokenization of texts into sentences

The module is based on the Kurdish tokenization project.

>>> from klpt.tokenize import Tokenize

>>> tokenizer = Tokenize("Kurmanji", "Latin")
>>> tokenizer.word_tokenize("ji bo fortê xwe avêtin")
['▁ji▁', 'bo', '▁▁fortê‒xwe‒avêtin▁▁']
>>> tokenizer.mwe_tokenize("bi serokê hukûmeta herêma Kurdistanê Prof. Salih re saz kir.")
'bi serokê hukûmeta herêma Kurdistanê Prof . Salih re saz kir .'

>>> tokenizer_ckb = Tokenize("Sorani", "Arabic")
>>> tokenizer_ckb.word("بە هەموو هەمووانەوە ڕێک کەوتن")
['▁بە▁', '▁هەموو▁', 'هەمووانەوە', '▁▁ڕێک‒کەوتن▁▁']

Transliteration

This module aims at transliterating one script of Kurdish into another one. Currently, only the Latin-based and the Arabic-based scripts of Sorani and Kurmanji are supported. The main function in this module is transliterate() which also takes care of detecting the correct form of double-usage graphemes, namely و ↔ w/u and ی ↔ î/y. In some specific occasions, it can also predict the placement of the missing i (also known as Bizroke/بزرۆکە).

The module is based on the Kurdish transliteration project.

>>> from klpt.transliterate import Transliterate
>>> transliterate = Transliterate("Kurmanji", "Latin", target_script="Arabic")
>>> transliterate.transliterate("rojhilata navîn")
'رۆژهلاتا ناڤین'

>>> transliterate_ckb = Transliterate("Sorani", "Arabic", target_script="Latin")
>>> transliterate_ckb.transliterate("لە وڵاتەکانی دیکەدا")
'le wiłatekanî dîkeda'

Stem

The Stem module deals with various tasks, mainly through the following functions:

  • check_spelling: spell error detection
  • correct_spelling: spell error correction
  • analyze: morphological analysis

The module is based on the Kurdish Hunspell project for Sorani and the Apertium project for Kurmanji. Please note that this module is currently getting further completed and we are aware of its current shortcomings.

>>> from klpt.stem import Stem
>>> stemmer = Stem("Sorani", "Arabic")
>>> stemmer.check_spelling("سوتاندبووت")
False
>>> stemmer.correct_spelling("سوتاندبووت")
(False, ['ستاندبووت', 'سووتاندبووت', 'سووڕاندبووت', 'ڕووتاندبووت', 'فەوتاندبووت', 'بووژاندبووت'])
>>> stemmer.analyze("دیتبامن")
[{'pos': 'verb', 'description': 'past_stem_transitive_active', 'base': 'دیت', 'terminal_suffix': 'بامن'}]

>>> stemmer = Stem("Kurmanji", "Latin")
>>> stemmer.analyze("dibêjim")
[{'base': 'gotin', 'description': 'vblex_tv_pri_p1_sg', 'pos': '', 'terminal_suffix': '', 'formation': ''}]

📖 Please note that a more complete documentation of the toolkit will be available soon.

Become a sponsor

Please consider donating to the project. Data annotation and resource creation requires tremendous amount of time and linguistic expertise. Even a trivial donation will make a difference. You can do so by becoming a sponsor to accompany me in this journey and help the Kurdish language have a better place within other natural languages on the Web. Depending on your support,

  • You can be an official sponsor
  • You will get a GitHub sponsor badge on your profile
  • If you have any questions, I will focus on it
  • If you want, I will add your name or company logo on the front page of your preferred project
  • Your contribution will be acknowledged in one of my future papers in a field of your choice

Number of sponsors: Open Collective sponsors (You, be the first one! 🙂)

Contribute

Are you interested in this project? Each task is addressed individually. Please check the following repositories to find which one you are more interested in:

In addition, our main objective is to extend the current toolkit to include more tasks, particularly part-of-speech tagging, named-entity recognition and syntactic analysis. Further instructions are provided at https://sinaahmadi.github.io/klpt/about/contributing/. You can also join us on Gitter.

Don't forget, open-source is fun! 😊

Thanks to all the following contributors for their valuable contributions!

Requirements

Cite this paper

Please consider citing this paper, if you use any part of the data or the tool (bib file):

@inproceedings{ahmadi2020klpt,
    title = "{KLPT--Kurdish Language Processing Toolkit}",
    author = "Ahmadi, Sina",
    booktitle = "Proceedings of the second Workshop for {NLP} Open Source Software ({NLP}-{OSS})",
    month = nov,
    year = "2020",
    publisher = "Association for Computational Linguistics"
}

License

Creative Commons License
Kurdish Language Processing Toolkit by Sina Ahmadi is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License which means:

  • You are free to share, copy and redistribute the material in any medium or format and also adapt, remix, transform, and build upon the material for any purpose, even commercially.
  • You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.