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%
Create a Python utility that analyzes bidirectional text to extract information about the base text direction and character-level details.
Your solution should implement a function that takes text as input and returns structured information about:
Base Direction Detection: Determine whether the text is primarily left-to-right (LTR) or right-to-left (RTL)
Character-Level Information: For each character in the text, extract:
The function should return a dictionary with keys: base_level, base_dir, and characters (a list of character info dictionaries)
"Hello"@test
"שלום" (Hebrew for "hello")@test
"Hello שלום"@test
@generates
def analyze_bidi_text(text: str) -> dict:
"""
Analyzes bidirectional text and returns base direction and character-level information.
Args:
text: A string to analyze (can contain LTR and RTL text)
Returns:
A dictionary containing:
- 'base_level': int (0 for LTR, 1 for RTL)
- 'base_dir': str ('L' or 'R')
- 'characters': list of dicts, each with keys: 'char', 'level', 'type'
"""
passProvides bidirectional text processing capabilities.