Learn R Programming

sumer (version 1.3.0)

compose_skeleton_entry: Compose a Skeleton Entry from its Children

Description

Composes the type and translation fields of a parent skeleton entry from the corresponding fields of its direct children, following the rules of the Sumerian type system. This function is called by translate when the user clicks the brown compose button next to a skeleton entry.

Usage

compose_skeleton_entry(df)

Value

Either the input data frame df with the type and translation fields of the first row filled in, or a character string containing an error message.

Arguments

df

A data frame with \(n + 1\) rows, where the first row represents the parent entry and the remaining \(n\) rows represent its direct children in the skeleton hierarchy.

The data frame has the following columns:

expr

Character. The expression of the entry.

n_tokens

Integer. Number of tokens covered by the entry.

start

Integer. Position (1-based) of the first token.

depth

Integer. Nesting depth in the skeleton hierarchy.

type

Character. The grammatical type annotation: "S" (substantive), "V" (verb), "A" (adjective/attribute), or an operator type like "xS->S".

translation

Character. The translation. Operator translations contain type-letter placeholders (e.g. "S" in "supplier of energy from S").

Details

The algorithm works in four steps:

  1. Structure string: Build a structure string by replacing each child's expression in the parent expression with a numbered tag (#1, #2, etc.). Token-group wrappers (<> and single-tag {}) are removed.

  2. Bracket insertion: add_brackets groups operators with their arguments and applies compositional rules (S+A, S+S, S+V, SEN+SEN).

  3. Translation: apply_translation_rules recursively evaluates the bracketed string to produce the final translation.

See Also

add_brackets, apply_translation_rules for the individual pipeline steps, translate which calls this function

Examples

Run this code
# Minimal example: S + Sx->V
df <- data.frame(
  expr = c("#1 #2", "#1", "#2"),
  n_tokens = c(2L, 1L, 1L),
  start = c(1L, 1L, 2L),
  depth = c(0L, 1L, 1L),
  type = c("", "S", "Sx->V"),
  translation = c("", "temple", "to utilize S"),
  stringsAsFactors = FALSE
)
result <- sumer:::compose_skeleton_entry(df)
stopifnot(result$type[1] == "V")
stopifnot(result$translation[1] == "to utilize the temple")
cat("compose_skeleton_entry check passed.\n")

Run the code above in your browser using DataLab