diff --git a/Makefile b/Makefile index d5d07a8..8e94179 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ -.PHONY: sync install build publish clean help test lint check tox-run check-uv run demo update-dev-requirements check-dev-requirements +.DEFAULT_GOAL := help + +.PHONY: sync install build publish clean help test lint check tox-run check-uv run demo-transliterate demo-syllabify update-dev-requirements check-dev-requirements add-dep check-uv: @if ! command -v uv &> /dev/null; then \ @@ -15,16 +17,24 @@ help: ## Muestra esta ayuda sync: check-uv ## Sincroniza dependencias y crea entorno virtual con uv @echo "🔄 Sincronizando dependencias con uv..." - @uv sync --extra dev - @echo "📝 Actualizando dev-requirements.txt..." - @$(MAKE) update-dev-requirements --no-print-directory + @uv sync @echo "✅ Entorno sincronizado" +sync-dev: check-uv ## Sincroniza dependencias de desarrollo + @echo "🔄 Sincronizando dependencias con uv..." + @uv sync --extra dev + @echo "✅ Entorno dev sincronizado" + install: check-uv sync ## Instala el módulo andaluh en modo desarrollo @echo "⚙️ Instalando módulo andaluh en modo desarrollo..." @uv pip install -e . @echo "✅ Módulo andaluh instalado en modo desarrollo" +install-editable: check-uv sync ## Instala el módulo andaluh en modo desarrollo + @echo "⚙️ Instalando módulo andaluh en modo desarrollo..." + @uv pip install -e . + @echo "✅ Módulo andaluh instalado en modo desarrollo" + build: check-uv ## Construye el paquete @echo "Construyendo paquete..." @if [ -d "dist" ]; then \ @@ -47,7 +57,7 @@ clean: check-uv ## Limpia archivos generados @find . -type f -name "*.pyc" -delete 2>/dev/null || true @echo "✅ Limpieza completada" -test: check-uv sync ## Ejecuta los tests +test: check-uv sync-dev ## Ejecuta los tests @echo "🧪 Ejecutando tests..." @uv run pytest --cov=andaluh tests/ @echo "✅ Tests completados" @@ -73,12 +83,26 @@ run: check-uv sync ## Ejecuta el CLI andaluh (uso: make run TEXT="tu texto aquí uv run python bin/andaluh "$(TEXT)" $(ARGS); \ fi -demo: check-uv sync ## Ejecuta una demostración del CLI andaluh - @echo "🎯 Demostración de andaluh:" +demo-transliterate: check-uv sync ## Ejecuta una demostración del CLI andaluh + @echo "🎯 Demostración de andaluh (transliteración):" @echo "Texto original: 'Hola, ¿cómo estás? ¡Qué tal el día!'" @echo "Transliteración:" @uv run python bin/andaluh "Hola, ¿cómo estás? ¡Qué tal el día!" +demo-syllabify: check-uv sync ## Ejecuta una demostración del CLI syllabify + @echo "🎯 Demostración de syllabify (silabificación):" + @echo "Palabra original: 'murçiélago'" + @echo "Silabificación:" + @uv run python bin/syllabify --word "murçiélago" + @echo "" + @echo "Palabra original: 'andalûh'" + @echo "Silabificación:" + @uv run python bin/syllabify --word "andalûh" + @echo "" + @echo "Palabra original: 'êppañôh'" + @echo "Silabificación:" + @uv run python bin/syllabify --word "êppañôh" + update-dev-requirements: check-uv ## Actualiza dev-requirements.txt desde pyproject.toml @echo "📝 Actualizando dev-requirements.txt desde pyproject.toml..." @uv export --extra dev --format requirements-txt --no-hashes > dev-requirements.txt.tmp @@ -100,3 +124,21 @@ check-dev-requirements: check-uv ## Verifica si dev-requirements.txt está sincr echo "✅ dev-requirements.txt está sincronizado"; \ rm -f dev-requirements.txt.expected; \ fi + +add-dep: check-uv ## Añade dependencias a pyproject.toml (uso: make add-dep DEPS="paquete1 paquete2" o make add-dep DEPS="paquete1 paquete2" DEV=true) + @if [ -z "$(DEPS)" ]; then \ + echo "❌ Debes especificar al menos una dependencia"; \ + echo "📖 Uso: make add-dep DEPS=\"paquete1 paquete2\""; \ + echo "📖 Para dependencias de desarrollo: make add-dep DEPS=\"paquete1 paquete2\" DEV=true"; \ + exit 1; \ + fi + @if [ "$(DEV)" = "true" ]; then \ + echo "📦 Añadiendo dependencias de desarrollo: $(DEPS)"; \ + uv add --dev $(DEPS); \ + else \ + echo "📦 Añadiendo dependencias: $(DEPS)"; \ + uv add $(DEPS); \ + fi + @echo "📝 Actualizando dev-requirements.txt..." + @$(MAKE) update-dev-requirements --no-print-directory + @echo "✅ Dependencias añadidas y dev-requirements.txt actualizado" diff --git a/README.md b/README.md index 82e8274..ca7548c 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ This package introduces transliteration functions to convert *español* (spanish ### Command line tool -Use from the command line with the **andaluh** tool: +Use EPA transliterator from the command line with the **andaluh** tool: ```bash $ andaluh -h @@ -56,6 +56,38 @@ $ andaluh -e z -j "El veloz murciélago hindú comía feliz cardillo y kiwi. La Er belôh murziélago indú comía felîh cardiyo y kiwi. La zigueña tocaba er zâzzofón detrâh der palenque de paja. ``` +You also can transliterate files using the `-i` option: + +```bash +$ andaluh -i input.txt > output.txt +``` + +### EPA Syllabifier + +The package includes a **syllabify** tool for syllabifying words using EPA rules: + +```bash +$ syllabify -h +usage: syllabify [-h] [--word WORD] [--file FILE] + +Syllabify a word + +optional arguments: + -h, --help show this help message and exit + --word WORD, -w WORD The EPA word to syllabify + --file FILE, -f FILE The file to syllabify + +# Syllabify a single word +$ syllabify --word "murciélago" +mur-cié-la-go + +$ syllabify -w "andaluz" +an-da-luz + +# Syllabify an entire file +$ syllabify --file input.txt +``` + ### Development usage If you're working with the source code, you can use the convenient make commands: diff --git a/bin/syllabify b/bin/syllabify new file mode 100644 index 0000000..b0b414e --- /dev/null +++ b/bin/syllabify @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# vim: ts=4 + +import argparse +import logging +import os +import sys +from epa_syllabifier import syllabify + +logging.basicConfig(level=logging.INFO) + +def syllabify_file(file_path): + output = "" + with open(file_path, "r", encoding="utf-8") as f: + for line in f: + # check if line is empty + if not line.strip(): + output += "\n\n" + continue + for word in line.split(): + stripped_word = word.strip() + if stripped_word: + try: + output += '-'.join(syllabify(stripped_word)) + " " + except Exception as e: + logging.error(f"Error syllabifying {stripped_word}: {e}") + output += stripped_word + " " + continue + return output + +def main(): + parser = argparse.ArgumentParser(description="Syllabify a word") + parser.add_argument("--word", "-w", type=str, help="The EPA word to syllabify") + parser.add_argument("--file", "-f", type=str, help="The file to syllabify") + args = parser.parse_args() + if args.word: + print('-'.join(syllabify(args.word))) + elif args.file: + if not os.path.exists(args.file): + logging.error(f"File {args.file} does not exist") + sys.exit(1) + result = syllabify_file(args.file) + print("=" * 80) + print(result) + else: + parser.print_help() + sys.exit(1) + +if __name__ == "__main__": + main() diff --git a/dev-requirements.txt b/dev-requirements.txt index b5e2d82..2cf044e 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -14,6 +14,8 @@ coverage==7.9.1 # pytest-cov distlib==0.3.9 # via virtualenv +epa-syllabifier==0.3.0 + # via andaluh exceptiongroup==1.3.0 ; python_full_version < '3.11' # via pytest filelock==3.18.0 diff --git a/pyproject.toml b/pyproject.toml index ce9cfdf..f42371c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,6 +24,9 @@ classifiers = [ "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", ] +dependencies = [ + "epa-syllabifier~=0.3.0", +] [project.urls] Homepage = "https://andaluh.es" @@ -43,7 +46,10 @@ dev = [ [tool.setuptools] packages = ["andaluh"] -script-files = ["bin/andaluh"] +script-files = [ + "bin/andaluh", + "bin/syllabify" +] [tool.setuptools.package-dir] "" = "." @@ -108,4 +114,4 @@ version_files = [ "pyproject.toml:version" ] tag_format = "v$version" -update_changelog_on_bump = true \ No newline at end of file +update_changelog_on_bump = true