Teradata Package for R Function Reference | 17.00 - 17.00 - LevenshteinDistance - Teradata Package for R

Teradata® Package for R Function Reference

Product
Teradata Package for R
Release Number
17.00
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B700-4007-090K
Language
English (United States)

Description

The Levenshtein Distance (LDist) function computes the Levenshtein distance between two text values. The Levenshtein distance (or edit distance) is the number of edits needed to transform one string into the other. An edit is an insertion, deletion, or substitution of a single character.

Usage

  td_levenshtein_distance_mle (
      data = NULL,
      target.column = NULL,
      source = NULL,
      threshold = NULL,
      output.column = "distance",
      output.target = "target",
      print.source = "source",
      accumulate = NULL,
      data.sequence.column = NULL,
      data.order.column = NULL
  )

Arguments

data

Required Argument.
Specifies the tbl_teradata input data for text analysis.

data.order.column

Optional Argument.
Specifies Order By columns for "data".
Values to this argument can be provided as a vector, if multiple columns are used for ordering.
Types: character OR vector of Strings (character)

target.column

Required Argument.
Specifies the name of the input column that contains the target text.
Types: character

source

Required Argument.
Specifies the names of the input columns that contain the source text.
Types: character OR vector of Strings (character)

threshold

Optional Argument.
Specifies the value that determines whether to return the Levenshtein distance for a source-target pair. The threshold must be a positive integer. The function returns the Levenshtein distance for a pair if it is less than or equal to threshold; otherwise, the function returns -1. By default, the function returns the Levenshtein distance of every pair.
Types: integer

output.column

Optional Argument.
Specifies the name of the output column that contains the Levenshtein distance for a source-target pair.
Default Value: "distance"
Types: character

output.target

Optional Argument.
Specifies the name of the output column that contains the compared target text.
Default Value: "target"
Types: character

print.source

Optional Argument.
Specifies the name of the output column that contains the compared source text.
Default Value: "source"
Types: character

accumulate

Optional Argument.
Specifies the names of the input columns to copy to the output tbl_teradata.
Types: character OR vector of Strings (character)

data.sequence.column

Optional Argument.
Specifies the vector of column(s) that uniquely identifies each row of the input argument "data". The argument is used to ensure deterministic results for functions which produce results that vary from run to run.
Types: character OR vector of Strings (character)

Value

Function returns an object of class "td_levenshtein_distance_mle" which is a named list containing object of class "tbl_teradata". Named list member can be referenced directly with the "$" operator using name: result.

Examples

    # Get the current context/connection
    con <- td_get_context()$connection
    
    # Load example data.
    loadExampleData("levenshteindistance_example", "levendist_input")
    
    # Create object(s) of class "tbl_teradata".
    levendist_input <- tbl(con, "levendist_input")
    
    # Example 1 - This function computes the Levenshtein distance between two input text values.
    td_levenshtein_distance_out <- td_levenshtein_distance_mle(data=levendist_input,
                                                           target.column = "tar_text",
                                                           source = c("src_text1", "src_text2"),
                                                           threshold = 10,
                                                           accumulate = c("id")
                                                           )