or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/python-bidi@0.6.x
tile.json

tessl/pypi-python-bidi

tessl install tessl/pypi-python-bidi@0.6.0

Python 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%

task.mdevals/scenario-7/

BiDi Text Analyzer

Create a Python utility that analyzes bidirectional text to extract information about the base text direction and character-level details.

Requirements

Your solution should implement a function that takes text as input and returns structured information about:

  1. Base Direction Detection: Determine whether the text is primarily left-to-right (LTR) or right-to-left (RTL)

    • Return base level as an integer (0 for LTR, 1 for RTL)
    • Return base direction as a string ('L' or 'R')
  2. Character-Level Information: For each character in the text, extract:

    • The character itself
    • Its bidirectional type (e.g., 'L', 'R', 'EN', 'AN', etc.)
    • Its embedding level

The function should return a dictionary with keys: base_level, base_dir, and characters (a list of character info dictionaries)

Test Cases

Test 1: Simple English Text { @test }

  • Input: "Hello"
  • Expected base level: 0 (LTR)
  • Expected base direction: 'L'
  • All characters should have type 'L' and be at level 0

@test

Test 2: Simple Hebrew Text { @test }

  • Input: "שלום" (Hebrew for "hello")
  • Expected base level: 1 (RTL)
  • Expected base direction: 'R'
  • All characters should have type 'R' and be at level 1

@test

Test 3: Mixed English and Hebrew { @test }

  • Input: "Hello שלום"
  • Should detect base direction based on first strong character
  • Characters should have their correct bidirectional types
  • Latin characters should have type 'L' and Hebrew characters should have type 'R'

@test

Implementation

@generates

API

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'
    """
    pass

Dependencies { .dependencies }

python-bidi { .dependency }

Provides bidirectional text processing capabilities.