====== Extracting units ======
# source("OpenAlex2Pajek.R")
# library(httr)
# library(jsonlite)
# source("https://raw.githubusercontent.com/bavla/OpenAlex/main/code/OpenAlex.R")
VBlist <- read.table("VladoWorks.csv")$V1
Q <- list(
search="handball",
filter="publication_year:2015",
select="id,primary_location,publication_year,publication_date,type,language,biblio,title,authorships,countries_distinct_count,cited_by_count,referenced_works_count,referenced_works",
# select="id,title,countries_distinct_count,cited_by_count,referenced_works_count",
# per_page="200"
per_page="3"
)
save <- TRUE
if(save) json <- file("save.ndjson","w",encoding="UTF-8")
openWorks <- function(query=NULL,list=NULL,file=NULL){
WC <<- new.env(hash=TRUE,parent=emptyenv())
WC$works <- "https://api.openalex.org/works"
WC$Q <- query; WC$L <- list; WC$f <- file
WC$n <- 0; WC$l <- 0; WC$m <- 0
if(length(query[["search"]])>0) {
WC$k <- 0; WC$nr <- 0; WC$act <- "page"
if(length(query[["per_page"]])==0) WC$Q$per_page <- "200"
WC$Q$cursor <- "*"
} else if(length(list)>0) { WC$act <- "list"
} else if(length(file)>0) { WC$act <- "open"
} else WC$act <- "stop"
}
nextWork <- function(){
# repeat{
for(t in 1:5){
switch(WC$act,
"page" = {
if(WC$n==10) {WC$act <- "list"; next}
WC$k <- WC$k + 1
if(WC$k>WC$nr){
WC$wd <- GET(WC$works,query=WC$Q)
if(WC$wd$status_code!=200) {WC$act <- "list"
cat(WC$n,"GET error\n"); flush.console(); next}
WC$k <- 1
WC$wc <- fromJSON(rawToChar(WC$wd$content))
WC$Q$cursor <- WC$wc$meta$next_cursor
if(is.null(WC$Q$cursor)) {WC$act <- "list"; next}
WC$df <- WC$wc$results; WC$nr <- nrow(WC$df)
cat(WC$k,wc$meta$count,WC$nr,"\n ",WC$Q$cursor,"\n"); flush.console()
}
WC$n <- WC$n + 1
return(WC$df[WC$k,])
},
"list" = {
WC$l <- WC$l + 1
if(WC$l>length(WC$L)) {WC$act <- "open"; next}
works <- paste(WC$works,"/",WC$L[WC$l],sep="")
WC$wd <- GET(works,query=list(select=WC$Q[["select"]]))
if(WC$wd$status_code!=200) {cat(WC$n,"GET error\n")
flush.console(); next}
cat(" >>>",WC$l,WC$L[WC$l],"\n"); flush.console()
wc <- fromJSON(rawToChar(WC$wd$content))
WC$n <- WC$n + 1
return(wc)
},
"open" = {
if(is.null(WC$f)) { WC$act <- "stop"; next }
WC$ndj <- file(WC$f,open="r")
WC$act <- "file"; next
},
"file" = {
wc <- readLines(con=WC$ndj,n=1)
if(length(wc)==0){ close(WC$ndj); WC$act <- "stop"; next }
WC$m <- WC$m + 1; WC$n <- WC$n + 1
return(fromJSON(wc))
},
"stop" = { return(NULL) },
stop(paste0("No handler for ",WC$act))
)
}
stop("Too many errors")
}
processWork <- function(w) {
cat(" Process:",WC$n,w$title,"\n")
Wid <- getID(w$id); hit <- TRUE
Sid <- getID(w$primary_location$source$id)
Sname <- w$primary_location$source$display_name
pYear <- w$publication_year; pDate <- w$publication_date
type <- w$type; lang <- w$language
vol <- w$biblio$volume; iss <- w$biblio$issue
fPage <- w$biblio$first_page; lPage <- w$biblio$last_page
title <- w$title; tit <- gsub(";",",",title)
fAName <- w$authorships$author$display_name[1]
if(length(w$authorships)==1) fAName <- w$authorships[[1]]$author$display_name[1]
sWname <- Gname(fAName,type,pYear,vol,fPage)
u <- putWork(Wid,sWname)
cat(u,Wid,hit,sWname,Sid,pYear,pDate,type,lang,vol,iss,fPage,lPage,fAName,tit,sep=";","\n"); flush.console()
if(!is.na(Sid)) {j <- putSrc(Sid,Sname); cat(u,j,"\n",file=wj)}
cat(u,Wid,hit,sWname,Sid,pYear,pDate,type,lang,vol,iss,fPage,lPage,fAName,tit,
sep=";",file=wrk); cat("\n",file=wrk)
refs <- w$referenced_works
if(length(w$referenced_works)==1) refs <- w$referenced_works[[1]]
for(wk in refs) {
vid <- getID(wk); v <- putWork(vid,"")
cat(v,vid,FALSE,"",NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,sep=";",file=wrk)
cat("\n",file=wrk); cat(u,v,"\n",file=ci) }
auts <- w$authorships$author
if(is.null(auts)) auts <- w$authorships[[1]]$author
for(a in 1:nrow(auts)) {
Aid <- getID(auts$id[a]); v <- putAuth(Aid,Aname=auts$display_name[a])
cat(u,v,"\n",file=wa) }
}
closeWorks <- function() rm(WC,inherits=TRUE)
cat("OpenAlex2Pajek - Start",date(),"\n")
ci <- file("Ci.tmp","w",encoding="UTF-8"); wa <- file("WA.tmp","w",encoding="UTF-8")
wj <- file("WJ.tmp","w",encoding="UTF-8"); wrk <- file("works.csv","w",encoding="UTF-8")
cat("% OpenAlex",date(),"\n",file=wa); cat("% OpenAlex",date(),"\n",file=wj)
cat("% OpenAlex",date(),"\n",file=ci); cat("% OpenAlex",date(),"\n",file=wrk)
cat("ind;Wid;hit;sWname;Sid;pYear;pDate;type;lang;vol;iss;fPage;lPage;fAName;title\n",file=wrk)
works <- eDict(); srces <- eDict(); auths <- eDict();
# openWorks(query=Q,list=VBlist,file="manual.ndjson")
# openWorks(query=Q,list=NULL,file="save.ndjson")
openWorks(query=Q,list=VBlist,file=NULL)
print(ls.str(WC))
cat("*** OpenAlex2Pajek - Start",date(),"\n")
repeat{
w <- nextWork()
if(is.null(w)) break
if(save) write(toJSON(w),file=json)
processWork(w)
}
cat("*** OpenAlex2Pajek - Stop",date(),"\n")
print(ls.str(WC))
closeWorks(); close(ci); close(wa); close(wj); close(wrk)
if(save) close(json)
cat("works:",length(works),"authors:",length(auths),"sources:",length(srces),"\n")
> source("OpenAlex2Pajek.R")
OpenAlex2Pajek - Start Sun Mar 17 19:00:53 2024
act : chr "page"
f : NULL
k : num 0
l : num 0
L : chr [1:7] "W2147991930" "W2008006577" "W1981385379" "W2110311637" "W2083084326" "W2023723604" ...
m : num 0
n : num 0
nr : num 0
Q : List of 5
$ search : chr "handball"
$ filter : chr "publication_year:2015"
$ select : chr "id,primary_location,publication_year,publication_date,type,language,biblio,title,authorships,countries_distinct"| __truncated__
$ per_page: chr "3"
$ cursor : chr "*"
works : chr "https://api.openalex.org/works"
*** OpenAlex2Pajek - Start Sun Mar 17 19:00:53 2024
1 1330 3
Ils2MDMuMTAxNywgMTQzNzA5MTIwMDAwMCwgJ2h0dHBzOi8vb3BlbmFsZXgub3JnL1cyMTMzNDE0MDY4J10i
Process: 1 Improving Fitness of Elite Handball Players
1;W1971587050;TRUE;Iacono_AD(2015)29:835;S150708336;2015;2015-03-01;article;en;29;3;835;843;Antonio Dello Iacono;Improving Fitness of Elite Handball Players;
Process: 2 Incidence and risk factors of injuries in Brazilian elite handball players: A prospective cohort study
31;W2218176234;TRUE;Giroto_N(2015)27:195;S199863227;2015;2015-12-10;article;en;27;2;195;202;N. Giroto;Incidence and risk factors of injuries in Brazilian elite handball players: A prospective cohort study;
Process: 3 Injury and illness surveillance during the 24th Men's Handball World Championship 2015 in Qatar
57;W2133414068;TRUE;Bere_T(2015)49:1151;S136578784;2015;2015-07-17;article;en;49;17;1151;1156;Tone Bere;Injury and illness surveillance during the 24th Men's Handball World Championship 2015 in Qatar;
1 1330 3
Ils0OTEuMjQyNzcsIDE0MzA0Mzg0MDAwMDAsICdodHRwczovL29wZW5hbGV4Lm9yZy9XMjAxMjE5NjY4NyddIg==
Process: 4 Technical Match Characteristics and Influence of Body Anthropometry on Playing Performance in Male Elite Team Handball
90;W2014565141;TRUE;Michalsi_LB(2015)29:416;S150708336;2015;2015-02-01;article;en;29;2;416;428;Lars Bojsen Michalsik;Technical Match Characteristics and Influence of Body Anthropometry on Playing Performance in Male Elite Team Handball;
Process: 5 Structural Brain Correlates Associated with Professional Handball Playing
98;W2070786099;TRUE;Hänggi_J(2015)10:e0124222;S202381698;2015;2015-04-27;article;en;10;4;e0124222;e0124222;Jürgen Hänggi;Structural Brain Correlates Associated with Professional Handball Playing;
Process: 6 Test-retest reliability of seven common clinical tests for assessing lower extremity muscle flexibility in futsal and handball players
181;W2012196687;TRUE;Cejudo_A(2015)16:107;S27861859;2015;2015-05-01;article;en;16;2;107;113;Antonio Cejudo;Test-retest reliability of seven common clinical tests for assessing lower extremity muscle flexibility in futsal and handball players;
1 1330 3
Ils0NDkuNTIyNzQsIDE0MjQwNDQ4MDAwMDAsICdodHRwczovL29wZW5hbGV4Lm9yZy9XMjAxMTA3NjQ4NSddIg==
Process: 7 Comparison of Inflammatory Responses and Muscle Damage Indices Following a Soccer, Basketball, Volleyball and Handball Game at an Elite Competitive Level
207;W1999308010;TRUE;Souglis_A(2015)23:59;S25740861;2015;2015-01-02;article;en;23;1;59;72;Athanasios Souglis;Comparison of Inflammatory Responses and Muscle Damage Indices Following a Soccer, Basketball, Volleyball and Handball Game at an Elite Competitive Level;
Process: 8 Talent development as an ecology of games: a case study of Norwegian handball
235;W2273156203;TRUE;Bjørndal_CT(2015)22:864;S58769659;2015;2015-09-22;article;en;22;7;864;877;Christian Thue Bjørndal;Talent development as an ecology of games: a case study of Norwegian handball;
Process: 9 Anthropometric and physical performance characteristics of top-elite, elite and non-elite youth female team handball players
261;W2011076485;TRUE;Moss_S(2015)33:1780;S95965737;2015;2015-02-16;article;en;33;17;1780;1789;Samantha Moss;Anthropometric and physical performance characteristics of top-elite, elite and non-elite youth female team handball players;
1 1330 3
Ils0MTUuNDE3MjQsIDE0Mjc4NDY0MDAwMDAsICdodHRwczovL29wZW5hbGV4Lm9yZy9XMjAyNjc0MDc4MiddIg==
Process: 10 Isokinetic Strength Profile of Elite Female Handball Players
281;W2413590293;TRUE;Xaverová_Z(2015)49:257;S128560994;2015;2015-12-01;article;en;49;1;257;266;Zuzana Xaverová;Isokinetic Strength Profile of Elite Female Handball Players;
>>> 1 W2147991930
Process: 11 Fast algorithms for determining (generalized) core groups in social networks
300;W2147991930;TRUE;Batagelj_V(2010)5:129;S4210175730;2010;2010-11-05;article;en;5;2;129;145;Vladimir Batagelj;Fast algorithms for determining (generalized) core groups in social networks;
>>> 2 W2008006577
Process: 12 Efficient generation of large random networks
317;W2008006577;TRUE;Batagelj_V(2005)71:;S35412551;2005;2005-03-11;article;en;71;3;Vladimir Batagelj;Efficient generation of large random networks;
>>> 3 W1981385379
Process: 13 Generalized blockmodeling of two-mode network data
326;W1981385379;TRUE;Doreian_P(2004)26:29;S26186134;2004;2004-01-01;article;en;26;1;29;53;Patrick Doreian;Generalized blockmodeling of two-mode network data;
>>> 4 W2110311637
Process: 14 Comparing resemblance measures
347;W2110311637;TRUE;Batagelj_V(1995)12:73;S73028643;1995;1995-03-01;article;en;12;1;73;90;Vladimir Batagelj;Comparing resemblance measures;
>>> 5 W2083084326
Process: 15 On bibliographic networks
356;W2083084326;TRUE;Batagelj_V(2013)96:845;S148561398;2013;2013-01-20;article;en;96;3;845;864;Vladimir Batagelj;On bibliographic networks;
W 362 Batagelj_V(2010)5:129
>>> 6 W2023723604
Process: 16 Direct and indirect methods for structural equivalence
336;W2023723604;TRUE;Batagelj_V(1992)14:63;S26186134;1992;1992-03-01;article;en;14;1-2;63;90;Vladimir Batagelj;Direct and indirect methods for structural equivalence;
>>> 7 W1967880836
Process: 17 Some analyses of Erdős collaboration graph
305;W1967880836;TRUE;Batagelj_V(2000)22:173;S26186134;2000;2000-05-01;article;en;22;2;173;186;Vladimir Batagelj;Some analyses of Erdős collaboration graph;
W 375 Batagelj_V(1995)12:73
*** OpenAlex2Pajek - Stop Sun Mar 17 19:00:55 2024
act : chr "stop"
df : 'data.frame': 3 obs. of 13 variables:
$ id : chr "https://openalex.org/W2413590293" "https://openalex.org/W1995065687" "https://openalex.org/W2026740782"
$ primary_location :'data.frame': 3 obs. of 8 variables:
$ publication_year : int 2015 2015 2015
$ publication_date : chr "2015-12-01" "2015-02-23" "2015-04-01"
$ type : chr "article" "article" "article"
$ language : chr "en" "en" "en"
$ biblio :'data.frame': 3 obs. of 4 variables:
$ title : chr "Isokinetic Strength Profile of Elite Female Handball Players" "The role of community in the development of elite handball and football players in Denmark" "Technical Activity Profile and Influence of Body Anthropometry on Playing Performance in Female Elite Team Handball"
$ authorships :List of 3
$ countries_distinct_count: int 2 1 2
$ cited_by_count : int 27 26 41
$ referenced_works_count : int 20 14 9
$ referenced_works :List of 3
f : NULL
k : num 1
l : num 8
L : chr [1:7] "W2147991930" "W2008006577" "W1981385379" "W2110311637" "W2083084326" "W2023723604" ...
m : num 0
n : num 17
nr : int 3
Q : List of 5
$ search : chr "handball"
$ filter : chr "publication_year:2015"
$ select : chr "id,primary_location,publication_year,publication_date,type,language,biblio,title,authorships,countries_distinct"| __truncated__
$ per_page: chr "3"
$ cursor : chr "Ils0MTUuNDE3MjQsIDE0Mjc4NDY0MDAwMDAsICdodHRwczovL29wZW5hbGV4Lm9yZy9XMjAyNjc0MDc4MiddIg=="
wc : List of 3
$ meta :List of 6
$ results :'data.frame': 3 obs. of 13 variables:
$ group_by: list()
wd : List of 10
$ url : chr "https://api.openalex.org/works/W1967880836?select=id%2Cprimary_location%2Cpublication_year%2Cpublication_date%2"| __truncated__
$ status_code: int 200
$ headers :List of 23
$ all_headers:List of 1
$ cookies :'data.frame': 0 obs. of 7 variables:
$ content : raw [1:2441] 7b 22 69 64 ...
$ date : POSIXct[1:1], format: "2024-03-17 18:00:55"
$ times : Named num [1:6] 0 0.000032 0 0.000101 0.133043 ...
$ request :List of 7
$ handle :Class 'curl_handle'
works : chr "https://api.openalex.org/works"
works: 375 authors: 54 sources: 14