R/test_reversals_ok.R

Defines functions test_reversals_ok

Documented in test_reversals_ok

#' Test that reversal mark up in reversal and gloss lines are well-formed
#'
#' @param wlp_lexicon a Warlpiri lexicon data frame, or path to a Warlpiri dictionary file
#'
#' @importFrom stringr str_detect str_remove_all
#' @importFrom purrr keep
#'
#' @export
#'

test_reversals_ok <- function(wlp_lexicon) {

    rv_test_func <- function(rv_string) {
        list(
            "consecutive carets"          = "\\^{2,}",
            "un-careted starting bracket" = "(?<!\\^)\\[",
            "final comma"                 = ",\\s*\\\\e(rv|gl)"
        ) %>%
        keep(~ str_detect(rv_string, .)) %>%
        names(.) %>%
        paste0(collapse = ", ")
    }

    wlp_lexicon %>%
        make_wlp_df() %>%
        filter(code1 %in% c("rv", "gl")) %>%
        mutate(
            data  = str_remove_all(data, use_wlp_regex("source_codes")),
            error = map_chr(data, rv_test_func)
        ) %>%
        filter(nzchar(error))

}
CoEDL/yinarlingi documentation built on Feb. 20, 2020, 4:30 a.m.