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

AI 数据湖服务

复制全文
文本处理
URL占比计算器
复制全文
URL占比计算器

算子介绍

描述

URL占比计算器 - 基于URL字符占比的文本特征提取

核心功能

  • URL占比计算:精确统计URL字符在文本中的占比
  • 多协议支持:支持HTTP、HTTPS等多种URL协议
  • 智能识别:使用正则表达式精确识别URL格式

应用场景

  • 文本质量评估
  • 数据清洗和预处理
  • 文本分类特征提取
  • 内容安全检测
  • 网页内容分析

技术特性

  • URL字符占比:URL字符占总字符数的比例
  • 支持多种URL格式,包括但不限于:
    • HTTP/HTTPS链接
    • 带查询参数的URL
    • 带锚点的URL
    • 带端口的URL

Daft 调用

算子参数

输入

输入列名

说明

texts

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

输出

占比结果列,元素为浮点数,表示URL字符的占比

调用示例

下面的代码展示了如何使用 daft 运行算子计算文本中URL字符的占比。

from __future__ import annotations

import os

import daft
from daft import col
from daft.las.functions.text.url_ratio_calculator import UrlRatioCalculator
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": [
            "Hello world",
            "Check out https://example.com for more info",
            "Visit http://test.com and https://demo.org",
            "No URLs here, just text",
            "Mixed content: https://short.com and some text",
        ]
    }

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

    ds.show()
    # ╭────────────────────────────────┬────────────────────╮
    # │ text                           ┆ url_ratio          │
    # │ ---                            ┆ ---                │
    # │ String                         ┆ Float64            │
    # ╞════════════════════════════════╪════════════════════╡
    # │ Hello world                    ┆ 0                  │
    # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
    # │ Check out https://example.com… ┆ 0.4418604651162791 │
    # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
    # │ Visit http://test.com and htt… ┆ 0.7380952380952381 │
    # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
    # │ No URLs here, just text        ┆ 0                  │
    # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
    # │ Mixed content: https://short.… ┆ 0.3695652173913043 │
    # ╰────────────────────────────────┴────────────────────╯
最近更新时间:2026.01.08 19:14:22
这个页面对您有帮助吗?
有用
有用
无用
无用