Learn R Programming

sumer (version 1.4.0)

apply_translation_rules: Apply Translation Rules to a Bracketed Structure String

Description

Translates a bracketed structure string into English by evaluating sumerian operators (substituting arguments into translation templates) and composing adjacent elements according to grammatical rules. The input is a structure string as produced by add_brackets, together with vectors of types and translations for each tag.

Usage

apply_translation_rules(s, type, translation)

Value

A character vector of length 2: c(result_type, result_translation).

On error (e.g. incompatible types), a character vector of length 1 containing the error message.

Arguments

s

Character string showing the order of evaluation, as produced by add_brackets.

type

Character vector of grammatical types. type[k] is the type string for tag #k (e.g. "S", "V", "Sx->V").

translation

Character vector of translations. translation[k] is the translation for tag #k. Operator translations contain placeholders (e.g. "to deliver S").

Details

Nested {...} groups are evaluated from the inside out. Within each group, an operator (if present) binds its arguments and produces a typed result. Groups without an operator are composed according to the rules described in eval_operator.

See Also

eval_operator for the evaluation rules, add_brackets for the previous pipeline step, compose_skeleton_entry which calls this function

Examples

Run this code
x <- "mec3-ki-aj2-ga-ce-er"
x <- as.cuneiform(x)
x

meaning <- rbind( c("S",      "a man who relies on his own strength"),
                  c("S",      "place {earth}"),
                  c("Sx->A",  ", whose allocated resource is S"),
                  c("xS->A",   ", whose sustenance is S"),
                  c("S",      "grain"),
                  c("Sx->S",  "lamented S"))

df <- data.frame(
    type  = meaning[,1],
    translation = meaning[,2],
    expr  = split_sumerian(x)$signs)

s <- x
for(i in 1:nrow(df)){
 s <- sub(df$expr[i], paste0("#", i), s)
}
s

s_bracketed <- sumer:::add_brackets(s, df$type)
s_bracketed

apply_translation_rules(s_bracketed$string, df$type, df$translation)

Run the code above in your browser using DataLab