# NOT RUN {
mytext <- c(
'do you like it? It is red. But I hate really bad dogs',
'I am the best friend.',
"Do you really like it? I'm not happy"
)
## works on a character vector but not the preferred method avoiding the
## repeated cost of doing sentence boundary disambiguation every time
## `sentiment` is run
# }
# NOT RUN {
sentiment(mytext)
sentiment_by(mytext)
# }
# NOT RUN {
## preferred method avoiding paying the cost
mytext <- get_sentences(mytext)
sentiment_by(mytext)
sentiment_by(mytext, averaging.function = average_mean)
sentiment_by(mytext, averaging.function = average_weighted_mixed_sentiment)
get_sentences(sentiment_by(mytext))
(mysentiment <- sentiment_by(mytext, question.weight = 0))
stats::setNames(get_sentences(sentiment_by(mytext, question.weight = 0)),
round(mysentiment[["ave_sentiment"]], 3))
pres_dat <- get_sentences(presidential_debates_2012)
# }
# NOT RUN {
## less optimized way
with(presidential_debates_2012, sentiment_by(dialogue, person))
# }
# NOT RUN {
# }
# NOT RUN {
sentiment_by(pres_dat, 'person')
(out <- sentiment_by(pres_dat, c('person', 'time')))
plot(out)
plot(uncombine(out))
sentiment_by(out, presidential_debates_2012$person)
with(presidential_debates_2012, sentiment_by(out, time))
highlight(with(presidential_debates_2012, sentiment_by(out, list(person, time))))
# }
# NOT RUN {
# }
# NOT RUN {
## tidy approach
library(dplyr)
library(magrittr)
hu_liu_cannon_reviews %>%
mutate(review_split = get_sentences(text)) %$%
sentiment_by(review_split)
# }
Run the code above in your browser using DataLab