Learn R Programming

text (version 0.9.99.2)

textDistance: Compute the semantic distance between two text variables.

Description

Compute the semantic distance between two text variables.

Usage

textDistance(x, y, method = "euclidean", center = FALSE, scale = FALSE)

Value

A vector comprising semantic distance scores.

Arguments

x

Word embeddings (from textEmbed).

y

Word embeddings (from textEmbed).

method

Character string describing type of measure to be computed; default is "euclidean" (see also measures from stats:dist() including "maximum", "manhattan", "canberra", "binary" and "minkowski". It is also possible to use "cosine", which computes the cosine distance (i.e., 1 - cosine(x, y)).

center

(boolean; from base::scale) If center is TRUE then centering is done by subtracting the column means (omitting NAs) of x from their corresponding columns, and if center is FALSE, no centering is done.

scale

(boolean; from base::scale) If scale is TRUE then scaling is done by dividing the (centered) columns of x by their standard deviations if center is TRUE, and the root mean square otherwise.

See Also

see textSimilarity, textSimilarityNorm and textSimilarityTest

Examples

Run this code
library(dplyr)
distance_scores <- textDistance(
  x = word_embeddings_4$texts$harmonytext,
  y = word_embeddings_4$texts$satisfactiontext
)
comment(distance_scores)

Run the code above in your browser using DataLab