@@ -143,9 +143,13 @@ replace_keywords_if_empty <- function(metadata, stops) {
143143 vplog $ info(paste(" vis_id:" , .GlobalEnv $ VIS_ID , " Documents without subjects after replacing from title:" , length(missing_subjects )))
144144 if (length(missing_subjects ) > 0 ) {
145145 foreach (i = missing_subjects ) %dopar % {
146- candidates = mapply(paste , metadata $ title [i ], metadata $ paper_abstract [i ])
146+ if (nrow(metadata ) == 1 ) {
147+ candidates = mapply(paste , metadata $ title , metadata $ paper_abstract )
148+ } else {
149+ candidates = mapply(paste , metadata $ title [i ,], metadata $ paper_abstract [i ,])
150+ }
147151 for (i in seq(1 , total_length , batch_size )) {
148- candidates = mclapply(candidates , function (x )paste(removeWords(x , stops [i : min(i + batch_size - 1 , total_length )]), collapse = " " ))
152+ candidates = mclapply(candidates , function (x )paste(removeWords(x , stops [i : min(i + batch_size - 1 , total_length )]), collapse = " " ))
149153 }
150154 candidates = lapply(candidates , function (x ) {gsub(" [^[:alpha:]]" , " " , x )})
151155 candidates = lapply(candidates , function (x ) {gsub(" +" , " " , x )})
@@ -155,7 +159,11 @@ replace_keywords_if_empty <- function(metadata, stops) {
155159 replacement_keywords <- filter_out_nested_ngrams(names(nn_count ), 3 )
156160 replacement_keywords = lapply(replacement_keywords , FUN = function (x ) {paste(unlist(x ), collapse = " ; " )})
157161 replacement_keywords = gsub(" _" , " " , replacement_keywords )
158- metadata $ subject [i ] <- paste(replacement_keywords , collapse = " ; " )
162+ if (nrow(metadata ) == 1 ) {
163+ metadata $ subject <- paste(replacement_keywords , collapse = " ; " )
164+ } else {
165+ metadata $ subject [i ] <- paste(replacement_keywords , collapse = " ; " )
166+ }
159167 }
160168 }
161169 return (metadata )
0 commit comments