Advanced Indonesian Natural Language Processing Library
Project description
nahiarhdNLP โ Indonesian NLP utilities
Lightweight utilities for Indonesian text preprocessing: cleaning, normalization, emoji conversion, spell correction, stemming, stopwords and a configurable Pipeline.
Install
pip install nahiarhdNLP
Quick usage
Import the pipeline and helpers:
from nahiarhdNLP.preprocessing import Pipeline, pipeline
from nahiarhdNLP.preprocessing import remove_html, remove_mentions, to_lowercase
- Pipeline with callables (function mode):
pipe = Pipeline(remove_html, remove_mentions, to_lowercase)
result = pipe.process("Hello <b>WORLD</b> @user https://example.com")
# -> HTML removed, mentions cleaned, lowered
- Pipeline with config dictionary (config mode):
config = {"clean_html": True, "clean_mentions": True, "remove_urls": True}
pipe = Pipeline(config)
result = pipe.process("Hello <b>World</b> @User https://EXAMPLE.com")
- Helper
pipeline()for one-shot processing with a config:
result = pipeline("Gw lg browsing https://google.com", {"remove_urls": True, "to_lowercase": True})
Running tests (local)
Project contains unit tests under nahiarhdNLP/tests. To run them locally in the project virtualenv:
# from project root
# ensure virtualenv is active, or install pytest into your environment
python3 -m pip install -U "pytest" "pytest-cov"
python3 -m pytest -q
If you use the project .venv, run:
.venv/bin/python3 -m pip install -U pytest pytest-cov
.venv/bin/python3 -m pytest -q
Notes & troubleshooting
- The package exposes two pipeline implementations:
nahiarhdNLP.preprocessing.main.Pipeline(config-only implementation) โ useful for config-driven workflows.nahiarhdNLP.preprocessing.utils.Pipeline(function-or-config implementation) โ supports both passing callables and config dicts.
- If you see import-time errors, ensure the package root is on
PYTHONPATHor install the package in editable mode:
pip install -e .
If you want more examples (tokenization, stemmer, emoji conversion, or spell-correction examples), tell me which features you want documented and I'll add them to this README.
More examples
Stemmer
from nahiarhdNLP.preprocessing import Stemmer
try:
stemmer = Stemmer()
text = "bermain-main dengan senang"
stemmed = stemmer.stem(text)
print(stemmed)
# Expected: "main main dengan senang"
except Exception as e:
print("Stemmer error:", e)
print("Install Sastrawi if missing: pip install Sastrawi")
EmojiConverter
from nahiarhdNLP.preprocessing import EmojiConverter
emoji = EmojiConverter()
emoji._load_data()
print(emoji.emoji_to_text_convert("๐๐"))
# e.g. -> "wajah_gembira wajah_menyeringai"
print(emoji.text_to_emoji_convert("wajah_gembira"))
# e.g. -> "๐"
SpellCorrector (slang + spelling)
from nahiarhdNLP.preprocessing import SpellCorrector
spell = SpellCorrector()
print(spell.correct_word("sya"))
# e.g. -> "saya"
print(spell.correct_sentence("gw lg di rmh"))
# e.g. -> "gue lagi di rumah"
Linguistic processing
remove_stopwords, stem_text, tokenize
Word-preserving cleaning
enable_html_cleaning, enable_url_cleaning, enable_mention_cleaning, enable_hashtag_cleaning, enable_email_cleaning, enable_phone_cleaning, enable_currency_cleaning
Replacement helpers (new)
replace_email, replace_link, replace_user
### 8. ๐๏ธ Preprocess Function (Backward Compatibility)
```python
from nahiarhdNLP.preprocessing import preprocess
# Preprocessing dengan parameter eksplisit
result = preprocess(
"Halooo @user!!! 123 ๐",
remove_emoji=True,
remove_mentions=True,
remove_numbers=True,
remove_punctuation=True,
replace_repeated_chars=True,
to_lowercase=True,
replace_spell_corrector=False,
)
print(result)
# Output: "haloo !! 123"
9. ๐ Dataset Loader
from nahiarhdNLP.datasets import DatasetLoader
loader = DatasetLoader()
# Load stopwords dari CSV lokal
stopwords = loader.load_stopwords_dataset()
print(f"Jumlah stopwords: {len(stopwords)}")
# Load slang dictionary dari CSV lokal
slang_dict = loader.load_slang_dataset()
print(f"Jumlah slang: {len(slang_dict)}")
# Load emoji dictionary dari CSV lokal
emoji_dict = loader.load_emoji_dataset()
print(f"Jumlah emoji: {len(emoji_dict)}")
# Load wordlist dari JSON lokal
wordlist = loader.load_wordlist_dataset()
print(f"Jumlah kata: {len(wordlist)}")
Catatan: Semua dataset (stopword, slang, emoji, wordlist) di-load langsung dari file CSV/JSON di folder
nahiarhdNLP/datasets/. Tidak ada proses download dari external source.
๐ฅ Demo Script
Untuk melihat semua fitur library bekerja:
python -m nahiarhdNLP.demo
Demo ini menunjukkan:
- โ Semua fungsi individual utility
- โ Penggunaan class-based approach
- โ Pipeline system (functions & config)
- โ Advanced pipeline features
- โ Handling error dan troubleshooting
๐จ Error Handling
try:
from nahiarhdNLP.preprocessing import SpellCorrector
spell = SpellCorrector()
result = spell.correct_sentence("test")
except ImportError:
print("Package nahiarhdNLP belum terinstall")
print("Install dengan: pip install nahiarhdNLP")
except Exception as e:
print(f"Error: {e}")
๐ก Tips Penggunaan
- Untuk preprocessing simple: Gunakan
Pipeline(function1, function2, ...)- langsung pass functions! - Untuk kontrol detail: Gunakan
Pipeline(config_dict)ataupreprocess()dengan parameter boolean - Untuk kontrol penuh: Gunakan kelas individual (
TextCleaner,SpellCorrector, dll) - Untuk spell correction + slang: Gunakan
SpellCorrectoryang menggabungkan kedua fitur - Untuk menghapus emoji: Gunakan
remove_emoji()atau setremove_emoji=Truedi Pipeline/preprocess - Untuk stemming: Install Sastrawi terlebih dahulu:
pip install Sastrawi - Untuk load dataset: Gunakan
DatasetLoaderdarinahiarhdNLP.datasets - Untuk inisialisasi kelas: Panggil
_load_data()untuk kelas yang memerlukan dataset - Pipeline design:
Pipeline(remove_url, to_lowercase)lebih jelas daripada config dictionary - Function chaining: Pipeline bisa dipanggil seperti function dengan
pipeline("text") - Demo testing: Jalankan
python -m nahiarhdNLP.demountuk melihat semua fitur bekerja
โก Performance & Dataset
nahiarhdNLP menggunakan dataset lokal yang sudah disediakan:
- Stopwords: File
stop_word.csv(788 kata) - Slang Dictionary: File
slang.csv(15,675 pasangan) - Emoji Mapping: File
emoji.csv(3,530 emoji) - Wordlist: File
wordlist.json(kamus kata Indonesia) - KBBI Dictionary: File
kata_dasar_kbbi.csv(28,527 kata) - Kamus Tambahan: File
kamus.txt(30,871 kata)
Semua dataset tersimpan di folder nahiarhdNLP/datasets/ dan diakses melalui DatasetLoader.
๐ฆ Dependencies
Package ini membutuhkan:
pandas- untuk load dan proses dataset CSV/JSONSastrawi- untuk stemming (opsional)rich- untuk output formatting di demo (opsional)
๐ง Struktur Modul
nahiarhdNLP/
โโโ datasets/
โ โโโ loaders.py # DatasetLoader class
โ โโโ emoji.csv # Dataset emoji (3,530 entries)
โ โโโ slang.csv # Dataset slang (15,675 entries)
โ โโโ stop_word.csv # Dataset stopwords (788 entries)
โ โโโ wordlist.json # Dataset wordlist
โ โโโ kata_dasar_kbbi.csv # Dataset KBBI (28,527 entries)
โ โโโ kamus.txt # Dataset kamus tambahan (30,871 entries)
โโโ preprocessing/
โ โโโ cleaning/
โ โ โโโ text_cleaner.py # TextCleaner class (complete removal)
โ โ โโโ text_cleaner_word.py # Word-preserving TextCleaner class
โ โโโ linguistic/
โ โ โโโ stemmer.py # Stemmer class
โ โ โโโ stopwords.py # StopwordRemover class
โ โโโ normalization/
โ โ โโโ emoji.py # EmojiConverter class
โ โ โโโ spell_corrector.py # SpellCorrector class
โ โโโ tokenization/
โ โ โโโ tokenizer.py # Tokenizer class
โ โโโ utils.py # Fungsi utility individual & Pipeline
โโโ demo.py # File demo penggunaan
๐ Changelog Versi 1.4.0
- ๐ [FITUR BARU] Menambahkan
remove_emoji()function untuk menghapus emoji dari teks - โ
[BARU] TextCleaner sekarang memiliki method
clean_emoji()untuk menghapus emoji - โ [BARU] Pipeline mendukung "remove_emoji" config untuk emoji removal
- โ
[BARU] Preprocess function mendukung parameter
remove_emoji=True/False - โ [PERBAIKAN] Demo script diperbarui dengan contoh emoji removal
- โ [PERBAIKAN] Dokumentasi lengkap untuk fitur emoji removal
- ๐ [MAJOR] Pipeline sekarang mendukung 2 mode: Functions dan Config Dictionary
- โ
[BARU] Pipeline dengan functions:
Pipeline(remove_url, to_lowercase) - โ
[BARU] Pipeline dengan config:
Pipeline({"remove_url": True, "to_lowercase": True}) - โ
[BARU] Advanced pipeline features:
get_config(),get_enabled_steps(),update_config() - โ
[PERBAIKAN] Fungsi
pipeline(text, config)sekarang bekerja dengan config dictionary - โ
[PERBAIKAN] TextCleaner sekarang punya method
clean_html()yang benar - โ [PERBAIKAN] SpellCorrector demo diperbaiki dengan proper instantiation
- โ [PERBAIKAN] Demo script berjalan sempurna tanpa error
- โ [PERBAIKAN] Dokumentasi yang akurat dan sesuai implementasi
- โ
[PERBAIKAN] Function names yang konsisten:
replace_spell_corrector,replace_repeated_chars - โ
[PERBAIKAN] Backward compatibility dengan
preprocess()function - โ
Menggabungkan spell correction dan slang normalization dalam
SpellCorrector - โ Semua dataset menggunakan file lokal (CSV/JSON)
- โ Struktur yang lebih terorganisir dengan pemisahan kelas dan fungsi
- โ
Penambahan
DatasetLoaderuntuk manajemen dataset terpusat - โ Dataset lengkap dengan 6 file berbeda (emoji, slang, stopwords, wordlist, KBBI, kamus)
๐ Changelog Versi 1.4.10 (Latest)
- ๐ [FITUR BARU] Enable Functions untuk pembersihan dengan mempertahankan konten
- โ
[BARU]
enable_html_cleaning()- Membersihkan HTML tags - โ
[BARU]
enable_url_cleaning()- Membersihkan URL - โ
[BARU]
enable_mention_cleaning()- Membersihkan mentions (@user) - โ
[BARU]
enable_hashtag_cleaning()- Membersihkan hashtags (#tag) - โ
[BARU]
enable_email_cleaning()- Membersihkan email - โ
[BARU]
enable_phone_cleaning()- Membersihkan nomor telepon - โ
[BARU]
enable_currency_cleaning()- Membersihkan mata uang - โ [BARU] Demo script diperbarui dengan contoh lengkap untuk semua fitur baru
- โ [BARU] Dokumentasi README lengkap dengan contoh penggunaan fitur baru
- โ [PERBAIKAN] Integrasi penuh dengan sistem Pipeline dan preprocess functions
- โ [PERBAIKAN] Backward compatibility dengan semua fitur existing
- โ [PERBAIKAN] Package structure yang konsisten dan terorganisir
๐ Troubleshooting
Error saat import dataset:
# Pastikan memanggil _load_data() untuk kelas yang memerlukan dataset
stopword = StopwordRemover()
stopword._load_data() # Penting!
Error Sastrawi tidak ditemukan:
pip install Sastrawi
Error pandas tidak ditemukan:
pip install pandas
Testing semua fitur:
python -m nahiarhdNLP.demo
๐ License
MIT License
๐จโ๐ป Author
Raihan Hidayatullah Djunaedi raihanhd.dev@gmail.com
Untuk contoh penggunaan lengkap, lihat file demo.py di repository ini atau jalankan python -m nahiarhdNLP.demo.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nahiarhdnlp-1.4.10.tar.gz.
File metadata
- Download URL: nahiarhdnlp-1.4.10.tar.gz
- Upload date:
- Size: 782.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d01f5543fb325eea2b3b17556aeb777154715068336bc97136e93ecd7d32f449
|
|
| MD5 |
ff6e155aba35f1a6ecd1ae0bb63caf85
|
|
| BLAKE2b-256 |
b892b3679d42402c8a203dbdbcd803c3a287f2328c5cd6cbb4f6565d08d3500b
|
File details
Details for the file nahiarhdnlp-1.4.10-py3-none-any.whl.
File metadata
- Download URL: nahiarhdnlp-1.4.10-py3-none-any.whl
- Upload date:
- Size: 786.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0e3b20456db09b955fc3efa943258631758028bba56c03e5a97f50a303cc600
|
|
| MD5 |
c95ce0c425097652dbc76e981054f44c
|
|
| BLAKE2b-256 |
787f6f56dc0522ae7555dc6783cefa2a7c73fe6fd960e9701484772549f81948
|