Ifeanyi commited on
Commit
1c57048
1 Parent(s): 629e3d5

Update OpenAlexEdges.R

Browse files
Files changed (1) hide show
  1. OpenAlexEdges.R +85 -2
OpenAlexEdges.R CHANGED
@@ -26,8 +26,91 @@ authorPubEdges <- function(keywords,pub_start_date,pub_end_date){
26
 
27
  }
28
 
29
- # import nodes function
30
- source("openAlexNodes.R")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  # run author nodes function
33
  author_nodes <- authorPubNodes(keywords,pub_start_date,pub_end_date)
 
26
 
27
  }
28
 
29
+ # define nodes function
30
+ authorPubNodes <- function(keywords,pub_start_date,pub_end_date){
31
+
32
+ keywords <- keywords
33
+ pub_start_date <- pub_start_date
34
+ pub_end_date <- pub_end_date
35
+
36
+ # create search engine function
37
+ search_engine <- function(keywords,pub_start_date,pub_end_date){
38
+ suppressPackageStartupMessages(library(openalexR))
39
+ suppressPackageStartupMessages(library(tidyverse))
40
+
41
+ options(openalexR.mailto = "idiayeifeanyi@yahoo.com")
42
+
43
+ # search engine
44
+ works_search <- oa_fetch(
45
+ entity = "works",
46
+ title.search = keywords,
47
+ cited_by_count = ">50",
48
+ from_publication_date = pub_start_date,
49
+ to_publication_date = pub_end_date,
50
+ options = list(sort = "cited_by_count:desc"),
51
+ verbose = FALSE
52
+ )
53
+
54
+ return(works_search)
55
+
56
+ }
57
+
58
+ search_data <- search_engine(keywords,pub_start_date,pub_end_date)
59
+
60
+ # grab authors and group them according to collaboration
61
+ authors_collaboration_groups <- list()
62
+ for (i in 1:nrow(search_data)){
63
+ authors_collaboration_groups[[i]] <- search_data$author[[i]][2]
64
+ }
65
+
66
+ # grab all authors
67
+ all_authors <- c()
68
+ for (i in 1:length(authors_collaboration_groups)) {
69
+ all_authors <- c(all_authors,authors_collaboration_groups[[i]][[1]])
70
+ }
71
+
72
+ # get length of each authors collaboration
73
+ authors_length <- c()
74
+ for(authors in 1:length(authors_collaboration_groups)){
75
+ authors_length <- c(authors_length,authors_collaboration_groups[[authors]] |> nrow())
76
+ }
77
+
78
+ # grab all publications
79
+ publications <- list()
80
+ for (i in 1:nrow(search_data)){
81
+ publications[[i]] <- rep(search_data$display_name[i], each = authors_length[i])
82
+ }
83
+
84
+ # place all publications in a vector
85
+ all_publications <- c()
86
+ for(i in 1:length(publications)){
87
+ all_publications <- c(all_publications,publications[[i]])
88
+ }
89
+
90
+ # create author_to_publication data frame
91
+ authors_to_publications <- data.frame(
92
+ Authors = all_authors,
93
+ Publications = all_publications
94
+ )
95
+
96
+ # stack the df so that authors and publications
97
+ # are together as one column
98
+ stacked_df <- stack(authors_to_publications)
99
+ stacked_df <- unique.data.frame(stacked_df) # remove duplicate rows
100
+ stacked_df <- stacked_df[-2] # delete second column in df
101
+
102
+ # create author_publications_nodes df
103
+ author_publication_nodes <- data.frame(
104
+ Id = 1:nrow(stacked_df),
105
+ Nodes = stacked_df$values,
106
+ Label = stacked_df$values
107
+ )
108
+
109
+
110
+ return(author_publication_nodes)
111
+
112
+
113
+ }
114
 
115
  # run author nodes function
116
  author_nodes <- authorPubNodes(keywords,pub_start_date,pub_end_date)