tessl install tessl/pypi-python-bidi@0.6.0Python Bidi layout wrapping the Rust crate unicode-bidi
Agent Success
Agent success rate when using this tile
93%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.09x
Baseline
Agent success rate without this tile
85%
Build a text direction analyzer that processes multilingual text snippets and determines their base paragraph direction. The analyzer should be able to identify whether a given text is primarily left-to-right (LTR) or right-to-left (RTL).
Implement a module that provides the following functionality:
Create a function analyze_text_direction(text: str) -> str that:
"LTR" if the text has a left-to-right base direction"RTL" if the text has a right-to-left base direction"LTR" as the defaultCreate a function analyze_batch(texts: list[str]) -> dict[str, int] that:
{"LTR": <count>, "RTL": <count>}Create a function classify_by_direction(texts: list[str]) -> dict[str, list[str]] that:
"LTR" and "RTL"Your implementation should pass these test cases:
# test_direction_analyzer.py
def test_ltr_text():
"""Test detection of left-to-right text"""
assert analyze_text_direction("Hello World") == "LTR"
assert analyze_text_direction("123 numbers") == "LTR"
def test_rtl_text():
"""Test detection of right-to-left text"""
assert analyze_text_direction("שלום") == "RTL"
assert analyze_text_direction("مرحبا") == "RTL"
def test_mixed_text():
"""Test mixed text - first strong character determines direction"""
assert analyze_text_direction("Hello שלום") == "LTR"
assert analyze_text_direction("שלום Hello") == "RTL"
def test_batch_analysis():
"""Test batch counting"""
texts = ["Hello", "שלום", "World", "مرحبا"]
result = analyze_batch(texts)
assert result["LTR"] == 2
assert result["RTL"] == 2
def test_classify_by_direction():
"""Test classification grouping"""
texts = ["Hello", "שלום", "World", "مرحبا"]
result = classify_by_direction(texts)
assert result["LTR"] == ["Hello", "World"]
assert result["RTL"] == ["שלום", "مرحبا"]Provides bidirectional text processing support.