@@ -143,7 +143,8 @@ works2df <- function(data, abstract = TRUE, verbose = TRUE,
143
143
" is_oa_anywhere" , " oa_status" , " oa_url" , " any_repository_has_fulltext" ,
144
144
" language" , " grants" , " cited_by_count" , " counts_by_year" ,
145
145
" publication_year" , " cited_by_api_url" , " ids" , " doi" , " type" ,
146
- " referenced_works" , " related_works" , " is_paratext" , " is_retracted" , " concepts"
146
+ " referenced_works" , " related_works" , " is_paratext" , " is_retracted" ,
147
+ " concepts" , " topics"
147
148
)
148
149
works_process <- tibble :: tribble(
149
150
~ type , ~ field ,
@@ -245,7 +246,31 @@ works2df <- function(data, abstract = TRUE, verbose = TRUE,
245
246
names(open_access )[[1 ]] <- " is_oa_anywhere"
246
247
}
247
248
248
- out_ls <- c(sim_fields , venue , open_access , paper_biblio , list (author = author , ab = ab ))
249
+ # Topics
250
+ process_paper_topics <- function (paper ) {
251
+ topics <- paper $ topics
252
+ if (is.null(topics )) return (NULL )
253
+ topics_ls <- lapply(seq_along(topics ), function (i ) {
254
+ topic <- topics [[i ]]
255
+ relev <- c(
256
+ # Hoist fields for the topic entity
257
+ list (topic = topic [c(" id" , " display_name" )]),
258
+ # Keep info about other entities as-is
259
+ topic [vapply(topic , is.list , logical (1 ))]
260
+ )
261
+ relev_df <- subs_na(relev , " rbind_df" )[[1 ]]
262
+ relev_df <- tibble :: rownames_to_column(relev_df , " name" )
263
+ cbind(i = i , score = topic $ score , relev_df )
264
+ })
265
+ topics_df <- do.call(rbind.data.frame , topics_ls )
266
+ list (tibble :: as_tibble(topics_df ))
267
+ }
268
+ topics <- process_paper_topics(paper )
269
+
270
+ out_ls <- c(
271
+ sim_fields , venue , open_access , paper_biblio ,
272
+ list (author = author , ab = ab , topics = topics )
273
+ )
249
274
out_ls [sapply(out_ls , is.null )] <- NULL
250
275
list_df [[i ]] <- out_ls
251
276
}
0 commit comments