testsAndMisc-archive/python_pkg/word_frequency/__init__.py

32 lines
1.1 KiB
Python
Raw Permalink Normal View History

2025-12-27 17:22:17 +01:00
"""Word frequency analyzer package.
This package provides tools for:
1. Analyzing word frequency in text (analyzer module)
2. Finding text excerpts where target words are most prevalent (excerpt_finder module)
2025-12-28 15:55:43 +01:00
3. Combining analysis with excerpts for language learning (learning_pipe module)
4. Offline translation between languages (translator module)
2025-12-27 17:22:17 +01:00
Example usage:
from python_pkg.word_frequency.analyzer import analyze_text, analyze_and_format
from python_pkg.word_frequency.excerpt_finder import find_best_excerpt
2025-12-28 15:55:43 +01:00
from python_pkg.word_frequency.translator import translate_words
2025-12-27 17:22:17 +01:00
# Analyze word frequency
counts = analyze_text("hello world hello")
print(counts["hello"]) # 2
# Find excerpt with target words
results = find_best_excerpt(
"they went somewhere he and she and the guy",
target_words=["and", "the"],
excerpt_length=3,
)
2025-12-28 15:55:43 +01:00
# Translate words (requires argostranslate installed)
translations = translate_words(["hello", "world"], "en", "es")
```
2025-12-27 17:22:17 +01:00
print(results[0].excerpt) # "and she and" or similar
"""
from __future__ import annotations