Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #1
- library("tm")
- library("wordcloud")
- library("sentimentr")
- setwd("D:/Studia/Magisterskie/Semestr III/Przetwarzanie")
- getwd()
- teksty <- paste0(getwd(), "/hrabia")
- teksty_dir <- DirSource(teksty,encoding="UTF-8")
- korpus_dir <- VCorpus(teksty_dir)
- czysc_korpus <- function(czysty_korpus, lista_slow=NULL) {
- czysty_korpus<-tm_map(czysty_korpus, removePunctuation)
- czysty_korpus<-tm_map(czysty_korpus, content_transformer(tolower))
- czysty_korpus<-tm_map(czysty_korpus, removeNumbers)
- czysty_korpus<-tm_map(czysty_korpus, stripWhitespace)
- czysty_korpus<-tm_map(czysty_korpus, removeWords, c(lista_slow, stopwords("en")))
- return(czysty_korpus)
- }
- czysty_korpus <- czysc_korpus(korpus_dir)
- #2
- dendrogram_hrabia <-DocumentTermMatrix(czysty_korpus,control = list(weighting = weightBin))
- dendrogram_hrabia<-removeSparseTerms(dendrogram_hrabia, sparse=0.95)
- mat_licz<-as.matrix(dendrogram_hrabia)
- sums_licz<-rowSums(mat_licz)
- sums_licz<-sort(sums_licz, decreasing = TRUE)
- rozdz<-c(head(sums_licz,2),tail(sums_licz,2))
- rozdz
- barplot(rozdz, las=2,main = "Liczebność termów w rozdziałach",ylab="Liczba termów")
- #3
- tekst<-korpus_dir['rozdz34.txt']$content
- (wynik_by <- sentiment_by(tekst))
- ggplot(wynik_by, aes(element_id, ave_sentiment)) +
- geom_bar(stat = "identity") +
- labs(title = "Analiza nastroju treści rozdziału 34", x = "Opinie", y = "Ocena sentymentu") +
- theme_minimal()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement