Skip to main content

A modern Python toolkit for Arabic Natural Language Processing (NLP).

Project description

Arabic NLP Toolkit

A lightweight, modular, and easy-to-use Python library for Arabic Natural Language Processing (NLP).

The toolkit provides common Arabic text preprocessing utilities including cleaning, normalization, tokenization, stopword removal, sentence segmentation, keyword extraction, similarity measurement, and more.


Features

Text Cleaning

  • Remove URLs
  • Remove Mentions (@username)
  • Remove Hashtags (#hashtag)
  • Remove Emojis
  • Remove Arabic Diacritics (Tashkeel)
  • Remove Tatweel (ـ)
  • Remove Extra Spaces

Arabic NLP

  • Arabic Text Normalization
  • Arabic Tokenization
  • Arabic Stopword Removal
  • Sentence Splitting
  • Word Frequency Analysis
  • Word N-Grams
  • Character N-Grams
  • Keyword Extraction
  • Language Detection
  • Text Statistics
  • Jaccard Text Similarity

Installation

pip install arabic-nlp-toolkit

Note

The package is currently under active development.


Quick Start

from arabinlp import preprocess

text = """
السَّلَامُ عَلَيْكُمْ 😊

زوروا موقعنا:
https://example.com

#الذكاء_الاصطناعي
"""

print(preprocess(text))

Output

السلام عليكم زوروا موقعنا: الذكاء_الاصطناعي

API Overview

from arabinlp import (
    preprocess,
    normalize_arabic,
    tokenize,
    remove_stopwords,
    split_sentences,
    word_frequency,
    ngrams,
    character_ngrams,
    detect_language,
    text_statistics,
    extract_keywords,
    jaccard_similarity,
)

Examples

Tokenization

from arabinlp import tokenize

tokenize("السلام عليكم ورحمة الله")

Output

['السلام', 'عليكم', 'ورحمة', 'الله']

Stopword Removal

from arabinlp import remove_stopwords

remove_stopwords("أنا أحب تعلم الذكاء الاصطناعي")

Output

['أحب', 'تعلم', 'الذكاء', 'الاصطناعي']

Sentence Splitting

from arabinlp import split_sentences

split_sentences(
    "السلام عليكم. كيف حالك؟ أنا بخير!"
)

Output

[
    'السلام عليكم.',
    'كيف حالك؟',
    'أنا بخير!'
]

Word Frequency

from arabinlp import word_frequency

word_frequency(
    "الذكاء الذكاء الاصطناعي رائع"
)

Output

{
    'الذكاء': 2,
    'الاصطناعي': 1,
    'رائع': 1
}

Word N-Grams

from arabinlp import ngrams

ngrams(
    "السلام عليكم ورحمة الله",
    n=2
)

Output

[
    ('السلام', 'عليكم'),
    ('عليكم', 'ورحمة'),
    ('ورحمة', 'الله')
]

Character N-Grams

from arabinlp import character_ngrams

character_ngrams(
    "السلام",
    n=3
)

Output

[
    'الس',
    'لسل',
    'سلا',
    'لام'
]

Language Detection

from arabinlp import detect_language

detect_language("Hello مرحبا")

Output

mixed

Text Statistics

from arabinlp import text_statistics

text_statistics(
    "السلام عليكم. كيف حالك؟"
)

Output

{
    'characters': 24,
    'characters_without_spaces': 20,
    'words': 4,
    'unique_words': 4,
    'sentences': 2
}

Keyword Extraction

from arabinlp import extract_keywords

extract_keywords(
    "الذكاء الاصطناعي رائع. الذكاء يتطور بسرعة."
)

Output

[
    'الذكاء',
    'الاصطناعي',
    'رائع'
]

Text Similarity

from arabinlp import jaccard_similarity

score = jaccard_similarity(
    "أنا أحب الذكاء الاصطناعي",
    "الذكاء الاصطناعي رائع"
)

print(score)

Output

0.4

Project Structure

arabic-nlp-toolkit/

├── arabinlp/
├── tests/
├── .github/
├── README.md
├── LICENSE
├── pyproject.toml
└── requirements.txt

Running Tests

python -m pytest

Current Status

40 tests passed

Roadmap

Version 1.1

  • Arabic Light Stemmer
  • Root Extraction
  • TF-IDF
  • BM25 Ranking
  • Arabic Spell Checker
  • Named Entity Recognition (NER)
  • AraBERT Integration

Contributing

Contributions, bug reports, feature requests, and pull requests are always welcome.

If you have ideas for improving Arabic NLP support, feel free to open an Issue.


License

This project is licensed under the MIT License.


Author

Ibtihal Makki

AI Engineer • NLP Researcher • Generative AI

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arabinlp-2.0.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arabinlp-2.0.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file arabinlp-2.0.0.tar.gz.

File metadata

  • Download URL: arabinlp-2.0.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for arabinlp-2.0.0.tar.gz
Algorithm Hash digest
SHA256 340cdfe8ebe7c57321d80b882578981c3d980d7a5f20ee2f31a5f357f9afbab9
MD5 98ce62ccb3dba1a51fd9a2b5d0353ee5
BLAKE2b-256 02eb3c4450706b8725d1b845ed90bde975baff9951a4971a3b0afa09f80f421e

See more details on using hashes here.

Provenance

The following attestation bundles were made for arabinlp-2.0.0.tar.gz:

Publisher: tests.yml on IbtihalMakki/arabic-nlp-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file arabinlp-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: arabinlp-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for arabinlp-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df83c31ad778988d5f1ed5e406cd03689158952a88dacb4c9d1cae4bbbf38209
MD5 bca9fff38fb8fe8e46a2a1323a383117
BLAKE2b-256 a843771ee91e4275f79e432f50ad1f9ce865286b13b0a9eb572de9d778307bdc

See more details on using hashes here.

Provenance

The following attestation bundles were made for arabinlp-2.0.0-py3-none-any.whl:

Publisher: tests.yml on IbtihalMakki/arabic-nlp-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page