StringSimilarity
Description
td_string_similarity_sqle()
function calculates the similarity between two
strings, using either the Jaro, Jaro-Winkler, N-Gram, or Levenshtein
distance.
Usage
td_string_similarity_sqle (
data = NULL,
comparison.columns = NULL,
case.sensitive = NULL,
accumulate = NULL,
...
)
Arguments
data |
Required Argument.
Specifies the input tbl_teradata.
Types: tbl_teradata
|
comparison.columns |
Required Argument.
Specifies pairs of input tbl_teradata columns that contain
strings to be compared (column1 and column2), how to compare them
(comparison_type), and (optionally) a constant and the name of the
output column for their similarity (output_column). The similarity is
a value in the range [0, 1].
For comparison_type, use one of these values:
"jaro": Jaro distance.
"jaro_winkler": Jaro-Winkler distance (1 for an exact match, 0 otherwise).
If you specify this comparison type, you can specify the value of
factor p with constant. 0 ≤ p ≤ 0.25.
Default: p = 0.1
"n_gram": N-gram similarity.
If you specify this comparison type, you can specify the value of N with
constant.
Default: N = 2
"LD": Levenshtein distance
The number of edits needed to transform one string into the other,
where edits include insertions, deletions, or substitutions of
individual characters.
"LDWS": Levenshtein distance without substitution.
Number of edits needed to transform one string into the other using only
insertions or deletions of individual characters.
"OSA": Optimal string alignment distance.
Number of edits needed to transform one string into the other.
Edits are insertions, deletions, substitutions, or transpositions of
characters. A substring can be edited only once.
"DL": Damerau-Levenshtein distance.
Like OSA, except that a substring can be edited any number of times.
"hamming": Hamming distance.
Number of positions where corresponding characters differ (that is,
minimum number of substitutions needed to transform one string into the
other) for strings of equal length, otherwise -1 for strings of unequal
length.
"LCS": Longest common substring.
Length of longest substring common to both strings.
"jaccard": Jaccard index-based comparison.
"cosine": Cosine similarity.
"soundexcode": Only for English strings. -1 if either string has a
non-English character, otherwise, 1 if their soundex codes are the same
and 0 otherwise.
You can specify a different comparison_type for every pair of columns.
The default output_column is "sim_i", where i is the sequence number of the
column pair.
Types: character OR vector of Strings (character)
|
case.sensitive |
Optional Argument.
Specifies whether string comparison is case-sensitive. The default
value is FALSE. You can specify either one value for all pairs or
one value for each pair. If you specify one value for each pair, then
the ith value applies to the ith pair.
Types: logical OR vector of logical
|
accumulate |
Optional Argument.
Specifies the names of input tbl_teradata columns to be
copied to the output.
Types: character OR vector of Strings (character)
|
... |
Specifies the generic keyword arguments SQLE functions accept.
Below are the generic keyword arguments:
persist:
Optional Argument.
Specifies whether to persist the results of the function in a table or not.
When set to TRUE, results are persisted in a table; otherwise, results
are garbage collected at the end of the session.
Default Value: FALSE
Types: logical
volatile:
Optional Argument.
Specifies whether to put the results of the function in a volatile table or not.
When set to TRUE, results are stored in a volatile table, otherwise not.
Default Value: FALSE
Types: logical
Function allows the user to partition, hash, order or local order the input
data. These generic arguments are available for each argument that accepts
tbl_teradata as input and can be accessed as:
"<input.data.arg.name>.partition.column" accepts character OR vector of Strings (character) (Strings)
"<input.data.arg.name>.hash.column" accepts character OR vector of Strings (character) (Strings)
"<input.data.arg.name>.order.column" accepts character OR vector of Strings (character) (Strings)
"local.order.<input.data.arg.name>" accepts logical
Note:
These generic arguments are supported by tdplyr if the underlying SQL Engine
function supports, else an exception is raised.
|
Value
Function returns an object of class "td_string_similarity_sqle"
which is a named list containing object of class "tbl_teradata".
Named list member(s) can be referenced directly with the "$" operator
using the name(s):result
Examples
# Get the current context/connection.
con <- td_get_context()$connection
# Load the example data.
loadExampleData("stringsimilarity_example", "strsimilarity_input")
# Create tbl_teradata object.
strsimilarity_input <- tbl(con, "strsimilarity_input")
# Check the list of available analytic functions.
display_analytic_functions()
# Example 1: Creating tbl_teradata by calculating the
# similarity between two strings.
obj <- td_string_similarity_sqle(
data = strsimilarity_input,
comparison.columns=c('jaro (src_text1, tar_text) AS jaro1_sim',
'LD (src_text1, tar_text) AS ld1_sim',
'n_gram (src_text1, tar_text, 2) AS ngram1_sim',
'jaro_winkler (src_text1, tar_text, 0.1) AS jw1_sim'),
case.sensitive = TRUE,
accumulate = c("id","src_text1","tar_text"))
# Print the result.
print(obj$result)