

translation_context <- function(project_dir, dic = NULL, text = NULL,
                                mapping = NULL, min_freq = c(6, 4, 2),
                                sentence_prob = 1.0) {

  line_folder <- file.path(project_dir, "lines")

  # Add project_dir to text if it is a filename without path
  if (!is.null(text) && is.character(text) && length(text) == 1 &&
      !grepl("[/\\\\]", text)) {
    text <- file.path(project_dir, text)
  }

  # Add project_dir to dic entries that are filenames without path
  if (is.character(dic)) {
    no_path <- !grepl("[/\\\\]", dic)
    dic[no_path] <- file.path(project_dir, dic[no_path])
  }

  structure(
    list(
      project_dir   = project_dir,
      line_folder   = line_folder,
      dic           = dic,
      text          = text,
      mapping       = mapping,
      min_freq      = min_freq,
      sentence_prob = sentence_prob
    ),
    class = "translation_context"
  )
}
