R/tier_has_content.R

Defines functions tier_has_content

Documented in tier_has_content

#' tier_has_content Function
#'
#' This function simply tests whether ELAN file has a tier or not
#' @param eaf_file The path to ELAN file which we want to parse
#' @param tier Tier name
#' @param value Whether the function should return the number of items on the tier instead of a boolean value
#' @keywords ELAN
#' @export
#' @examples
#' tier_has_content("path/to/elan/file.eaf", "orth@NTP-M-1986")

tier_has_content <- function(eaf_file, tier, value = F){

        `%>%` <- dplyr::`%>%`

        if (tier_exists(eaf_file = eaf_file, tier = tier) == F){
                FALSE
        } else {
                tier_content <- xml2::read_xml(eaf_file) %>%
                        xml2::xml_find_all(
                                xpath = paste0("//TIER[@TIER_ID='", tier, "']/ANNOTATION/*/ANNOTATION_VALUE")) %>%
                        xml2::xml_text()
                tier_content
                }

        if (value == FALSE && tier_exists(eaf_file = eaf_file, tier = tier) == T) {
                result <- length(tier_content) > 0
                result
        }

        if (value == T && tier_exists(eaf_file = eaf_file, tier = tier) == T) {
                length(tier_content)
        }
}
langdoc/FRelan documentation built on May 20, 2019, 7:55 p.m.