Metadata-Version: 2.4
Name: urdu-nlp-tools
Version: 0.1.0
Summary: Normalization, preprocessing, transliteration, augmentation, metrics, and sentiment tools for Urdu and Roman Urdu NLP.
Author: Awais Akhtar
License-Expression: MIT
Project-URL: Homepage, https://github.com/awais-akhtar/urdu-nlp-tools
Project-URL: Repository, https://github.com/awais-akhtar/urdu-nlp-tools
Project-URL: Issues, https://github.com/awais-akhtar/urdu-nlp-tools/issues
Keywords: urdu,nlp,sentiment-analysis,roman-urdu,low-resource-nlp
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Natural Language :: Urdu
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Text Processing :: Linguistic
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: train
Requires-Dist: scikit-learn>=1.0; extra == "train"
Provides-Extra: dev
Requires-Dist: build>=1.0; extra == "dev"
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: twine>=5; extra == "dev"
Dynamic: license-file

# urdu-nlp-tools

Practical Python utilities for Urdu and Roman Urdu NLP: normalization, preprocessing, transliteration, lightweight augmentation, classification metrics, and sentiment analysis.

The default sentiment analyzer is dependency-free and works immediately with a small Urdu/Roman Urdu lexicon. For real research or production work, train it on your own labeled dataset with the optional scikit-learn extra.

## Install

```bash
pip install urdu-nlp-tools
```

For TF-IDF + LinearSVC training:

```bash
pip install "urdu-nlp-tools[train]"
```

## Quick Start

```python
from urdu_nlp import SentimentAnalyzer

model = SentimentAnalyzer()
print(model.predict("یہ فلم بہت اچھی تھی"))
# positive
```

Batch prediction:

```python
from urdu_nlp import SentimentAnalyzer

model = SentimentAnalyzer()
labels = model.predict([
    "یہ فلم بہت اچھی تھی",
    "movie bohat kharab thi",
])
print(labels)
```

## Train Your Own Sentiment Model

CSV files should include a text column and a label column. By default, the helpers expect `review` and `sentiment`.

```python
from urdu_nlp import SentimentAnalyzer, load_labeled_csv

records = load_labeled_csv("urdu_reviews.csv")
texts = [record.text for record in records]
labels = [record.label for record in records]

model = SentimentAnalyzer().fit(texts, labels)
model.save("urdu_sentiment.pkl")

loaded = SentimentAnalyzer.from_file("urdu_sentiment.pkl")
print(loaded.predict("یہ فلم بہت اچھی تھی"))
```

## Text Utilities

```python
from urdu_nlp import clean_text, normalize_urdu, roman_to_urdu, tokenize_words

print(normalize_urdu("كيا يہ ۱۲۳ ہے؟"))
print(clean_text("@user movie bohat achi thi!!!"))
print(tokenize_words("یہ فلم بہت اچھی تھی"))
print(roman_to_urdu("bohat achi film"))
```

## Metrics

```python
from urdu_nlp import accuracy_score, classification_report

y_true = ["positive", "negative", "neutral"]
y_pred = ["positive", "negative", "positive"]

print(accuracy_score(y_true, y_pred))
print(classification_report(y_true, y_pred))
```

## CLI

```bash
urdu-nlp-sentiment "یہ فلم بہت اچھی تھی"
urdu-nlp-sentiment --model urdu_sentiment.pkl "movie bohat kharab thi"
```

## Package Layout

```text
urdu_nlp/
├── normalize.py
├── sentiment.py
├── transliteration.py
├── augmentation.py
├── preprocessing.py
└── metrics.py
```

## Publishing

Publishing is automated with GitHub Actions. Add a repository secret named
`PYPI_API_TOKEN`, then create a GitHub release. The workflow runs the test
suite, builds the wheel and source distribution, and publishes both to PyPI.
It can also be started manually from the Actions tab.
