Learn R Programming

sumer (version 1.4.0)

add_brackets: Add Brackets to a Structure String

Description

Inserts curly braces into a structure string so that operators are grouped with their arguments and remaining elements are grouped by compositional rules.

The function processes {...} groups already present in the input recursively, then resolves operator binding and compositional grouping rules according to a priority list.

Usage

add_brackets(s, type)

Value

A list with two elements:

string

The structure string with all brackets inserted.

type

The resulting type of the outermost group ("S", "V", "SEN", or "ERROR").

Arguments

s

Character string containing #N tags and optional {...} groups, as produced by step a of compose_skeleton_entry.

type

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

Details

The function first recursively processes any {...} groups already present in the input. Then it applies rules from a priority list, restarting after each successful match:

  1. Pipe rules: Operators whose result type matches the first argument's base type (the type "flows through").

  2. Explicit rules: Specific operator types bound by exact match (e.g. xS->A).

  3. General operator rules: Any remaining operators that match their argument types.

  4. Compositional grouping: Adjacent elements are grouped by type: S+A, S,S (comma), S+Vt, S+S, S+Vi, S+V, SEN+SEN.

If operators cannot find matching arguments, an error is returned.

See Also

apply_translation_rules for the next step (translating the bracketed string), 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))
apply_translation_rules(s_bracketed$string, df$type, df$translation)

Run the code above in your browser using DataLab