-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathloadingDatasets.R
230 lines (215 loc) · 7.16 KB
/
loadingDatasets.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#json_folder = 'http://www.lexique.org/databases/_json/'
json_folder = '../../datasets-info/_json/'
#source('../../datasets-info/fetch_datasets.R')
#source('../../apps/openlexicon/www/functions/getMandatory.R')
join_column = "Word"
default_db = "Lexique383"
default_language = "French"
# Les datasets-id sont les noms des json
# Pb avec anagrammes
dataset_ids <-
c('Lexique383',
'Lexique-Infra-bigrammes',
'Lexique-Infra-lettres',
'Lexique-Infra-trigrammes',
'Lexique-Infra-word_frequency',
'AoA_FreqSub_1493',
'AoA_FamConcept_1225',
'Aoa32lang',
'Assoc_520',
'Assoc_366',
'Concr_ContextAv_ValEmo_Arous_1659',
'Concr_Imag_FreqSub_Valemo_866',
'FrenchLexiconProject-words',
'FreqSub_Adulte_Senior_660',
'FreqSub_Imag_ParAge_1286',
'FreqSub_Imag_1916',
'FreqSub_Imag_3600',
'Img_AoA_..._400',
'Imag_1493',
'Manulex-Ortho',
'Manulex-Lemmes',
'Megalex-visual',
'Megalex-auditory',
'SUBTLEX-US',
'RT_LD_NMG_FLP_Mono_1482',
'SensoryExp_1659',
'SensoryExp_1659',
'ValEmo_Arous_Imag_835',
'ValEmo_Arous_1286',
'Valemo_Enfants_600',
'Valemo_Adultes_604',
'Voisins',
'FreqTwitter-WorldLex-French',
'SemantiQc_auditory',
'SemantiQc_familiarity_concept',
'SemantiQc_visual',
'WorldLex-English',
'WorldLex-Afrikaans',
'WorldLex-Albanian',
'WorldLex-Amharic',
'WorldLex-Arabic',
'WorldLex-Armenian',
'WorldLex-Azeri',
'WorldLex-Bengali',
'WorldLex-Bosnian',
'WorldLex-Catalan',
'WorldLex-Chinese-Simplified',
'WorldLex-Croatian',
'WorldLex-Czech',
'WorldLex-Danish',
'WorldLex-Dutch',
'WorldLex-Estonian',
'WorldLex-Finnish',
'WorldLex-Georgian',
'WorldLex-German',
'WorldLex-Greek',
'WorldLex-Greenlandic',
'WorldLex-Gujarati',
'WorldLex-Hebrew',
'WorldLex-Hindi',
'WorldLex-Hungarian',
'WorldLex-Icelandic',
'WorldLex-Indonesian',
'WorldLex-Italian',
'WorldLex-Japanese',
'WorldLex-Kannada',
'WorldLex-Kazakh',
'WorldLex-Khmer',
'WorldLex-Korean',
'WorldLex-Latvian',
'WorldLex-Lithuanian',
'WorldLex-Macedonian',
'WorldLex-Malayalam',
'WorldLex-Malaysian',
'WorldLex-Mongolian',
'WorldLex-Nepali',
'WorldLex-Norwegian',
'WorldLex-Persian',
'WorldLex-Polish',
'WorldLex-Portuguese-Brazil',
'WorldLex-Portuguese-Europe',
'WorldLex-Punjabi',
'WorldLex-Romanian',
'WorldLex-Russian',
'WorldLex-Serbian',
'WorldLex-Sinhala',
'WorldLex-Slovak',
'WorldLex-Slovenian',
'WorldLex-Spanish-Latin-America',
'WorldLex-Spanish-Spain',
'WorldLex-Swahili',
'WorldLex-Swedish',
'WorldLex-Tagalog',
'WorldLex-Tamil',
'WorldLex-Telugu',
'WorldLex-Turkish',
'WorldLex-Ukrainian',
'WorldLex-Urdu',
'WorldLex-Uzbek',
'WorldLex-Vietnamese',
'WorldLex-Welsh',
'SILEX_MasterFile',
'SILEX_FinalLetters',
'SILEX_PhonemeGrapheme',
'SILEX_OrthographicEndings',
'SILEX_PhonologicalCodesGraphemes')
datasets <- list()
# ex_filenames_ds dictionnaire assigns dataset_ids with a tuple (json, rds)
# ex_filenames_ds should be avoided by using the same filename for rds and json files (e.g., Lexique383.json, Lexique383.rds). In cases where json and rds do not have the same filename, we can use ex_filenames_ds. json is the first element of the tuple, and rds the second.
ex_filenames_ds <- list(
'FrenchLexiconProject-words' = c('RT_FrenchLexiconProject-words', 'flp-words'),
'FreqTwitter-WorldLex-French' = c('WorldLex-French','WorldLex_FR'),
'WorldLex-English' = c('WorldLex-English', 'WorldLex_EN'),
'Manulex-Ortho' = c('Manulex', 'Manulex-Ortho'),
'Manulex-Lemmes' = c('Manulex', 'Manulex-Lemmes'),
'Aoa32lang' = c('AoA-32lang', 'AoA32lang'),
'SUBTLEX-US' = c('SUBTLEX-US', 'SUBTLEXus'),
'anagrammes' = c('anagrammes', 'Anagrammes')
)
# Capitalize word
capFirst <- function(s) {
paste(toupper(substring(s, 1, 1)), substring(s, 2), sep = "")
}
load_tables <- function(ds_list, my_tables){
for (ds in names(my_tables)){
if (!(ds %in% ds_list)){
my_tables[[ds]] <- NULL
}
}
for (ds in ds_list){
if (!(ds %in% names(my_tables))){
new_table <- load_dataset_table(ds)
if (!is.null(new_table)){
my_tables[[ds]] <- new_table
}
}
}
return(my_tables)
}
load_dataset_table <- function(ds){
my_table <<- NULL
tryCatch({
json_url <- datasets[[ds]][1]
rds_file <- datasets[[ds]][2]
my_table <<- fix.encoding(readRDS(get_dataset_from_json(json_url, rds_file)))
},
error = function(e) {
message(paste("Couldn't load database ", ds, ". Check json and rds files.", sep = ""))
}
)
# Removes not loaded datasets from the list
if (is.null(my_table)) { datasets[[ds]] <<- NULL} else {
colnames(my_table)[1] <<- join_column
json_url <- datasets[[ds]][1]
info = get_info_from_json(json_url)
# Column names description
for (j in 2:length(colnames(my_table))) {
current_colname = colnames(my_table)[j]
if (typeof(info$column_names[[current_colname]]) == "NULL"){
dictionary_databases[[ds]][["colnames_dataset"]][[current_colname]] <<- ""
}
else{
dictionary_databases[[ds]][["colnames_dataset"]][[current_colname]] <<- info$column_names[[current_colname]]
}
}
if (is.null(dictionary_databases[[ds]][["dsmandcol"]])) {
dictionary_databases[[ds]][["dsmandcol"]] <<- names(dictionary_databases[[ds]][["colnames_dataset"]])
}
}
return(my_table)
}
for (ds in dataset_ids)
{
#datasets[[ds]] <- fetch_dataset(ds, format='rds')
rds_file <- ds
json_file <- ds
if (!is.null(ex_filenames_ds[[ds]])) {
json_file <- ex_filenames_ds[[ds]][1]
rds_file <- ex_filenames_ds[[ds]][2]
}
datasets[[ds]] = c(paste(json_folder,json_file,'.json', sep = ""),
paste(rds_file,'.rds', sep = ""))
}
dictionary_databases <- list()
dslanguage <- list()
language_choices <- c("\n")
for (ds in names(datasets)) {
json_url <- datasets[[ds]][1]
info = get_info_from_json(json_url)
dslanguage[[ds]]['name'] <- info$language
if (!(dslanguage[[ds]]['name'] %in% language_choices)){
language_choices <- c(language_choices, capFirst(dslanguage[[ds]]['name']))
}
dictionary_databases[[ds]] <- list()
dictionary_databases[[ds]][["dsdesc"]] <- info$description
dictionary_databases[[ds]][["dsreadme"]] <- info$readme
dictionary_databases[[ds]][["dsweb"]] <- info$website
dictionary_databases[[ds]][["colnames_dataset"]] <- list()
# Load Lexique from the start since this is our default language
if (ds == default_db){
load_dataset_table(ds)
}
dictionary_databases[[ds]][["dsmandcol"]] <- get_mandatory_columns(ds, info, dictionary_databases)
}
language_choices <- unique(language_choices)