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

Lake AI Service

Copy page
Download PDF
Text processing
Duplicate row calculator
Copy page
Download PDF
Duplicate row calculator

Operator introduction

Description

Duplicate row calculator - calculates the proportion of duplicate rows in text

Key features

  • Duplicate row detection: Automatically identifies duplicate row content in text
  • Ratio calculation: Calculates the ratio of duplicate rows to original rows
  • Quality assessment: Evaluates the degree of duplication and quality of the text

Application scenarios

  • Text quality assessment
  • Data cleaning and preprocessing
  • Content duplication detection
  • Document quality check

Technical features

  • Exact match: Only completely identical content is considered duplicate
  • Blank row filtering: Automatically filters blank rows, does not affect the calculation
  • Result range: 0-1, the closer to 1, the greater the duplication

Operator invocation in Daft

Operator parameters

Input

Input column name

Description

texts

Text column to be processed, element type must be of string type

Output

Duplicate row ratio column, elements are floating-point numbers representing the duplicate row ratio

Examples

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

from __future__ import annotations

import os

import daft
from daft import col
from daft.las.functions.text.repeated_lines_calculator import RepeatedLinesCalculator
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": [
            "The content of the first line \n the content of the second line \n the content of the first line \n the content of the third line",
            "",
            "",
        ]
    }

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

    ds.show()
    
    # ╭────────────┬────────────────────╮
    # │ text       ┆ repeated_ratio     │
    # │ ---        ┆ ---                │
    # │ String     ┆ Float64            │
    # ╞════════════╪════════════════════╡
    # │ First row content ┆ 0.25               │
    # │ Second row content ┆                    │
    # │ First row content ┆                    │
    # │ Third row content ┆                    │
    # ├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
    # │ First row content ┆ 0.6666666666666666 │
    # │ First row content ┆                    │
    # │ First row content ┆                    │
    # ├╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
    # │ First row content ┆ 0                  │
    # │            ┆                    │
    # │ Second row content ┆                    │
    # │            ┆                    │
    # │ Third row content ┆                    │
    # ╰────────────┴────────────────────╯
Last updated: 2026.05.22 11:19:18