版权声明移除器 - 移除文本中跟版权声明相关的文本
输入列名 | 说明 |
|---|---|
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 ┆ │ # │ 你好 ┆ │ # ╰──────────────────────────────────────────────┴──────────────────────────────────────────────╯