You need to enable JavaScript to run this app.
Lake AI Service

Lake AI Service

Copy page
Download PDF
Text processing
Whitespace character normalizer
Copy page
Download PDF
Whitespace character normalizer

Operator introduction

Description

Whitespace character normalizer - replaces different types of whitespace characters in text with standard spaces

Key features

  • Whitespace character recognition: Automatically identifies various Unicode whitespace characters
  • Normalization processing: Replaces all whitespace characters with standard spaces

Application scenarios

  • Text preprocessing
  • Data cleaning and normalization
  • Format unification
  • Text standardization

Technical features

  • Supports multiple types of whitespace characters: spaces, tabs, line breaks, full-width spaces, and more
  • Intelligent processing: Retains text content and only replaces whitespace characters
  • Leading and trailing cleanup: Automatically removes whitespace characters at the beginning and end of text
  • Preserves structure: Does not alter the basic structure or content of the text

Daft invocation

Operator parameters

Input

Input column name

Note

texts

The text column to be processed; element type must be string

Output

Normalized text column

Examples

The following code demonstrates how to use daft to run the operator to normalize whitespace characters in text.

from __future__ import annotations

import os

import daft
from daft import col
from daft.las.functions.text.whitespace_normalizer import WhitespaceNormalizer
from daft.las.functions.udf import las_udf

if __name__ == "__main__":

    if os.getenv("DAFT_RUNNER", "native") == "ray":
        import logging

        import ray

        def configure_logging():
            logging.basicConfig(
                level=logging.INFO,
                format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
                datefmt="%Y-%m-%d %H:%M:%S.%s".format(),
            )
            logging.getLogger("tracing.span").setLevel(logging.WARNING)
            logging.getLogger("daft_io.stats").setLevel(logging.WARNING)
            logging.getLogger("DaftStatisticsManager").setLevel(logging.WARNING)
            logging.getLogger("DaftFlotillaScheduler").setLevel(logging.WARNING)
            logging.getLogger("DaftFlotillaDispatcher").setLevel(logging.WARNING)

        ray.init(dashboard_host="0.0.0.0", runtime_env={"worker_process_setup_hook": configure_logging})
        daft.set_runner_ray()
    daft.set_execution_config(actor_udf_ready_timeout=600)
    daft.set_execution_config(min_cpu_per_task=0)

    samples = {
        "text": [
            "Hello\u2000World\u2001Test",
            "中文\u2002文本\u2003测试",
            "English\u2004中文\u2005Mixed",
            "Multiple\u2006\u2007\u2008Spaces",
        ]
    }

    ds = daft.from_pydict(samples)
    ds = ds.with_column(
        "normalized_text",
        las_udf(WhitespaceNormalizer)(col("text")),
    )

    ds.show()
    # ╭──────────────────────────────────────────────┬──────────────────────────────────────────────╮
    # │ text                                         ┆ normalized_text                             │
    # │ ---                                          ┆ ---                                          │
    # │ Utf8                                         ┆ Utf8                                         │
    # ╞══════════════════════════════════════════════╪══════════════════════════════════════════════╡
    # │ Hello World Test                             ┆ Hello World Test                             │
    # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
    # │ 中文 文本 测试                                ┆ 中文 文本 测试                               │
    # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
    # │ English 中文 Mixed                            ┆ English 中文 Mixed                            │
    # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
    # │ Multiple   Spaces                            ┆ Multiple Spaces                              │
    # ╰──────────────────────────────────────────────┴──────────────────────────────────────────────╯
Last updated: 2026.05.12 19:06:32