Metadata-Version: 2.4
Name: anbani
Version: 3.3.0
Summary: Georgian alphabet and language utilities for Natural Language Processing, script conversion and more.
Home-page: https://github.com/anbani/anbani.py
Author: George Gach
Author-email: georgegach@outlook.com
License: GPL
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: hjson
Provides-Extra: pdf
Requires-Dist: pymupdf; extra == "pdf"
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: summary

# AnbaniPy

[![tests](https://github.com/Anbani/anbani.py/actions/workflows/test.yml/badge.svg)](https://github.com/Anbani/anbani.py/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/Anbani/anbani.py/branch/main/graph/badge.svg)](https://codecov.io/gh/Anbani/anbani.py)
[![PyPI](https://img.shields.io/pypi/v/anbani)](https://pypi.org/project/anbani/)
[![Python versions](https://img.shields.io/pypi/pyversions/anbani)](https://pypi.org/project/anbani/)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](LICENSE)

Georgian Python toolkit for NLP, Transliteration and more. Partially based on [anbani.js](https://github.com/anbani/anbani.js).  

## Install

```bash
pip install anbani
```

Transliteration and NLP utilities need only `hjson`. PDF / e-book extraction
(`anbani.nlp.utils.ebook2text`) additionally requires PyMuPDF:

```bash
pip install anbani[pdf]
```

## Quickstart

Transliteration example:

```python
from anbani.core.converter import convert, interpret

interpret("გამარჯობა", "asomtavruli")

# 'ႢႠႫႠႰႿႭႡႠ'
```

Georgianisation example:

```python
from anbani.nlp.georgianisation import georgianise

georgianise("gamarjoba - rogor xar - rasa iqm - kaia kata - kai erti")

# 'გამარჯობა - როგორ ხარ - რასა იქმ - კაია კატა - კაი ერთი'
```


Convert ebooks with qwerty encoding to unicode Mkhedruli:

```python
from anbani.nlp.utils import ebook2text
from anbani.core.converter import classify_text
from anbani.core.converter import convert

text = ebook2text("/home/george/Dev/georgian-text-corpus/sources/mylibrary/raw/files/ჩარლზ დიკენსი - დევიდ კოპერფილდი.pdf")
print(text[:300])

print(classify_text(text))

print(convert(text, "qwerty", "mkhedruli")[:300])

# Carlz dikensi daviT koperfildi Tavi pirveli dabadeba me viqnebi gmiri Cemive sakuTari Tavgadasavlisa Tu sxva...

# latin

# ჩარლზ დიკენსი დავით კოპერფილდი თავი პირველი დაბადება მე ვიქნები გმირი ჩემივე საკუთარი თავგადასავლისა თუ სხვა...
```

Expand contractions:

```python
from anbani.nlp.contractions import expand_text

text = "ილია ჭავჭავაძე (დ. 8 ნოემბერი, 1837, სოფელი ყვარელი — გ. 12 სექტემბერი, 1907, წიწამური)"

print(text)
print(expand_text(text))

# ილია ჭავჭავაძე (დ. 8 ნოემბერი, 1837, სოფელი ყვარელი — გ. 12 სექტემბერი, 1907, წიწამური)
# ილია ჭავჭავაძე (დაბადება 8 ნოემბერი, 1837, სოფელი ყვარელი — გარდაცვალება 12 სექტემბერი, 1907, წიწამური)

```

Contract them back:

```python
from anbani.nlp.contractions import contract_text

print(contract_text("მასის ატომური ერთეული და ასე შემდეგ"))

# მ.ა.ე. და ა.შ.
```

## Text statistics & lorem

```python
from anbani import toolkit, lorem

toolkit.frequency("ანბანი")   # per-letter frequencies
toolkit.friedman(text)         # index of coincidence
lorem.sentences(12)            # fake Georgian prose
lorem.names(3)                 # fake full names
```

## Command line

Installing the package also installs an `anbani` command:

```bash
anbani interpret "gamarjoba"                      # -> ᲒᲐᲛᲐᲠᲯᲝᲑᲐ
anbani convert "ანბანი" -f mkhedruli -t asomtavruli
anbani georgianise "gamarjoba"
anbani expand "ვნახოთ ა. შ."
anbani lorem -w 8
```

## Interactive TUI

New in 3.1: a full-screen terminal UI. Launch it with `anbani tui` (or
`python -m anbani tui`). Zero extra dependencies — it is hand-rolled ANSI, and
imports stay lazy so `import anbani` and the plain CLI are unaffected.

```bash
anbani tui
```

![anbani tui — loading splash](docs/tui/splash.png)

Five tabs, switch with `1`–`5` or `tab` / `shift+tab`:

| Tab | What it does |
|-----|--------------|
| **Converter** | live transliteration; `m` toggles auto/manual, `f`/`o` pick source/target, `s` swaps |
| **Alphabet** | letter grid + detail card; `hjkl` to move, `c` cycles script, `a` toggles archaic, `enter` copies |
| **Lorem** | fake Georgian text; `k` kind, `+`/`-` amount, `g` generate |
| **NLP** | georgianise / latinise / expand / contract; `m` mode, `b` georgianise level (fast/balanced/accurate) |
| **Toolkit** | letter-frequency bars + Friedman index of coincidence |

**Converter** — live transliteration with script auto-detection:

![Converter tab](docs/tui/converter.png)

**Alphabet** — grid + per-letter detail across every Georgian script, IPA, braille, numeral:

![Alphabet tab](docs/tui/alphabet.png)

**NLP** — georgianise / latinise / expand / contract:

![NLP tab](docs/tui/nlp.png)

**Toolkit** — letter-frequency bars and the Friedman index of coincidence:

![Toolkit tab](docs/tui/toolkit.png)

Global keys: `?` help overlay · `i`/`enter` edit · `y` copy (via OSC 52) ·
`q` or `ctrl+c` quit. Minimum terminal size is 60×16.

Notes:
- No Georgian keyboard? Pick `from: qwerty` in the Converter (type Latin, get
  Georgian), or paste — bracketed paste is supported in edit mode.
- Copy uses OSC 52; some terminals block it, in which case the copy silently does
  nothing.
- Not supported on native Windows (needs a POSIX terminal); use WSL or the npm
  package there.

## Parity with anbani.js

anbani.py and [anbani.js](https://github.com/Anbani/anbani.js) share one
behavior contract, proved in CI by the byte-identical `spec/golden.json` that
both test suites run. As of 3.0 they are feature-equivalent; the only
intentional gaps are `ebook2text` (Python-only, needs PyMuPDF) and the
browser/UMD bundle (js-only).

## 3.0 — breaking changes

- `classify_text` returns `"unknown"` for undetectable / mixed-script text and
  now reports the four bicameral scripts; `interpret` raises on `"unknown"`.
- `convert` / `interpret` raise `ValueError` on an unsupported source or target
  (was an assertion, or a silent passthrough for targets).
- `georgianise` defaults to `mode="balanced"` (was `"accurate"`).

## To-Do

Feel free to fork this repo!  

- [x] Tokenizer
- [x] Transliteration 
- [x] Expand contractions
- [x] ebook2text converter
- [ ] Stemmer
- [ ] Lemmatizer
- [ ] Stopwords


## Resources used

- http://www.nplg.gov.ge/civil/statiebi/wignebi/qartul_enis_marTlwera/qartul_enis_marTlwera_tavi-12.htm
- http://www.nplg.gov.ge/civil/upload/Semokleba.htm
