Teradata R Package Function Reference - LevenshteinDistance - Teradata R Package - Look here for syntax, methods and examples for the functions included in the Teradata R Package.

Teradata® R Package Function Reference

Product
Teradata R Package
Release Number
16.20
Published
February 2020
Language
English (United States)
Last Update
2020-02-28
dita:id
B700-4007
lifecycle
previous
Product Category
Teradata Vantage

Description

The Levenshtein Distance function td_levenshtein_distance_mle() 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.
Order By Columns for data.
Values to this argument can be provided as 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 OR vector of Strings (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: numeric.

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 table.
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 Teradata tbl object.
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 remote tibble objects.
    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")
                                                           )