Skip to content

Commit 12ab7c8

Browse files
authored
Merge pull request #734 from OpenKnowledgeMaps/single-item-keyword-bugfix
Single item keyword bugfix
2 parents d7b9353 + 2bc5e18 commit 12ab7c8

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

server/preprocessing/other-scripts/preprocess.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

server/workers/base/renv.lock

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@
199199
"renv": {
200200
"Package": "renv",
201201
"Version": "0.14.0",
202-
"Source": "Repository",
203-
"Repository": "CRAN",
204-
"Hash": "30e5eba91b67f7f4d75d31de14bbfbdc"
202+
"Source": "Repository"
205203
},
206204
"rlang": {
207205
"Package": "rlang",

0 commit comments

Comments
 (0)