Advertisement
Guest User

Untitled

a guest
Feb 28th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #1
  2. library("tm")
  3. library("wordcloud")
  4. library("sentimentr")
  5. setwd("D:/Studia/Magisterskie/Semestr III/Przetwarzanie")
  6. getwd()
  7. teksty <- paste0(getwd(), "/hrabia")
  8. teksty_dir <- DirSource(teksty,encoding="UTF-8")
  9. korpus_dir <- VCorpus(teksty_dir)
  10. czysc_korpus <- function(czysty_korpus, lista_slow=NULL) {
  11. czysty_korpus<-tm_map(czysty_korpus, removePunctuation)
  12. czysty_korpus<-tm_map(czysty_korpus, content_transformer(tolower))
  13. czysty_korpus<-tm_map(czysty_korpus, removeNumbers)
  14. czysty_korpus<-tm_map(czysty_korpus, stripWhitespace)
  15. czysty_korpus<-tm_map(czysty_korpus, removeWords, c(lista_slow, stopwords("en")))
  16. return(czysty_korpus)
  17. }
  18. czysty_korpus <- czysc_korpus(korpus_dir)
  19. #2
  20. dendrogram_hrabia <-DocumentTermMatrix(czysty_korpus,control = list(weighting = weightBin))
  21. dendrogram_hrabia<-removeSparseTerms(dendrogram_hrabia, sparse=0.95)
  22. mat_licz<-as.matrix(dendrogram_hrabia)
  23. sums_licz<-rowSums(mat_licz)
  24. sums_licz<-sort(sums_licz, decreasing = TRUE)
  25. rozdz<-c(head(sums_licz,2),tail(sums_licz,2))
  26. rozdz
  27. barplot(rozdz, las=2,main = "Liczebność termów w rozdziałach",ylab="Liczba termów")
  28. #3
  29. tekst<-korpus_dir['rozdz34.txt']$content
  30. (wynik_by <- sentiment_by(tekst))
  31.  
  32. ggplot(wynik_by, aes(element_id, ave_sentiment)) +
  33. geom_bar(stat = "identity") +
  34. labs(title = "Analiza nastroju treści rozdziału 34", x = "Opinie", y = "Ocena sentymentu") +
  35. theme_minimal()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement