#' Structure Interview Transcript by Speaker
#'
#' This function structures an interview transcript to identify
#' consecutive lines spoken by the same speaker. It uses run-length
#' encoding (rle) after extracting speaker identifiers from bracketed
#' tags in the text.
#'
#' @param interview A character vector representing the interview 
#'   transcript, where each line is tagged with a speaker's name 
#'   enclosed in square brackets (e.g., "\[Speaker1\] This is a line").
#'
#' @return An object of class "rle" containing information about 
#'   the lengths and values of consecutive lines spoken by the same
#'   speaker.  The `values` component contains speaker names, and
#'   `lengths` indicates how many consecutive lines each speaker spoke.
#'
#' @examples
#' # Example usage:
#' interview_structure = so.ii:::structure_interview(intrw)
#'
#' @family process interview
#' 
#' @keywords internal

structure_interview = function(interview){
    structure = rle(
        gsub(
            pattern = "^(\\[)([A-Z_0-9]+)(\\])(.*)", 
            replacement = "\\2", 
            x = interview
        )
    )
    return(structure)
}