Learn R Programming

sumer (version 1.3.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 (left-binding first, right-binding second) and finally applies compositional grouping rules (S+A, S+S, S,S, S+V).

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 algorithm works in four phases:

  1. Existing groups: Recursively process any {...} groups already in the input.

  2. Left-binding operators: Operators with a left argument (e.g. Sx->V) bind their left neighbour first.

  3. Right-binding operators: Operators with a right argument (e.g. xS->V) bind their right neighbour.

  4. Compositional grouping: Remaining elements are grouped by type priority: S+A, then S+S (no punctuation), then S,S (comma), then S+V.

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