From fa827f27f4aa032065fed2c6d375acdcf52b85a4 Mon Sep 17 00:00:00 2001 From: Matthijs Berends Date: Wed, 7 Jan 2026 11:00:58 +0100 Subject: [PATCH] (v3.0.1.9012) fix translations --- DESCRIPTION | 4 ++-- NEWS.md | 2 +- R/ab_property.R | 2 +- R/translate.R | 30 ++++++++++++------------------ 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c9c2f25e5..9c54ab616 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: AMR -Version: 3.0.1.9008 -Date: 2026-01-06 +Version: 3.0.1.9012 +Date: 2026-01-07 Title: Antimicrobial Resistance Data Analysis Description: Functions to simplify and standardise antimicrobial resistance (AMR) data analysis and to work with microbial and antimicrobial properties by diff --git a/NEWS.md b/NEWS.md index 155d0c23f..8ee26a8e8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# AMR 3.0.1.9008 +# AMR 3.0.1.9012 ### New * Integration with the **tidymodels** framework to allow seamless use of SIR, MIC and disk data in modelling pipelines via `recipes` diff --git a/R/ab_property.R b/R/ab_property.R index 75de8cbf1..8700f086f 100755 --- a/R/ab_property.R +++ b/R/ab_property.R @@ -301,7 +301,7 @@ ab_info <- function(x, language = get_AMR_locale(), ...) { ab = as.character(x), cid = ab_cid(x), name = ab_name(x, language = language), - group = ab_group(x, language = language), + group = ab_group(x, language = language, all_groups = TRUE), atc = ab_atc(x), atc_group1 = ab_atc_group1(x, language = language), atc_group2 = ab_atc_group2(x, language = language), diff --git a/R/translate.R b/R/translate.R index 96792049f..245fac1da 100755 --- a/R/translate.R +++ b/R/translate.R @@ -279,29 +279,23 @@ translate_into_language <- function(from, } ) # non-regex part + translate_tokens <- function(tokens) { + patterns <- df_trans$pattern[df_trans$regular_expr == FALSE] + replacements <- df_trans[[lang]][df_trans$regular_expr == FALSE] + matches <- match(tokens, patterns) + tokens[!is.na(matches)] <- replacements[matches[!is.na(matches)]] + tokens + } from_unique_translated <- vapply( FUN.VALUE = character(1), USE.NAMES = FALSE, from_unique_translated, function(x) { - words <- strsplit(x, " ", fixed = TRUE)[[1]] - # print(words) - for (i in seq_along(words)) { - word_trans <- df_trans[[lang]][df_trans$regular_expr == FALSE][match(words[i], df_trans$pattern[df_trans$regular_expr == FALSE])] - if (!is.na(word_trans)) { - words[i] <- word_trans - } - } - words <- paste(words, collapse = " ") - words <- strsplit(x, "/", fixed = TRUE)[[1]] - # print(words) - for (i in seq_along(words)) { - word_trans <- df_trans[[lang]][df_trans$regular_expr == FALSE][match(words[i], df_trans$pattern[df_trans$regular_expr == FALSE])] - if (!is.na(word_trans)) { - words[i] <- word_trans - } - } - paste(words, collapse = " ") + delimiters <- "[ /()]" + split_regex <- paste0("(?<=", delimiters, ")|(?=", delimiters, ")") + tokens <- strsplit(x, split_regex, perl = TRUE)[[1]] + tokens <- translate_tokens(tokens) + paste(tokens, collapse = "") } )