-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisi_recipes.R
More file actions
103 lines (81 loc) · 3.63 KB
/
Copy pathisi_recipes.R
File metadata and controls
103 lines (81 loc) · 3.63 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
library(bibliometrix)
library(tidytext)
library(tm)
library(topicmodels)
library(dplyr)
library(tm.plugin.webmining)
#all articles before selection
isi.rawdata <- readFiles("isi/savedrecs.bib")
isi.dfrawdata <- convert2df(isi.rawdata, dbsource = "isi", format = "bibtex")
#selected papers
isi.selected <- readFiles("isiselected.bib")
isi.df <- convert2df(isi.selected, dbsource = "isi", format = "bibtex")
#conceptual coword structure
isi.rawcs <- conceptualStructure(isi.dfrawdata, field = "DE_TM", minDegree = 7, k.max = 4, stemming = FALSE, labelsize = 10)
isi.rawcs$km.res
#best repr
isi.rawcs <- conceptualStructure(isi.dfrawdata, field = "DE_TM", minDegree = 14, k.max = 5, stemming = FALSE, labelsize = 10)
#selected pdf files
library(tm)
files <- list.files("isiarticles/",pattern = "pdf$")
rpdf <- readPDF(control = list(text = "-layout"))
isi.pdf <- Corpus(URISource(files), readerControl = list(reader = rpdf))
isi.pdftdm <- TermDocumentMatrix(isi.pdf, control=list(removePunctuation = TRUE, stopwords = TRUE, tolower = TRUE, stemming = TRUE, removeNumbers = TRUE))
isi.pdfdtm <- DocumentTermMatrix(isi.pdf, control=list(removePunctuation = TRUE, stopwords = TRUE, tolower = TRUE, stemming = FALSE, removeNumbers = TRUE))
#select terms
isi.dtmTerms <- Terms(isi.pdfdtm)
head(isi.dtmTerms)
library(tidytext)
#sentiment analysis
isi.pdfsentiment <- isi.pdftidy %>%
inner_join(get_sentiments("bing"), by = c(term ="word"))
isi.pdftidy <- tidy(isi.pdfdtm)
isi.pdfsentiment %>%
+ count(sentiment, term, wt = count) %>%
+ ungroup() %>%
+ filter(n >= 200) %>%
+ mutate(n =ifelse(sentiment == "negative", -n, n)) %>%
+ mutate(term=reorder(term,n)) %>%
+ ggplot(aes(term, n, fill = sentiment)) +
+ geom_bar(stat="identity") +
+ ylab("Contribution to sentiment") +
+ coord_flip()
#create dataframe
isi.df <- convert2df(isi.rawdata, dbsource = "isi", format = "bibtex")
#tf-idf analysis, book chapter 3
isi.pdf.tf_idf <- isi.pdftidy %>%
+ bind_tf_idf(term, document, count) %>%
+ arrange(desc(tf_idf))
isi.pdf.tf_idf
#word topic probabilities
library(topicmodels)
isi.pdf.ap_lda <- LDA(isi.pdfdtm, k=3, control=list(seed=1234))
isi.pdf.ap_topics <- tidy(isi.pdf.ap_lda, matrix = "beta")
ilibrary(dplyr)
library(ggplot2)
isi.pdf.aptop_terms <- isi.pdf.ap_topics %>%
+ group_by(topic) %>%
+ top_n(10, beta) %>%
+ ungroup %>%
+ arrange(topic, -beta)
isi.pdf.aptop_terms %>%
+ mutate(term = reorder(term, beta)) %>%
+ ggplot(aes(term, beta, fill=factor(topic))) +
+ geom_col(show.legend = FALSE) +
+ facet_wrap(~ topic, scales = "free") +
+ coord_flip()
#radar chart
library(fmsb)
mbaryear=barplot(isi.summary$AnnualProduction$Articles, border=F,names.arg = isi.summary$AnnualProduction$`Year `, las = 2, col = rgb(0.2, 0.12, 0.47), ylab = "articles")
#country scientific collaboration
isi.metaTag <- metaTagExtraction(isi.df, Field = "AU_CO", sep = ";")
netmatrix <- biblioNetwork(isi.metaTag, analysis = "collaboration", network = "countries", sep = ";")
networkPlot(netmatrix, n =20, type = "circle", size = TRUE, remove.multiple = FALSE)
#author's coupling
isi.selected <- readFiles("savedrecs_selected.bib")
isi.selectedf <- convert2df(isi.selected, dbsource = "isi", format = "bibtex")
isi.netmatrix <- biblioNetwork(isi.selectedf, analysis = "coupling", network = "authors", sep = ";")
isi.netmatrixnormalized <- normalizeSimilarity(isi.netmatrix, type="salton")
networkPlot(isi.netmatrixnormalized, n=30, Title = "Author's Coupling", type = "kamada", size = FALSE,remove.multiple = TRUE, halo = TRUE, curved = TRUE, edgesize = 0.2)
#salva dados para arquivo
cat("ISI Summary", capture.output(isi.results), file = "res.txt",sep = "n",append = TRUE)