You need to enable JavaScript to run this app.
AI 数据湖服务

AI 数据湖服务

复制全文
文本处理
版权声明移除
复制全文
版权声明移除

算子介绍

描述

版权声明移除器 - 移除文本中跟版权声明相关的文本

核心功能

  • 版权声明检测:自动识别代码中的版权声明注释
  • 智能清理:根据版权声明特征进行精确的内容移除
  • 多格式支持:支持块注释和行注释格式

应用场景

  • 代码版权声明清理
  • 文本预处理和标准化
  • 代码质量检查和优化

技术特性

  • 支持两种版权声明格式:
    • 块注释格式:/* ... */ 中包含copyright关键词的注释块
    • 行注释格式:以//、#、--开头的行注释

Daft 调用

算子参数

输入

输入列名

说明

texts

待处理的文本列,要求元素类型为字符串

输出

清理后的文本列,移除版权声明相关内容

调用示例

下面的代码展示了如何使用 daft 运行算子移除文本中的版权声明内容。

from __future__ import annotations

import os

import daft
from daft import col
from daft.las.functions.text.copyright_cleaner import CopyrightCleaner
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.context.set_runner_ray()
    daft.set_execution_config(actor_udf_ready_timeout=600)
    daft.set_execution_config(min_cpu_per_task=0)

    samples = {
        "text": [
            "/* \n * Copyright (c) 2023 Jane Smith\n * 本代码依据 Apache License 2.0 授权,详见随附的 LICENSE 文件。\n */ 你好",
            "# 版权 (c) 2023 Jane Smith\n# 本代码依据 Apache License 2.0 授权,详见随附的 LICENSE 文件。\n 你好",
        ]
    }

    ds = daft.from_pydict(samples)
    ds = ds.with_column(
        "cleaned_text",
        las_udf(
            CopyrightCleaner,
            construct_args={},
        )(col("text")),
    )

    ds.show()
    # ╭──────────────────────────────────────────────┬──────────────────────────────────────────────╮
    # │ text                                         ┆ cleaned_text                                │
    # │ ---                                          ┆ ---                                          │
    # │ Utf8                                         ┆ Utf8                                         │
    # ╞══════════════════════════════════════════════╪══════════════════════════════════════════════╡
    # │ /* \n * Copyright (c) 2023 Jane Smith\n * 本    ┆  你好                                        │
    # │ 代码依据 Apache License 2.0 授权,详见随附的     ┆                                             │
    # │ LICENSE 文件。\n */ 你好                        ┆                                             │
    # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
    # │ # 版权 (c) 2023 Jane Smith\n# 本代码依据 Apache    ┆  你好                                        │
    # │ License 2.0 授权,详见随附的 LICENSE 文件。\n     ┆                                             │
    # │ 你好                                          ┆                                             │
    # ╰──────────────────────────────────────────────┴──────────────────────────────────────────────╯
最近更新时间:2026.01.08 19:14:24
这个页面对您有帮助吗?
有用
有用
无用
无用