most_similar | R Documentation |
Select the most similar texts to a specific text
most_similar(sample, pool, coefficient, n)
sample |
This is a single row of a |
pool |
This is a dfm containing all possible samples from which to select the top n. |
coefficient |
The coefficient to use for similarity. Either "minmax", "cosine", or "Phi". |
n |
The number of rows to extract from the pool of potential samples. |
The function returns a dfm containing the top n most similar rows to the input sample using the minmax distance.
text1 <- "The cat sat on the mat"
text2 <- "The dog sat on the chair"
text3 <- "Violence is the last refuge of the incompetent"
c <- quanteda::corpus(c(text1, text2, text3))
d <- quanteda::tokens(c) |> quanteda::dfm() |> quanteda::dfm_weight(scheme = "prop")
most_similar(d[1,], d[-1,], coefficient = "minmax", n = 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.