pylelemmatize.print_err

pylelemmatize.print_err(txt='Hello', correct=None, confidence=None, file=None)[source]

Print text to stderr with color coding based on correctness and confidence.

Each character in the input text is colorized using ANSI escape codes. The foreground color is green for correct characters and red for incorrect ones. The background color interpolates from black (high confidence) to white (low confidence).

Parameters:
  • txt (str, optional) – The text to be printed. Defaults to “Hello”.

  • correct (list of bool, optional) – A list indicating whether each character in txt is correct (True) or incorrect (False). If None, all characters are assumed to be correct. Defaults to None.

  • confidence (list of float, optional) – A list of confidence values (between 0.0 and 1.0) for each character in txt. A value of 1.0 corresponds to high confidence (black background), and 0.0 corresponds to low confidence (white background). If None, all characters are assigned a confidence of 1.0. Defaults to None.

  • file (file-like object, optional) – A file-like object to which the output will be written. If None, the output is printed to the standard error. Defaults to None.

Return type:

str

Notes

This function uses ANSI escape codes for colorization, which may not be supported in all terminal environments.

Examples

>>> print_err("Test", correct=[True, False, True, True], confidence=[1.0, 0.5, 0.8, 1.0])
(Outputs colorized text to the terminal)