You need to enable JavaScript to run this app.
文档中心
AI 数据湖服务

AI 数据湖服务

复制全文
下载 pdf
文本清洗
Email 地址清理
复制全文
下载 pdf
Email 地址清理

算子介绍

描述

基于正则的 Email 地址清理算子。

核心功能

  • 多场景支持:内置通用匹配模式,同时允许注入自定义正则表达式。
  • 可控替换:可配置替换串,实现脱敏或占位填充。
  • 批量兼容:支持数组批量处理

Daft 调用

算子参数

输入

输入列名

说明

texts

字符串数组,每个元素为待处理的文本(允许 None)。

输出

字符串数组,包含替换/清洗后的文本,若处理失败则为 None。

参数

如参数没有默认值,则为必填参数

参数名称

类型

默认值

描述

pattern

str

r"[A-Za-z0-9.-+]+@[a-z0-9.-+]+.[a-z]+"

用于定位 email 的正则表达式。如果以 r'...' 或 r"..." 形式传入,算子会去除前缀。

repl

str

""

用于替换匹配到的 email 地址的字符串。

调用示例

下面的代码展示了如何使用 daft 运行 CleanEmail 算子来清洗文本中的 email 地址。

from __future__ import annotations

import os

import daft
from daft import col
from daft.las.functions.text.clean_email import CleanEmail
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": [
            "lihua@163.com This is a test content.",
            "This is a test content.",
            None,
        ]
    }

    repl = "****"
    ds = daft.from_pydict(samples)

    ds = ds.with_column(
        "cleaned_text",
        las_udf(
            CleanEmail,
            construct_args={"repl": repl},
        )(col("text")),
    )
    ds.show()

    # ╭────────────────────────────────┬──────────────────────────────╮
    # │ text                           ┆ cleaned_text                 │
    # │ ---                            ┆ ---                          │
    # │ Utf8                           ┆ Utf8                         │
    # ╞════════════════════════════════╪══════════════════════════════╡
    # │ lihua@163.com This is a test … ┆ **** This is a test content. │
    # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
    # │ This is a test content.        ┆ This is a test content.      │
    # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
    # │ None                           ┆ None                         │
    # ╰────────────────────────────────┴──────────────────────────────╯
最近更新时间:2026.03.30 14:23:37
这个页面对您有帮助吗?
有用
有用
无用
无用