Comments & more Config

This commit is contained in:
Linsberger Christian 2021-09-06 15:27:49 +02:00
commit 8a1fa79065
3 changed files with 46 additions and 22 deletions

View file

@ -5,66 +5,82 @@ library("xlsx")
source("config/config.R")
#Übernimmt die Liste der zu durchsuchenden Excelfiles aus der Konfiguration
file_list <- FIND_DISTINCTS_FILES
#select all *.xlsx files inside the Input-Folder and put them into a list
file_list <- list.files(PFAD_EXCEL, "*.xlsx")
#Legt eine leere List zum Befüllen an
my_table <- c()
#Liest die Excelfiles ein
for (file in 1:length(file_list)) {
temp_pfad <- paste(PFAD_EXCEL, file_list[file], sep="")
my_table[[file]] <- read_excel(temp_pfad)
}
#select the bibliographicCitation columns in all tables
#Wählt die Spalten aus in denen die Distincts gesucht werden
for(spalte in 1:length(my_table)) {
#Akutelle Spalte in die Liste
df_all <- data.frame(my_table[[spalte]])
#Liefert die Spaltenname die der Vorgabe (COLUMN_NAME) entsprechen
Names <- colnames(my_table[[spalte]])
Names <- Names[grepl("^bibliographicCitation", Names)]
Names <- Names[grepl(paste("^", COLUMN_NAME, sep=""), Names)]
#Legt eine leeren DataFrame an
temp <- data.frame()
for (j in 1:length(Names)) {
#omit empty rows
#Verwirft leere Elemente
df_temp <- na.omit(df_all[Names[j]])
#rename columns
colnames(df_temp) <- (c('bibliographicCitation'))
#benennt die Spalten
colnames(df_temp) <- (c(COLUMN_NAME))
#create a big dataframe
#Fügt die aktuellen Spalte zur Gesamtliste hinzu
temp <- rbind(temp, df_temp)
}
my_table[[spalte]] <- temp
}
#combine all the columns of all tables into one
for (i in 2:length(my_table)) {
my_table[[i]] <- rbind(my_table[[i-1]], my_table[[i]])
#Fügt die Spalten aller Exceldatein zu einer Liste zusammen
if (length(my_table) > 1) {
for (i in 2:length(my_table)) {
my_table[[i]] <- rbind(my_table[[i-1]], my_table[[i]])
}
all <- my_table[[length(my_table)]]
}
all <- my_table[[length(my_table)]]
if (length(my_table) == 1) {
all <- my_table
}
#remove multiple spaces
distincts <- lapply(all, FUN=str_squish)
#get all unique values and sort
#Sucht alle Uniques
distincts <- unique(all)
distincts <- data.frame(distincts[order(distincts$bibliographicCitation), ])
colnames(distincts) <- (c('bibliographicCitation'))
#Sortiert alphabetisch
distincts <- data.frame(distincts[order(distincts$bibliographicCitation), ])
#Benennt die Spalte
colnames(distincts) <- (c(COLUMN_NAME))
#Entfernt Steuerungszeichen
for (i in i:length(distincts$bibliographicCitation)) {
distincts[i, 1] <- gsub("(?<=[\\s])\\s*|^\\s+|\\s+$", "", distincts[i, 1], perl=TRUE)
}
#Sucht nochmals nach den Uniques
distincts <- unique(distincts)
#Entfernt alle Einträge die zu kurz (<THRESHOLD) sind
distincts <- data.frame(distincts[nchar(distincts$bibliographicCitation) >= THRESHOLD, ])
colnames(distincts) <- (c('bibliographicCitation'))
#Schreibt die Distincts in eine Exceldatei
write_xlsx(distincts, "data/Output/distincts_automated_gc3d.xlsx")