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

Lake AI Service

Copy page
Download PDF
Text processing
URL ratio calculator
Copy page
Download PDF
URL ratio calculator

Operator introduction

Description

URL ratio calculator - Text feature extraction based on the proportion of URL characters

Key features

  • URL ratio calculation: Accurately calculates the proportion of URL characters in the text
  • Multi-protocol support: Supports multiple URL protocols, such as HTTP and HTTPS
  • Intelligent recognition: Uses regular expressions to accurately identify URL formats

Application scenarios

  • Text quality assessment
  • Data cleaning and preprocessing
  • Text classification feature extraction
  • Content security detection
  • Web content analysis

Technical characteristics

  • URL character ratio: The proportion of URL characters to the total number of characters
  • Supports multiple URL formats, including but not limited to:
    • HTTP/HTTPS links
    • URLs with query parameters
    • URLs with anchors
    • URLs with ports

Daft usage

Operator parameters

Input

Input column name

Description

texts

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

Output

Column of ratio results, where each element is a floating-point number representing the proportion of URL characters

Examples

The following code demonstrates how to use daft to run the operator and calculate the proportion of URL characters in text.

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.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 │
    # ╰────────────────────────────────┴────────────────────╯
Last updated: 2026.05.12 19:06:38