emoji_collocations() counts the words that appear near each emoji across a
corpus and scores the association with pointwise mutual information. It is
the corpus-derived alternative to importing a fixed sense inventory: the
senses come from your texts, so they cannot be stale and carry no licence
baggage.
Usage
emoji_collocations(
data,
text,
window = 5,
min_n = 3,
measure = c("pmi", "count")
)Arguments
- data
A data frame or tibble containing a text column. Grouped data frames are accepted. The verbs that work a row at a time (adding columns, or keeping and expanding rows) carry the grouping through to their result, as
dplyr::mutate()anddplyr::filter()do. The verbs that pool across rows – the counts, the co-occurrence edge lists, the time series – warn that they ignore the grouping and return one corpus-wide answer.- text
The text column to scan, supplied unquoted. Any atomic column is accepted and read as character, so a
factorworks and a numeric,Dateor logical one simply contains no emoji. A list column – or a data-frame column – is refused rather than coerced, because coercing one deparses it and the emoji found would be in the code rather than in your data. What counts as an emoji is the same in every verb; see the Detection section of tidyEmoji for the one case that surprises people, code points that are emoji only when they carryU+FE0F.- window
Context window on each side, in words. Default
5.- min_n
Minimum number of co-occurrences for a pair to be reported. Default
3.- measure
Sort order:
"pmi"(default) or"count". Both columns are always returned.
Value
A tibble with columns emoji, word, n (co-occurrences) and
pmi, shaped like widyr::pairwise_count() output so it drops into
existing tidytext workflows. Rows are sorted by measure descending,
then by the other of the two descending, then by the glyph and the word,
so the order is fully determined. Ties in pmi are common: every pair
seen the same number of times with the same marginals scores alike.
Details
Each emoji occurrence contributes its context window (see
emoji_context()). A word is counted once per occurrence however often it
repeats inside that window. Words are lower-cased and stripped of leading
and trailing characters that are not letters, digits or combining marks, and
a token left holding no letter and no digit at all is not a word. All three
rules read Unicode's own tables rather than the session's locale, so a
corpus in any script gives the same answer wherever it is run. No stopword
list is applied, because which stopwords are right is a decision for your
analysis, not for this package – filter the result with
tidytext's stop_words if you want one.
PMI is log(n(e, w) * N / (n(e) * n(w))), with N the total number of
emoji-word co-occurrence events. Marginals are computed over all
co-occurrences before min_n filters the rows, so a rare pairing is scored
against the full corpus rather than against the surviving subset.
Glyphs are canonicalised through the package's codepoint key, so qualified and unqualified forms of the same emoji share one row.
On a script without spaces between words this verb cannot find a
collocation at all, and it will not say so. Its tokens are the
whitespace-delimited ones of emoji_context(), so a Chinese, Japanese, Thai,
Khmer, Lao or Burmese clause is one token: three rows of Chinese reading
"the weather is good today", "my mood is good today" and "going to Beijing
tomorrow" yield three tokens, each a whole clause, each with n = 1, and
nothing clears min_n. The same three sentences in English yield good,
is and today at n = 2. Segment the column before it reaches this verb
(see emoji_context()); min_n cannot rescue a vocabulary in which every
type occurs once.
See also
emoji_context() for the occurrence-level windows this aggregates.
Examples
df <- data.frame(text = c("cold coffee \U0001f622",
"coffee again \U0001f622",
"warm tea \U0001f60a"))
emoji_collocations(df, text, min_n = 1)
#> # A tibble: 5 × 4
#> emoji word n pmi
#> <chr> <chr> <int> <dbl>
#> 1 😊 tea 1 1.10
#> 2 😊 warm 1 1.10
#> 3 😢 coffee 2 0.405
#> 4 😢 again 1 0.405
#> 5 😢 cold 1 0.405