dict: Create word dictionary

Description Usage Arguments Value Examples

View source: R/dict.R

Description

Create word dictionary

Usage

1
dict(x)

Arguments

x

Input can be a vector of words, a list of 'positive' and 'negative' word vectors, a data frame with 'word' and 'weight' columns

Value

A dictionary

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
pos <- c("like", "love", "amazing", "excellent", "great", "fantastic",
  "incredible", "awesome", "best", "favorite", "fan", "fun", "enjoyed",
  "good", "solid", "better", "soooo", "happy")
neg <- c("hate", "loathe", "dislike", "awful", "horrible", "worst",
  "miserable", "ruin", "ruining", "destroy", "destroyed", "destroying",
  "pathetic", "hated", "hateful", "unhappy", "terrible")

## create dictionary using only positive words
dict(pos)

## create dictionary using only negative words
dict(neg)

## create dictionary using both positive and negative words
d <- dict(list(pos = pos, neg = neg))

## view up to n entries of dictionary
print(d, n = 15)

## example text
txt <- c("love amazing excellent good",
  "hate loathe horrifies unhappy terrible",
  "awesome best hateful hated worst")

## get estimate for each element of txt using pos/neg dictionary
d$score(txt)

## create tibble
tibble::tibble(
  text = txt,
  sent = d$score_score(txt)
)

mkearney/dict documentation built on Nov. 4, 2019, 6:59 p.m.