ToOrdinal builds compound ordinals with cardinal tens, as in English

Abierto
#998 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
73/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust, yaml

Línea de trabajo

Read hundreds_to_words in src/xpath_functions.rs and the definitions in Rules/Languages/es/definitions.yaml. Check how ToOrdinal selects words for compound numbers, then add the OrdinalCompound behavior described in the issue while preserving the default English output. Done when Spanish compound ordinals use ordinal words for each part and the existing English behavior remains unchanged; the issue does not name a test file.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

ToOrdinal builds 21–99 as cardinal + ordinal, which is right for English ("twenty first") but not for Spanish, where every part is an ordinal:

n Spanish today expected
21 veinte primero vigésimo primero
45 cuarenta quinto cuadragésimo quinto
99 noventa noveno nonagésimo noveno

The cardinal words come from NumbersTens and NumbersHundreds in hundreds_to_words (src/xpath_functions.rs); the Spanish ordinal lists themselves are fine now (fixed in the es-ordinals PR).

Proposed patch: a new definition, OrdinalCompound: ["ordinal"], that a language can set so hundreds_to_words uses the ordinal lists for every part. Languages that don't set it keep today's behavior, so English doesn't change.

-            let mut hundreds = definitions.get_vec("NumbersHundreds")?[number[0]].clone();
+            // in some languages (e.g., Spanish) every part of a compound ordinal is an ordinal ("vigésimo primero"),
+            // not a cardinal followed by an ordinal ("twenty first")
+            let all_ordinal = definitions.get_vec("OrdinalCompound")
+                .is_some_and(|v| v.first().is_some_and(|s| s == "ordinal"));
+            let mut hundreds = if all_ordinal {
+                words[0][number[0]].clone()
+            } else {
+                definitions.get_vec("NumbersHundreds")?[number[0]].clone()
+            };
@@
-                return Some(hundreds + &definitions.get_vec("NumbersTens")?[number[1]] + " " + &words[2][number[2]]);
+                let tens = if all_ordinal {
+                    words[1][number[1]].clone()
+                } else {
+                    definitions.get_vec("NumbersTens")?[number[1]].clone()
+                };
+                return Some(hundreds + &tens + " " + &words[2][number[2]]);

and in Rules/Languages/es/definitions.yaml:

- OrdinalCompound: ["ordinal"]

Spanish doesn't call ToOrdinal for this today: the es-ordinals PR #999 uses two small maps of its own, because of this problem. With the fix, that rule could use ToOrdinal and drop them (the feminine "primera" and the apocope "primer" are built in the rule from the masculine word).

Lenguaje dominante
Rust
Estrellas
131
Forks
97
Merge medio
21 h 45 min
PR fusionados (30 d)
95

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de daisy/MathCAT

Todos los issues de daisy/MathCAT

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.