Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions scripts/aggregation-helper-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -299,23 +299,19 @@ order_ipa <- function(strings, keep_stars=FALSE, keep_brackets=TRUE) {
}
## If a diacritic comes right after a modifier letter, swap their order
if (stri_detect_fixed(typestring, "MD")) {
ixs <- stri_locate_all_fixed(typestring, "MD")[[1]]
for (row in seq_len(dim(ixs)[1])) {
ix <- ixs[row, 1]
if (string[ix] %in% clicks) next
# SWAP LOGIC REMAINS SAME
} }

ix <- stri_locate_first_fixed(typestring, "MD")[1]
# If the modifier letter is a click, don't swap it with the diacritic
if (string[ix] %in% clicks) break
if (ix == 1) neworder <- c(2, 1, 3:lenstr)
else if (ix == lenstr-1) neworder <- c(1:(ix-1), ix+1, ix)
else neworder <- c(1:(ix-1), ix+1, ix, (ix+2):lenstr)
string <- string[neworder]
typstr <- typstr[neworder]
typestring <- paste(typstr, collapse="")
}
ixs <- stri_locate_all_fixed(typestring, "MD")[[1]]
# Iterate through the rows of the matrix of indices, swapping modifier and diacritic.
for (row in seq_len(dim(ixs)[1])) {
ix <- ixs[row, 1]
# If the modifier letter is a click, don't swap it with the diacritic
if (string[ix] %in% clicks) next
if (ix == 1) neworder <- c(2, 1, 3:lenstr)
else if (ix == lenstr-1) neworder <- c(1:(ix-1), ix+1, ix)
else neworder <- c(1:(ix-1), ix+1, ix, (ix+2):lenstr)
string <- string[neworder]
typstr <- typstr[neworder]
typestring <- paste(typstr, collapse="")
} }
## Put sequences of modifier letters in canonical order
if (stri_detect_fixed(typestring, "MM")) {
ixs <- stri_locate_all_regex(typestring, "M+")[[1]]
Expand Down
Loading