Learn R Programming

sumer (version 1.4.0)

translate_line: Line-by-Line Translation of a Sumerian Text

Description

translation_context bundles the settings for a translation project: the project directory (with a lines/ subfolder for saving line files), the dictionaries, the source text, and parameters for the interactive translator.

translate_line opens the interactive translation tool (translate) for a single line. If a saved translation exists for this line, it is loaded so that previous work can be continued. When the user clicks “Done”, the result is saved back to the line file.

Usage

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

translate_line(n, context)

Value

translation_context returns a list of class "translation_context".

translate_line is called for its side effect (opening the interactive translator and saving the result). Returns NULL invisibly.

Arguments

project_dir

Character string. Path to the project directory. Translated lines are saved in the subdirectory lines/ as Line_1.txt, Line_2.txt, etc. If text or dic are given as filenames without a path, they are assumed to reside in project_dir.

dic

Dictionaries to use for translation lookup. A character vector of file paths (or filenames relative to project_dir), a single data frame, or a list of data frames. The first dictionary serves as the primary source. Additional dictionaries serve as fallback references. If NULL, the built-in dictionary is used.

text

The full text being translated. A file path (or filename relative to project_dir) or a character vector (one line per element). Needed for n-gram analysis and context display in translate.

mapping

A data frame with the sign mapping table, or a file path to a semicolon-separated mapping file. If NULL (the default), the package's internal mapping is used.

min_freq

Minimum frequency thresholds passed to translate. Default is c(6, 4, 2).

sentence_prob

Probability that a randomly chosen sign is part of a sentence with a verb, passed to translate. Default is 1.0.

n

An integer line number. If a file Line_<n>.txt exists in the lines/ subdirectory of project_dir, the saved translation is loaded for revision. Otherwise, the most frequent translation for each substring is looked up in the dictionaries.

context

A context object as created by translation_context.

Details

translate_line performs the following steps:

  1. If Line_<n>.txt exists in the lines/ subdirectory, the cuneiform text and previous translations are loaded via fill_substr_info.

  2. A project dictionary is built from saved line files using make_dictionary. Line n itself is excluded to avoid confirmation bias.

  3. The interactive translator (translate) is opened with the primary dictionary, the project dictionary, and any additional dictionaries as fallback references.

  4. If the user clicks “Done”, the result is saved to Line_<n>.txt. If the window is closed in another way, the result is not saved.

See Also

translate for the underlying interactive translation tool, fill_substr_info for reading back a saved translation, make_dictionary for creating a dictionary from translated lines

Examples

Run this code
# Note: The folder containing the built-in project
#       is copied to a temporary directory.
#       This prevents you from altering the package files.

path  <- system.file("extdata", package = "sumer")

file.copy(
  from = file.path(path, "project"),
  to   = tempdir(),
  recursive = TRUE
)

ctx <- translation_context(
  project_dir = file.path(tempdir(), "project"),
  text        = "enki_and_the_world_order.txt",
  dic         = file.path(path, "sumer-dictionary.txt"),
  sentence_prob = 0.25
)
ctx

if (FALSE) {
# Translate line 29 (opens interactive translator)
translate_line(29, ctx)

# Confirm that your changes are still there:
translate_line(29, ctx)

# Continue with the next line:
translate_line(30, ctx)
}

Run the code above in your browser using DataLab