WoS2Pajek 1.2 (September 2013) creates also a csv file titles.csv
with works names and their title, first author, journal and year of publication. This file can be merged with a subnetwork (island) net file to produce a list of titles of works contained in the subnetwork. It uses the Python csv library.
> setwd("E:/Data/Centrality/net") > Code <- function(x) paste(substr(unlist(strsplit(x," ")),1,1),collapse="") > T <- read.csv('../WoS/titles.csv',sep=";",colClasses="character") > dim(T) [1] 38535 6 > names(T) [1] "name" "WoSline" "author" "title" "journal" "year" > T$WoSline <- as.integer(T$WoSline) > T$year <- as.integer(T$year) > n <- nrow(T) > cod <- character(n) > for(i in 1:n) cod[i] <- Code(as.character(T$journal[i])) > T$code <- cod > save(T,file="titlesCentr.Rdata") > dim(T) [1] 38535 7
# # description produces a csv file csvFile containing a table with columns # (name, WoSline, author, title, journal, year, code) # for vertices of a subnetwork from file netFile. # The titles for all (DC>0) vertices are stored in the table T. # Since for vertices with DC=0 the title is not available it takes '***'. # # Vladimir Batagelj, September 7, 2013 / August 19, 2013 # description <- function(netFile,csvFile,T){ f <- function(L){ s <- unlist(strsplit(L,"[[:space:]]+")) if(s[1]=="") t <- s[3] else t <- s[2] t <- substr(t,2,nchar(t)-1) if(substr(t,1,1)=="=") t <- substr(t,2,nchar(t)) return(t) } net <- file(netFile,"r") L <- readLines(net,n=1) n <- as.integer(unlist(strsplit(L,"[[:space:]]+"))[2]) S <- readLines(net,n=n); close(net) N <- gsub("'","'",unlist(lapply(S,f))) nn <- length(N); tit <- character(nn); aut <- character(nn); jrn <- character(nn); cod <- character(nn); wos <- integer(nn); yer <- integer(nn) for(k in 1:nn){j <- which(T$name==N[k]); tit[k] <- ifelse(length(j)==0,NA,T$title[j]) aut[k] <- ifelse(length(j)==0,NA,T$author[j]) wos[k] <- ifelse(length(j)==0,NA,T$WoSline[j]) jrn[k] <- ifelse(length(j)==0,NA,T$journal[j]) cod[k] <- ifelse(length(j)==0,NA,T$code[j]) yer[k] <- ifelse(length(j)==0,NA,T$year[j]) if(is.na(yer[k])){ l <- regexpr("(",N[k],fixed=TRUE)[1]+1 r <- regexpr(")",N[k],fixed=TRUE)[1]-1 yer[k] <- as.integer(substr(N[k],l,r)) } } D <- data.frame(name=as.character(N),WoSline=wos,author=as.character(aut), title=as.character(tit),journal=as.character(jrn),year=yer,code=as.character(cod)) write.csv2(D,file=csvFile,fileEncoding="UTF-8",row.names=FALSE,quote=FALSE) return(D) }
Application:
> setwd("E:/Data/Centrality/net") > load("titlesCentr.Rdata") > names(T) [1] "name" "WoSline" "author" "title" "journal" "year" "code" > dim(T) [1] 38535 7 > source("E:\\Data\\Centrality\\net\\res\\description.R") > d <- description("./res/island2.net","./res/island2new.csv",T)
WoS2Pajek 1.2 (August 2013) creates also a csv file titles.csv
with works names and their titles. This file can be merged with a subnetwork (island) net file to produce a list of titles of works contained in the subnetwork.
> setwd("D:/Data/Centrality/WoS") > T <- read.csv("titles.csv",header=FALSE,sep="÷",quote="",colClasses="character") > t <- T$V1[1] > s <- substr(t,23,23) > U <- as.data.frame(matrix(unlist(strsplit(T$V1,s)),ncol=2,byrow=TRUE)) > names(U) <- c("name","title") > library(gdata) > U$title <- trim(U$title) > T$name <- as.character(U$name) > T$title <- as.character(U$title) > write.table(T,file="CentTitles.csv",sep=";",qmethod="double",row.names=FALSE) > save(T,file="CentTitles.Rdata") > write.table(T,file="CentTit.csv",sep=";",fileEncoding="UTF-8",qmethod="double",row.names=FALSE,quote=FALSE)
Function in R to create a list:
# # description produces a csv file csvFile containing a table with columns # (name, year, title) for vertices of a subnetwork from file netFile. # The titles for all (DC>0) vertices are stored in the table T. # Since for vertices with DC=0 the title is not available it takes '***'. # # Vladimir Batagelj, August 19, 2013 # description <- function(netFile,csvFile,T){ f <- function(L){ s <- unlist(strsplit(L,"[[:space:]]+")) if(s[1]=="") t <- s[3] else t <- s[2] t <- substr(t,2,nchar(t)-1) if(substr(t,1,1)=="=") t <- substr(t,2,nchar(t)) return(t) } getYear <- function(x){ i <- regexpr('\\(',x)[1]+1; j <- regexpr('\\)',x)[1]-1 ifelse(i<j,as.integer(substr(x,i,j)),-1) } net <- file(netFile,"r") L <- readLines(net,n=1) n <- as.integer(unlist(strsplit(L,"[[:space:]]+"))[2]) S <- readLines(net,n=n); close(net) N <- gsub("'","'",unlist(lapply(S,f))) year <- unlist(lapply(N,getYear)) nn <- length(N); tit <- character(nn) for(k in 1:nn){j <- which(T$name==N[k]); tit[k] <- ifelse(length(j)==0,"***",T$title[j])} D <- data.frame(name=as.character(N),year=year,title=as.character(tit)) write.table(D,file=csvFile,sep=";",fileEncoding="UTF-8",qmethod="double",row.names=FALSE) return(D) } # setwd("D:/Data/Centrality/net") # source("D:\\Data\\Centrality\\net\\res\\description.R") # T <- read.csv("CentTitles.csv",header=TRUE,sep=";",colClasses="character") # d <- description("mainPath.net","mainPath.csv",T) # d <- description("islands2.net","islands2.csv",T)
Application:
setwd("D:/Data/Centrality/net") source("D:\\Data\\Centrality\\net\\res\\description.R") T <- read.csv("../WoS/CentTitles.csv",header=TRUE,sep=";",colClasses="character") d <- description("./res/mainPath.net","./res/mainPath.csv",T)
Instead of the command T ← read.csv
we can use also
T <- load("CentTitles.Rdata")