@@ -5,9 +5,45 @@ library("plyr")
55mlog <- getLogger(" metrics" )
66
77
8- enrich_metadata_metrics <- function (metadata ) {
8+ enrich_metadata_metrics <- function (metadata , metrics_sources = ( " altmetric " , " crossref " ) ) {
99 start.time <- Sys.time()
1010
11+ if (" altmetric" %in% metrics_sources ) {
12+ metadata <- add_altmetrics(metadata )
13+ }
14+ if (" crossref" %in% metrics_sources ) {
15+ output <- add_citations(output )
16+ }
17+
18+ # Remove duplicate lines - TODO: check for root of this problem
19+ output <- unique(output )
20+
21+ end.time <- Sys.time()
22+ time.taken <- end.time - start.time
23+ mlog $ info(paste(" vis_id:" , .GlobalEnv $ VIS_ID , " Time taken:" , time.taken , sep = " " ))
24+
25+ return (output )
26+ }
27+
28+ get_altmetrics <- function (dois ) {
29+ valid_dois <- unique(dois [which(dois != " " )])
30+ results <- data.frame ()
31+ for (doi in valid_dois ) {
32+ tryCatch(
33+ {
34+ metrics <- altmetric_data(altmetrics(doi = doi , apikey = " " ))
35+ results <- rbind.fill(results , metrics )
36+ },
37+ error = function (err ) {
38+ mlog $ debug(gsub(" [\r\n ]" , " " , paste(err , doi , sep = " " )))
39+ }
40+ )
41+ }
42+ return (results )
43+ }
44+
45+ add_altmetrics <- function (metadata ) {
46+
1147 results <- get_altmetrics(metadata $ doi )
1248 requested_metrics <- c(
1349 " cited_by_wikipedia_count" ,
@@ -44,33 +80,6 @@ enrich_metadata_metrics <- function(metadata) {
4480 mlog $ info(" No altmetrics found for any paper in this dataset." )
4581 output <- metadata
4682 }
47- output <- add_citations(output )
48-
49- # Remove duplicate lines - TODO: check for root of this problem
50- output <- unique(output )
51-
52- end.time <- Sys.time()
53- time.taken <- end.time - start.time
54- mlog $ info(paste(" vis_id:" , .GlobalEnv $ VIS_ID , " Time taken:" , time.taken , sep = " " ))
55-
56- return (output )
57- }
58-
59- get_altmetrics <- function (dois ) {
60- valid_dois <- unique(dois [which(dois != " " )])
61- results <- data.frame ()
62- for (doi in valid_dois ) {
63- tryCatch(
64- {
65- metrics <- altmetric_data(altmetrics(doi = doi , apikey = " " ))
66- results <- rbind.fill(results , metrics )
67- },
68- error = function (err ) {
69- mlog $ debug(gsub(" [\r\n ]" , " " , paste(err , doi , sep = " " )))
70- }
71- )
72- }
73- return (results )
7483}
7584
7685add_citations <- function (output ) {
0 commit comments