hslld <- chitb |>
# clean file name: keep only the base name between the last / and .cha
dplyr::mutate(files = gsub(".*/(.*?)\\.cha", "\\1", files)) |>
# speaker: everything before the first colon; strip remaining non-word characters
dplyr::mutate(
speaker = stringr::str_remove_all(rawcontent, ":.*"),
speaker = stringr::str_remove_all(speaker, "\\W")
) |>
# utterance: remove POS tier (%mor:...), all other % tiers, and speaker codes (*XXX:)
dplyr::mutate(
utterance = stringr::str_remove_all(rawcontent, "%mor:.*"),
utterance = stringr::str_remove_all(utterance, "%.*"),
utterance = stringr::str_remove_all(utterance, "\\*\\w{2,6}:"),
utterance = stringr::str_squish(utterance)
) |>
# postag: the %mor: tier — remove everything before it, then strip other tiers
dplyr::mutate(
postag = stringr::str_remove_all(rawcontent, ".*%mor:"),
postag = stringr::str_remove_all(postag, "%.*"),
postag = stringr::str_remove_all(postag, "\\*\\w{2,6}:"),
postag = stringr::str_squish(postag)
) |>
# comment: the %sit: tier — non-greedy .*? stops at the first %
dplyr::mutate(
comment = stringr::str_remove_all(rawcontent, ".*%mor:"),
comment = stringr::str_remove(comment, ".*?%"),
comment = stringr::str_remove_all(comment, ".*|.*"),
comment = stringr::str_squish(comment)
) |>
# metadata fields extracted from the CHAT file header
dplyr::mutate(
participants = gsub(".*@Participants:(.*?)@.*", "\\1", fileinfo),
# child age encoded as "years;months.days" in the header
age_targetchild = gsub(".*\\|([0-9]{1,3};[0-9]{1,3}\\.[0-9]{1,3})\\|.*", "\\1", fileinfo),
age_years_targetchild = stringr::str_remove_all(age_targetchild, ";.*"),
gender_targetchild = gsub(".*\\|([female]{4,6})\\|.*", "\\1", fileinfo),
dob_targetchild = gsub(".*@Birth of CHI:(.*?)@.*", "\\1", fileinfo),
comment_file = gsub(".*@Comment: (.*?)@.*", "\\1", fileinfo),
date = gsub(".*@Date: (.*?)@.*", "\\1", fileinfo),
location = gsub(".*@Location: (.*?)@.*", "\\1", fileinfo),
situation_raw = gsub(".*@Situation: (.*?)@.*", "\\1", fileinfo),
activity = gsub(".*@Activities: (.*?)@.*", "\\1", fileinfo),
homevisit = stringr::str_sub(files, 4, 6)
) |>
# word count per utterance (count word tokens)
dplyr::mutate(
words = stringr::str_replace_all(utterance, "\\W", " "),
words = stringr::str_squish(words),
words = stringr::str_count(words, "\\w+")
) |>
# remove empty rows (no speaker) and rows with malformed age strings
dplyr::filter(speaker != "", nchar(age_years_targetchild) < 5) |>
# drop raw columns, rename, add corpus metadata, decode activity codes
dplyr::select(-fileinfo, -rawcontent, -situation_raw) |>
dplyr::rename(transcript_id = files) |>
dplyr::mutate(
collection = "EngNA",
corpus = "HSLLD",
visit = substr(transcript_id, 6, 6),
situation = substr(transcript_id, 4, 5),
situation = stringr::str_replace_all(situation, "br", "Book reading"),
situation = stringr::str_replace_all(situation, "er", "Elicited report"),
situation = stringr::str_replace_all(situation, "et", "Experimental task"),
situation = stringr::str_replace_all(situation, "lw", "Letter writing"),
situation = stringr::str_replace_all(situation, "md", "Mother-defined"),
situation = stringr::str_replace_all(situation, "mt", "Mealtime"),
situation = stringr::str_replace_all(situation, "re", "Reading"),
situation = stringr::str_replace_all(situation, "tp", "Toy play")
)