summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Maa <jmaa@berkeley.edu>2024-06-24 09:56:02 -0700
committerGitHub <noreply@github.com>2024-06-24 16:56:02 +0000
commitcfa33c8f5d77b2365abc3715c31d18f52135897b (patch)
tree7d9d7037f29e86677f5cd0d089866f457b2149b4
parentb584c5440721fa7399564ced57f134fd5333d20c (diff)
More Spanish transforms (#1100)
* Preterite and spanish bench * More spanish forms * Rename
-rw-r--r--benches/japanese-language-transformer.bench.js (renamed from benches/language-transformer.bench.js)6
-rw-r--r--benches/spanish-language-transformer.bench.js140
-rw-r--r--ext/js/language/es/spanish-transforms.js490
-rw-r--r--test/language/spanish-transforms.test.js143
4 files changed, 742 insertions, 37 deletions
diff --git a/benches/language-transformer.bench.js b/benches/japanese-language-transformer.bench.js
index d06fd963..7f4922c2 100644
--- a/benches/language-transformer.bench.js
+++ b/benches/japanese-language-transformer.bench.js
@@ -22,7 +22,7 @@ import {LanguageTransformer} from '../ext/js/language/language-transformer.js';
const languageTransformer = new LanguageTransformer();
languageTransformer.addDescriptor(japaneseTransforms);
-describe('language transformer', () => {
+describe('japanese language transformer', () => {
describe('basic tests', () => {
const adjectiveInflections = [
'愛しい',
@@ -199,14 +199,14 @@ describe('language transformer', () => {
];
const basicTransformations = [...adjectiveInflections, ...verbInflections, ...inflectionCombinations];
- bench(`transformations (n=${basicTransformations.length})`, () => {
+ bench(`japanese transformations (n=${basicTransformations.length})`, () => {
for (const transform of basicTransformations) {
languageTransformer.transform(transform);
}
});
const transformationsFull = [...basicTransformations, ...kuruInflections, ...suruInflections, ...kansaibenInflections];
- bench(`transformations-full (n=${transformationsFull.length})`, () => {
+ bench(`japanese transformations-full (n=${transformationsFull.length})`, () => {
for (const transform of transformationsFull) {
languageTransformer.transform(transform);
}
diff --git a/benches/spanish-language-transformer.bench.js b/benches/spanish-language-transformer.bench.js
new file mode 100644
index 00000000..8dc60ceb
--- /dev/null
+++ b/benches/spanish-language-transformer.bench.js
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2023-2024 Yomitan Authors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+import {bench, describe} from 'vitest';
+import {spanishTransforms} from '../ext/js/language/es/spanish-transforms.js';
+import {LanguageTransformer} from '../ext/js/language/language-transformer.js';
+
+const languageTransformer = new LanguageTransformer();
+languageTransformer.addDescriptor(spanishTransforms);
+
+describe('spanish language transformer', () => {
+ describe('basic tests', () => {
+ const nounInflections = [
+ 'gatos',
+ 'sofás',
+ 'tisús',
+ 'tisúes',
+ 'autobuses',
+ 'ciudades',
+ 'clics',
+ 'síes',
+ 'zigzags',
+ 'luces',
+ 'canciones',
+ ];
+
+ const verbPresentInflections = [
+ 'hablo',
+ 'hablas',
+ 'habla',
+ 'hablamos',
+ 'habláis',
+ 'hablan',
+ 'como',
+ 'comes',
+ 'come',
+ 'comemos',
+ 'coméis',
+ 'comen',
+ 'vivo',
+ 'vives',
+ 'vive',
+ 'vivimos',
+ 'vivís',
+ 'viven',
+ 'tengo',
+ 'tienes',
+ 'tiene',
+ 'tenemos',
+ 'tenéis',
+ 'tienen',
+ 'exijo',
+ 'extingo',
+ 'escojo',
+ 'quepo',
+ 'caigo',
+ 'conozco',
+ 'doy',
+ 'hago',
+ 'pongo',
+ 'sé',
+ 'salgo',
+ 'traduzco',
+ 'traigo',
+ 'valgo',
+ 'veo',
+ 'soy',
+ 'estoy',
+ 'voy',
+ 'he',
+ ];
+
+ const verbPreteriteInflections = [
+ 'hablé',
+ 'hablaste',
+ 'habló',
+ 'hablamos',
+ 'hablasteis',
+ 'hablaron',
+ 'comí',
+ 'comiste',
+ 'comió',
+ 'comimos',
+ 'comisteis',
+ 'comieron',
+ 'viví',
+ 'viviste',
+ 'vivió',
+ 'vivimos',
+ 'vivisteis',
+ 'vivieron',
+ 'tuve',
+ 'tuviste',
+ 'tuvo',
+ 'tuvimos',
+ 'tuvisteis',
+ 'tuvieron',
+ 'exigí',
+ 'extinguí',
+ 'escogí',
+ 'cupe',
+ 'caí',
+ 'conocí',
+ 'di',
+ 'hice',
+ 'puse',
+ 'supe',
+ 'salí',
+ 'traduje',
+ 'traje',
+ 'valí',
+ 'vi',
+ 'fui',
+ 'estuve',
+ 'fui',
+ 'hube',
+ ];
+
+ const basicTransformations = [...nounInflections, ...verbPresentInflections, ...verbPreteriteInflections];
+ bench(`spanish transformations (n=${basicTransformations.length})`, () => {
+ for (const transform of basicTransformations) {
+ languageTransformer.transform(transform);
+ }
+ });
+ });
+});
diff --git a/ext/js/language/es/spanish-transforms.js b/ext/js/language/es/spanish-transforms.js
index 54022fd5..dc4fc5a5 100644
--- a/ext/js/language/es/spanish-transforms.js
+++ b/ext/js/language/es/spanish-transforms.js
@@ -38,6 +38,19 @@ function addAccent(char) {
export const spanishTransforms = {
language: 'es',
conditions: {
+ n: {
+ name: 'Noun',
+ isDictionaryForm: true,
+ subConditions: ['ns', 'np'],
+ },
+ np: {
+ name: 'Noun plural',
+ isDictionaryForm: false,
+ },
+ ns: {
+ name: 'Noun singular',
+ isDictionaryForm: false,
+ },
v: {
name: 'Verb',
isDictionaryForm: true,
@@ -45,28 +58,15 @@ export const spanishTransforms = {
},
v_ar: {
name: '-ar verb',
- isDictionaryForm: true,
+ isDictionaryForm: false,
},
v_er: {
name: '-er verb',
- isDictionaryForm: true,
+ isDictionaryForm: false,
},
v_ir: {
name: '-ir verb',
- isDictionaryForm: true,
- },
- n: {
- name: 'Noun',
- isDictionaryForm: true,
- subConditions: ['ns', 'np'],
- },
- np: {
- name: 'Noun plural',
- isDictionaryForm: true,
- },
- ns: {
- name: 'Noun singular',
- isDictionaryForm: true,
+ isDictionaryForm: false,
},
adj: {
name: 'Adjective',
@@ -97,26 +97,26 @@ export const spanishTransforms = {
description: 'Present indicative form of a verb',
rules: [
// -ar verbs
- suffixInflection('o', 'ar', ['v'], ['v']),
- suffixInflection('as', 'ar', ['v'], ['v']),
- suffixInflection('a', 'ar', ['v'], ['v']),
- suffixInflection('amos', 'ar', ['v'], ['v']),
- suffixInflection('áis', 'ar', ['v'], ['v']),
- suffixInflection('an', 'ar', ['v'], ['v']),
+ suffixInflection('o', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('as', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('a', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('amos', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('áis', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('an', 'ar', ['v_ar'], ['v_ar']),
// -er verbs
- suffixInflection('o', 'er', ['v'], ['v']),
- suffixInflection('es', 'er', ['v'], ['v']),
- suffixInflection('e', 'er', ['v'], ['v']),
- suffixInflection('emos', 'er', ['v'], ['v']),
- suffixInflection('éis', 'er', ['v'], ['v']),
- suffixInflection('en', 'er', ['v'], ['v']),
+ suffixInflection('o', 'er', ['v_er'], ['v_er']),
+ suffixInflection('es', 'er', ['v_er'], ['v_er']),
+ suffixInflection('e', 'er', ['v_er'], ['v_er']),
+ suffixInflection('emos', 'er', ['v_er'], ['v_er']),
+ suffixInflection('éis', 'er', ['v_er'], ['v_er']),
+ suffixInflection('en', 'er', ['v_er'], ['v_er']),
// -ir verbs
- suffixInflection('o', 'ir', ['v'], ['v']),
- suffixInflection('es', 'ir', ['v'], ['v']),
- suffixInflection('e', 'ir', ['v'], ['v']),
- suffixInflection('imos', 'ir', ['v'], ['v']),
- suffixInflection('ís', 'ir', ['v'], ['v']),
- suffixInflection('en', 'ir', ['v'], ['v']),
+ suffixInflection('o', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('es', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('e', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('imos', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('ís', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('en', 'ir', ['v_ir'], ['v_ir']),
// -tener verbs
suffixInflection('tengo', 'tener', ['v'], ['v']),
suffixInflection('tienes', 'tener', ['v'], ['v']),
@@ -167,5 +167,427 @@ export const spanishTransforms = {
wholeWordInflection('han', 'haber', ['v'], ['v']),
],
},
+ 'preterite': {
+ name: 'preterite',
+ description: 'Preterite (past) form of a verb',
+ rules: [
+ // -ar verbs
+ suffixInflection('é', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('aste', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('ó', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('amos', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('asteis', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('aron', 'ar', ['v_ar'], ['v_ar']),
+ // -er verbs
+ suffixInflection('í', 'er', ['v_er'], ['v_er']),
+ suffixInflection('iste', 'er', ['v_er'], ['v_er']),
+ suffixInflection('ió', 'er', ['v_er'], ['v_er']),
+ suffixInflection('imos', 'er', ['v_er'], ['v_er']),
+ suffixInflection('isteis', 'er', ['v_er'], ['v_er']),
+ suffixInflection('ieron', 'er', ['v_er'], ['v_er']),
+ // -ir verbs
+ suffixInflection('í', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('iste', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('ió', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('imos', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('isteis', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('ieron', 'ir', ['v_ir'], ['v_ir']),
+ // -car, -gar, -zar verbs
+ suffixInflection('qué', 'car', ['v'], ['v']),
+ suffixInflection('gué', 'gar', ['v'], ['v']),
+ suffixInflection('cé', 'zar', ['v'], ['v']),
+ // -uir verbs
+ suffixInflection('í', 'uir', ['v'], ['v']),
+ // Verbs with irregular forms
+ wholeWordInflection('fui', 'ser', ['v'], ['v']),
+ wholeWordInflection('fuiste', 'ser', ['v'], ['v']),
+ wholeWordInflection('fue', 'ser', ['v'], ['v']),
+ wholeWordInflection('fuimos', 'ser', ['v'], ['v']),
+ wholeWordInflection('fuisteis', 'ser', ['v'], ['v']),
+ wholeWordInflection('fueron', 'ser', ['v'], ['v']),
+ wholeWordInflection('fui', 'ir', ['v'], ['v']),
+ wholeWordInflection('fuiste', 'ir', ['v'], ['v']),
+ wholeWordInflection('fue', 'ir', ['v'], ['v']),
+ wholeWordInflection('fuimos', 'ir', ['v'], ['v']),
+ wholeWordInflection('fuisteis', 'ir', ['v'], ['v']),
+ wholeWordInflection('fueron', 'ir', ['v'], ['v']),
+ wholeWordInflection('di', 'dar', ['v'], ['v']),
+ wholeWordInflection('diste', 'dar', ['v'], ['v']),
+ wholeWordInflection('dio', 'dar', ['v'], ['v']),
+ wholeWordInflection('dimos', 'dar', ['v'], ['v']),
+ wholeWordInflection('disteis', 'dar', ['v'], ['v']),
+ wholeWordInflection('dieron', 'dar', ['v'], ['v']),
+ suffixInflection('hice', 'hacer', ['v'], ['v']),
+ suffixInflection('hiciste', 'hacer', ['v'], ['v']),
+ suffixInflection('hizo', 'hacer', ['v'], ['v']),
+ suffixInflection('hicimos', 'hacer', ['v'], ['v']),
+ suffixInflection('hicisteis', 'hacer', ['v'], ['v']),
+ suffixInflection('hicieron', 'hacer', ['v'], ['v']),
+ suffixInflection('puse', 'poner', ['v'], ['v']),
+ suffixInflection('pusiste', 'poner', ['v'], ['v']),
+ suffixInflection('puso', 'poner', ['v'], ['v']),
+ suffixInflection('pusimos', 'poner', ['v'], ['v']),
+ suffixInflection('pusisteis', 'poner', ['v'], ['v']),
+ suffixInflection('pusieron', 'poner', ['v'], ['v']),
+ suffixInflection('dije', 'decir', ['v'], ['v']),
+ suffixInflection('dijiste', 'decir', ['v'], ['v']),
+ suffixInflection('dijo', 'decir', ['v'], ['v']),
+ suffixInflection('dijimos', 'decir', ['v'], ['v']),
+ suffixInflection('dijisteis', 'decir', ['v'], ['v']),
+ suffixInflection('dijeron', 'decir', ['v'], ['v']),
+ suffixInflection('vine', 'venir', ['v'], ['v']),
+ suffixInflection('viniste', 'venir', ['v'], ['v']),
+ suffixInflection('vino', 'venir', ['v'], ['v']),
+ suffixInflection('vinimos', 'venir', ['v'], ['v']),
+ suffixInflection('vinisteis', 'venir', ['v'], ['v']),
+ suffixInflection('vinieron', 'venir', ['v'], ['v']),
+ wholeWordInflection('quise', 'querer', ['v'], ['v']),
+ wholeWordInflection('quisiste', 'querer', ['v'], ['v']),
+ wholeWordInflection('quiso', 'querer', ['v'], ['v']),
+ wholeWordInflection('quisimos', 'querer', ['v'], ['v']),
+ wholeWordInflection('quisisteis', 'querer', ['v'], ['v']),
+ wholeWordInflection('quisieron', 'querer', ['v'], ['v']),
+ suffixInflection('tuve', 'tener', ['v'], ['v']),
+ suffixInflection('tuviste', 'tener', ['v'], ['v']),
+ suffixInflection('tuvo', 'tener', ['v'], ['v']),
+ suffixInflection('tuvimos', 'tener', ['v'], ['v']),
+ suffixInflection('tuvisteis', 'tener', ['v'], ['v']),
+ suffixInflection('tuvieron', 'tener', ['v'], ['v']),
+ wholeWordInflection('pude', 'poder', ['v'], ['v']),
+ wholeWordInflection('pudiste', 'poder', ['v'], ['v']),
+ wholeWordInflection('pudo', 'poder', ['v'], ['v']),
+ wholeWordInflection('pudimos', 'poder', ['v'], ['v']),
+ wholeWordInflection('pudisteis', 'poder', ['v'], ['v']),
+ wholeWordInflection('pudieron', 'poder', ['v'], ['v']),
+ wholeWordInflection('supe', 'saber', ['v'], ['v']),
+ wholeWordInflection('supiste', 'saber', ['v'], ['v']),
+ wholeWordInflection('supo', 'saber', ['v'], ['v']),
+ wholeWordInflection('supimos', 'saber', ['v'], ['v']),
+ wholeWordInflection('supisteis', 'saber', ['v'], ['v']),
+ wholeWordInflection('supieron', 'saber', ['v'], ['v']),
+ wholeWordInflection('estuve', 'estar', ['v'], ['v']),
+ wholeWordInflection('estuviste', 'estar', ['v'], ['v']),
+ wholeWordInflection('estuvo', 'estar', ['v'], ['v']),
+ wholeWordInflection('estuvimos', 'estar', ['v'], ['v']),
+ wholeWordInflection('estuvisteis', 'estar', ['v'], ['v']),
+ wholeWordInflection('estuvieron', 'estar', ['v'], ['v']),
+ wholeWordInflection('anduve', 'andar', ['v'], ['v']),
+ wholeWordInflection('anduviste', 'andar', ['v'], ['v']),
+ wholeWordInflection('anduvo', 'andar', ['v'], ['v']),
+ wholeWordInflection('anduvimos', 'andar', ['v'], ['v']),
+ wholeWordInflection('anduvisteis', 'andar', ['v'], ['v']),
+ wholeWordInflection('anduvieron', 'andar', ['v'], ['v']),
+ ],
+ },
+ 'imperfect': {
+ name: 'imperfect',
+ description: 'Imperfect form of a verb',
+ rules: [
+ // -ar verbs
+ suffixInflection('aba', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('abas', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('aba', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('ábamos', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('abais', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('aban', 'ar', ['v_ar'], ['v_ar']),
+ // -er verbs
+ suffixInflection('ía', 'er', ['v_er'], ['v_er']),
+ suffixInflection('ías', 'er', ['v_er'], ['v_er']),
+ suffixInflection('ía', 'er', ['v_er'], ['v_er']),
+ suffixInflection('íamos', 'er', ['v_er'], ['v_er']),
+ suffixInflection('íais', 'er', ['v_er'], ['v_er']),
+ suffixInflection('ían', 'er', ['v_er'], ['v_er']),
+ // -ir verbs
+ suffixInflection('ía', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('ías', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('ía', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('íamos', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('íais', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('ían', 'ir', ['v_ir'], ['v_ir']),
+ // -ir verbs with stem changes
+ suffixInflection('eía', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('eías', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('eía', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('eíamos', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('eíais', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('eían', 'ir', ['v_ir'], ['v_ir']),
+ // irregular verbs ir, ser, ver
+ wholeWordInflection('era', 'ser', ['v'], ['v']),
+ wholeWordInflection('eras', 'ser', ['v'], ['v']),
+ wholeWordInflection('era', 'ser', ['v'], ['v']),
+ wholeWordInflection('éramos', 'ser', ['v'], ['v']),
+ wholeWordInflection('erais', 'ser', ['v'], ['v']),
+ wholeWordInflection('eran', 'ser', ['v'], ['v']),
+ wholeWordInflection('iba', 'ir', ['v'], ['v']),
+ wholeWordInflection('ibas', 'ir', ['v'], ['v']),
+ wholeWordInflection('iba', 'ir', ['v'], ['v']),
+ wholeWordInflection('íbamos', 'ir', ['v'], ['v']),
+ wholeWordInflection('ibais', 'ir', ['v'], ['v']),
+ wholeWordInflection('iban', 'ir', ['v'], ['v']),
+ wholeWordInflection('veía', 'ver', ['v'], ['v']),
+ wholeWordInflection('veías', 'ver', ['v'], ['v']),
+ wholeWordInflection('veía', 'ver', ['v'], ['v']),
+ wholeWordInflection('veíamos', 'ver', ['v'], ['v']),
+ wholeWordInflection('veíais', 'ver', ['v'], ['v']),
+ wholeWordInflection('veían', 'ver', ['v'], ['v']),
+ ],
+ },
+ 'progressive': {
+ name: 'progressive',
+ description: 'Progressive form of a verb',
+ rules: [
+ suffixInflection('ando', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('iendo', 'er', ['v_er'], ['v_er']),
+ suffixInflection('iendo', 'ir', ['v_ir'], ['v_ir']),
+ ],
+ },
+ 'imperative': {
+ name: 'imperative',
+ description: 'Imperative form of a verb',
+ rules: [
+ // -ar verbs
+ suffixInflection('a', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('ad', 'ar', ['v_ar'], ['v_ar']),
+ // -er verbs
+ suffixInflection('e', 'er', ['v_er'], ['v_er']),
+ suffixInflection('ed', 'er', ['v_er'], ['v_er']),
+ // -ir verbs
+ suffixInflection('e', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('id', 'ir', ['v_ir'], ['v_ir']),
+ // irregular verbs
+ wholeWordInflection('diga', 'decir', ['v'], ['v']),
+ // irregular imperative verbs
+ wholeWordInflection('sé', 'ser', ['v'], ['v']),
+ wholeWordInflection('ve', 'ir', ['v'], ['v']),
+ wholeWordInflection('ten', 'tener', ['v'], ['v']),
+ wholeWordInflection('ven', 'vener', ['v'], ['v']),
+ wholeWordInflection('haz', 'hacer', ['v'], ['v']),
+ wholeWordInflection('di', 'decir', ['v'], ['v']),
+ wholeWordInflection('pon', 'poner', ['v'], ['v']),
+ wholeWordInflection('sal', 'salir', ['v'], ['v']),
+ // TODO: negative commands, nosotros & vosotros commands
+ ],
+ },
+ 'conditional': {
+ name: 'conditional',
+ description: 'Conditional form of a verb',
+ rules: [
+ suffixInflection('ía', '', ['v'], ['v']),
+ suffixInflection('ías', '', ['v'], ['v']),
+ suffixInflection('ía', '', ['v'], ['v']),
+ suffixInflection('íamos', '', ['v'], ['v']),
+ suffixInflection('íais', '', ['v'], ['v']),
+ suffixInflection('ían', '', ['v'], ['v']),
+ // irregular verbs
+ wholeWordInflection('diría', 'decir', ['v'], ['v']),
+ wholeWordInflection('dirías', 'decir', ['v'], ['v']),
+ wholeWordInflection('diría', 'decir', ['v'], ['v']),
+ wholeWordInflection('diríamos', 'decir', ['v'], ['v']),
+ wholeWordInflection('diríais', 'decir', ['v'], ['v']),
+ wholeWordInflection('dirían', 'decir', ['v'], ['v']),
+ wholeWordInflection('haría', 'hacer', ['v'], ['v']),
+ wholeWordInflection('harías', 'hacer', ['v'], ['v']),
+ wholeWordInflection('haría', 'hacer', ['v'], ['v']),
+ wholeWordInflection('haríamos', 'hacer', ['v'], ['v']),
+ wholeWordInflection('haríais', 'hacer', ['v'], ['v']),
+ wholeWordInflection('harían', 'hacer', ['v'], ['v']),
+ wholeWordInflection('pondría', 'poner', ['v'], ['v']),
+ wholeWordInflection('pondrías', 'poner', ['v'], ['v']),
+ wholeWordInflection('pondría', 'poner', ['v'], ['v']),
+ wholeWordInflection('pondríamos', 'poner', ['v'], ['v']),
+ wholeWordInflection('pondríais', 'poner', ['v'], ['v']),
+ wholeWordInflection('pondrían', 'poner', ['v'], ['v']),
+ wholeWordInflection('saldría', 'salir', ['v'], ['v']),
+ wholeWordInflection('saldrías', 'salir', ['v'], ['v']),
+ wholeWordInflection('saldría', 'salir', ['v'], ['v']),
+ wholeWordInflection('saldríamos', 'salir', ['v'], ['v']),
+ wholeWordInflection('saldríais', 'salir', ['v'], ['v']),
+ wholeWordInflection('saldrían', 'salir', ['v'], ['v']),
+ wholeWordInflection('tendría', 'tener', ['v'], ['v']),
+ wholeWordInflection('tendrías', 'tener', ['v'], ['v']),
+ wholeWordInflection('tendría', 'tener', ['v'], ['v']),
+ wholeWordInflection('tendríamos', 'tener', ['v'], ['v']),
+ wholeWordInflection('tendríais', 'tener', ['v'], ['v']),
+ wholeWordInflection('tendrían', 'tener', ['v'], ['v']),
+ wholeWordInflection('vendría', 'venir', ['v'], ['v']),
+ wholeWordInflection('vendrías', 'venir', ['v'], ['v']),
+ wholeWordInflection('vendría', 'venir', ['v'], ['v']),
+ wholeWordInflection('vendríamos', 'venir', ['v'], ['v']),
+ wholeWordInflection('vendríais', 'venir', ['v'], ['v']),
+ wholeWordInflection('vendrían', 'venir', ['v'], ['v']),
+ wholeWordInflection('querría', 'querer', ['v'], ['v']),
+ wholeWordInflection('querrías', 'querer', ['v'], ['v']),
+ wholeWordInflection('querría', 'querer', ['v'], ['v']),
+ wholeWordInflection('querríamos', 'querer', ['v'], ['v']),
+ wholeWordInflection('querríais', 'querer', ['v'], ['v']),
+ wholeWordInflection('querrían', 'querer', ['v'], ['v']),
+ wholeWordInflection('podría', 'poder', ['v'], ['v']),
+ wholeWordInflection('podrías', 'poder', ['v'], ['v']),
+ wholeWordInflection('podría', 'poder', ['v'], ['v']),
+ wholeWordInflection('podríamos', 'poder', ['v'], ['v']),
+ wholeWordInflection('podríais', 'poder', ['v'], ['v']),
+ wholeWordInflection('podrían', 'poder', ['v'], ['v']),
+ wholeWordInflection('sabría', 'saber', ['v'], ['v']),
+ wholeWordInflection('sabrías', 'saber', ['v'], ['v']),
+ wholeWordInflection('sabría', 'saber', ['v'], ['v']),
+ wholeWordInflection('sabríamos', 'saber', ['v'], ['v']),
+ wholeWordInflection('sabríais', 'saber', ['v'], ['v']),
+ wholeWordInflection('sabrían', 'saber', ['v'], ['v']),
+ ],
+ },
+ 'future': {
+ name: 'future',
+ description: 'Future form of a verb',
+ rules: [
+ suffixInflection('é', '', ['v'], ['v']),
+ suffixInflection('ás', '', ['v'], ['v']),
+ suffixInflection('á', '', ['v'], ['v']),
+ suffixInflection('emos', '', ['v'], ['v']),
+ suffixInflection('éis', '', ['v'], ['v']),
+ suffixInflection('án', '', ['v'], ['v']),
+ // irregular verbs
+ suffixInflection('diré', 'decir', ['v'], ['v']),
+ suffixInflection('dirás', 'decir', ['v'], ['v']),
+ suffixInflection('dirá', 'decir', ['v'], ['v']),
+ suffixInflection('diremos', 'decir', ['v'], ['v']),
+ suffixInflection('diréis', 'decir', ['v'], ['v']),
+ suffixInflection('dirán', 'decir', ['v'], ['v']),
+ wholeWordInflection('haré', 'hacer', ['v'], ['v']),
+ wholeWordInflection('harás', 'hacer', ['v'], ['v']),
+ wholeWordInflection('hará', 'hacer', ['v'], ['v']),
+ wholeWordInflection('haremos', 'hacer', ['v'], ['v']),
+ wholeWordInflection('haréis', 'hacer', ['v'], ['v']),
+ wholeWordInflection('harán', 'hacer', ['v'], ['v']),
+ suffixInflection('pondré', 'poner', ['v'], ['v']),
+ suffixInflection('pondrás', 'poner', ['v'], ['v']),
+ suffixInflection('pondrá', 'poner', ['v'], ['v']),
+ suffixInflection('pondremos', 'poner', ['v'], ['v']),
+ suffixInflection('pondréis', 'poner', ['v'], ['v']),
+ suffixInflection('pondrán', 'poner', ['v'], ['v']),
+ wholeWordInflection('saldré', 'salir', ['v'], ['v']),
+ wholeWordInflection('saldrás', 'salir', ['v'], ['v']),
+ wholeWordInflection('saldrá', 'salir', ['v'], ['v']),
+ wholeWordInflection('saldremos', 'salir', ['v'], ['v']),
+ wholeWordInflection('saldréis', 'salir', ['v'], ['v']),
+ wholeWordInflection('saldrán', 'salir', ['v'], ['v']),
+ suffixInflection('tendré', 'tener', ['v'], ['v']),
+ suffixInflection('tendrás', 'tener', ['v'], ['v']),
+ suffixInflection('tendrá', 'tener', ['v'], ['v']),
+ suffixInflection('tendremos', 'tener', ['v'], ['v']),
+ suffixInflection('tendréis', 'tener', ['v'], ['v']),
+ suffixInflection('tendrán', 'tener', ['v'], ['v']),
+ suffixInflection('vendré', 'venir', ['v'], ['v']),
+ suffixInflection('vendrás', 'venir', ['v'], ['v']),
+ suffixInflection('vendrá', 'venir', ['v'], ['v']),
+ suffixInflection('vendremos', 'venir', ['v'], ['v']),
+ suffixInflection('vendréis', 'venir', ['v'], ['v']),
+ suffixInflection('vendrán', 'venir', ['v'], ['v']),
+ ],
+ },
+ 'present subjunctive': {
+ name: 'present subjunctive',
+ description: 'Present subjunctive form of a verb',
+ rules: [
+ // -ar verbs
+ suffixInflection('e', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('es', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('e', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('emos', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('éis', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('en', 'ar', ['v_ar'], ['v_ar']),
+ // -er verbs
+ suffixInflection('a', 'er', ['v_er'], ['v_er']),
+ suffixInflection('as', 'er', ['v_er'], ['v_er']),
+ suffixInflection('a', 'er', ['v_er'], ['v_er']),
+ suffixInflection('amos', 'er', ['v_er'], ['v_er']),
+ suffixInflection('áis', 'er', ['v_er'], ['v_er']),
+ suffixInflection('an', 'er', ['v_er'], ['v_er']),
+ // -ir verbs
+ suffixInflection('a', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('as', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('a', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('amos', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('áis', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('an', 'ir', ['v_ir'], ['v_ir']),
+ // TODO: stem-changing verbs
+ // irregular verbs
+ wholeWordInflection('dé', 'dar', ['v'], ['v']),
+ wholeWordInflection('des', 'dar', ['v'], ['v']),
+ wholeWordInflection('dé', 'dar', ['v'], ['v']),
+ wholeWordInflection('demos', 'dar', ['v'], ['v']),
+ wholeWordInflection('deis', 'dar', ['v'], ['v']),
+ wholeWordInflection('den', 'dar', ['v'], ['v']),
+ wholeWordInflection('esté', 'estar', ['v'], ['v']),
+ wholeWordInflection('estés', 'estar', ['v'], ['v']),
+ wholeWordInflection('esté', 'estar', ['v'], ['v']),
+ wholeWordInflection('estemos', 'estar', ['v'], ['v']),
+ wholeWordInflection('estéis', 'estar', ['v'], ['v']),
+ wholeWordInflection('estén', 'estar', ['v'], ['v']),
+ wholeWordInflection('sea', 'ser', ['v'], ['v']),
+ wholeWordInflection('seas', 'ser', ['v'], ['v']),
+ wholeWordInflection('sea', 'ser', ['v'], ['v']),
+ wholeWordInflection('seamos', 'ser', ['v'], ['v']),
+ wholeWordInflection('seáis', 'ser', ['v'], ['v']),
+ wholeWordInflection('sean', 'ser', ['v'], ['v']),
+ wholeWordInflection('vaya', 'ir', ['v'], ['v']),
+ wholeWordInflection('vayas', 'ir', ['v'], ['v']),
+ wholeWordInflection('vaya', 'ir', ['v'], ['v']),
+ wholeWordInflection('vayamos', 'ir', ['v'], ['v']),
+ wholeWordInflection('vayáis', 'ir', ['v'], ['v']),
+ wholeWordInflection('vayan', 'ir', ['v'], ['v']),
+ wholeWordInflection('haya', 'haber', ['v'], ['v']),
+ wholeWordInflection('hayas', 'haber', ['v'], ['v']),
+ wholeWordInflection('haya', 'haber', ['v'], ['v']),
+ wholeWordInflection('hayamos', 'haber', ['v'], ['v']),
+ wholeWordInflection('hayáis', 'haber', ['v'], ['v']),
+ wholeWordInflection('hayan', 'haber', ['v'], ['v']),
+ wholeWordInflection('sepa', 'saber', ['v'], ['v']),
+ wholeWordInflection('sepas', 'saber', ['v'], ['v']),
+ wholeWordInflection('sepa', 'saber', ['v'], ['v']),
+ wholeWordInflection('sepamos', 'saber', ['v'], ['v']),
+ wholeWordInflection('sepáis', 'saber', ['v'], ['v']),
+ wholeWordInflection('sepan', 'saber', ['v'], ['v']),
+ ],
+ },
+ 'imperfect subjunctive': {
+ name: 'imperfect subjunctive',
+ description: 'Imperfect subjunctive form of a verb',
+ rules: [
+ // -ar verbs
+ suffixInflection('ara', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('aras', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('ara', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('áramos', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('arais', 'ar', ['v_ar'], ['v_ar']),
+ suffixInflection('aran', 'ar', ['v_ar'], ['v_ar']),
+ // -er verbs
+ suffixInflection('iera', 'er', ['v_er'], ['v_er']),
+ suffixInflection('ieras', 'er', ['v_er'], ['v_er']),
+ suffixInflection('iera', 'er', ['v_er'], ['v_er']),
+ suffixInflection('iéramos', 'er', ['v_er'], ['v_er']),
+ suffixInflection('ierais', 'er', ['v_er'], ['v_er']),
+ suffixInflection('ieran', 'er', ['v_er'], ['v_er']),
+ // -ir verbs
+ suffixInflection('iera', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('ieras', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('iera', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('iéramos', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('ierais', 'ir', ['v_ir'], ['v_ir']),
+ suffixInflection('ieran', 'ir', ['v_ir'], ['v_ir']),
+ // irregular verbs
+ wholeWordInflection('fuera', 'ser', ['v'], ['v']),
+ wholeWordInflection('fueras', 'ser', ['v'], ['v']),
+ wholeWordInflection('fuera', 'ser', ['v'], ['v']),
+ wholeWordInflection('fuéramos', 'ser', ['v'], ['v']),
+ wholeWordInflection('fuerais', 'ser', ['v'], ['v']),
+ wholeWordInflection('fueran', 'ser', ['v'], ['v']),
+ wholeWordInflection('fuera', 'ir', ['v'], ['v']),
+ wholeWordInflection('fueras', 'ir', ['v'], ['v']),
+ wholeWordInflection('fuera', 'ir', ['v'], ['v']),
+ wholeWordInflection('fuéramos', 'ir', ['v'], ['v']),
+ wholeWordInflection('fuerais', 'ir', ['v'], ['v']),
+ wholeWordInflection('fueran', 'ir', ['v'], ['v']),
+ ],
+ },
},
};
diff --git a/test/language/spanish-transforms.test.js b/test/language/spanish-transforms.test.js
index 0af2587a..53ff3e2c 100644
--- a/test/language/spanish-transforms.test.js
+++ b/test/language/spanish-transforms.test.js
@@ -93,6 +93,149 @@ const tests = [
{term: 'haber', source: 'he', rule: 'v', reasons: ['present indicative']},
],
},
+ {
+ category: 'preterite',
+ valid: true,
+ tests: [
+ {term: 'hablar', source: 'hablé', rule: 'v', reasons: ['preterite']},
+ {term: 'hablar', source: 'hablaste', rule: 'v', reasons: ['preterite']},
+ {term: 'hablar', source: 'habló', rule: 'v', reasons: ['preterite']},
+ {term: 'hablar', source: 'hablamos', rule: 'v', reasons: ['preterite']},
+ {term: 'hablar', source: 'hablasteis', rule: 'v', reasons: ['preterite']},
+ {term: 'hablar', source: 'hablaron', rule: 'v', reasons: ['preterite']},
+ {term: 'comer', source: 'comí', rule: 'v', reasons: ['preterite']},
+ {term: 'comer', source: 'comiste', rule: 'v', reasons: ['preterite']},
+ {term: 'comer', source: 'comió', rule: 'v', reasons: ['preterite']},
+ {term: 'comer', source: 'comimos', rule: 'v', reasons: ['preterite']},
+ {term: 'comer', source: 'comisteis', rule: 'v', reasons: ['preterite']},
+ {term: 'comer', source: 'comieron', rule: 'v', reasons: ['preterite']},
+ {term: 'vivir', source: 'viví', rule: 'v', reasons: ['preterite']},
+ {term: 'vivir', source: 'viviste', rule: 'v', reasons: ['preterite']},
+ {term: 'vivir', source: 'vivió', rule: 'v', reasons: ['preterite']},
+ {term: 'vivir', source: 'vivimos', rule: 'v', reasons: ['preterite']},
+ {term: 'vivir', source: 'vivisteis', rule: 'v', reasons: ['preterite']},
+ {term: 'vivir', source: 'vivieron', rule: 'v', reasons: ['preterite']},
+ {term: 'tener', source: 'tuve', rule: 'v', reasons: ['preterite']},
+ ],
+ },
+ {
+ category: 'imperfect',
+ valid: true,
+ tests: [
+ {term: 'hablar', source: 'hablaba', rule: 'v', reasons: ['imperfect']},
+ {term: 'hablar', source: 'hablabas', rule: 'v', reasons: ['imperfect']},
+ {term: 'hablar', source: 'hablaba', rule: 'v', reasons: ['imperfect']},
+ {term: 'hablar', source: 'hablábamos', rule: 'v', reasons: ['imperfect']},
+ {term: 'hablar', source: 'hablabais', rule: 'v', reasons: ['imperfect']},
+ {term: 'hablar', source: 'hablaban', rule: 'v', reasons: ['imperfect']},
+ {term: 'comer', source: 'comía', rule: 'v', reasons: ['imperfect']},
+ {term: 'comer', source: 'comías', rule: 'v', reasons: ['imperfect']},
+ {term: 'comer', source: 'comía', rule: 'v', reasons: ['imperfect']},
+ {term: 'comer', source: 'comíamos', rule: 'v', reasons: ['imperfect']},
+ {term: 'comer', source: 'comíais', rule: 'v', reasons: ['imperfect']},
+ {term: 'comer', source: 'comían', rule: 'v', reasons: ['imperfect']},
+ {term: 'vivir', source: 'vivía', rule: 'v', reasons: ['imperfect']},
+ {term: 'vivir', source: 'vivías', rule: 'v', reasons: ['imperfect']},
+ {term: 'vivir', source: 'vivía', rule: 'v', reasons: ['imperfect']},
+ {term: 'vivir', source: 'vivíamos', rule: 'v', reasons: ['imperfect']},
+ {term: 'vivir', source: 'vivíais', rule: 'v', reasons: ['imperfect']},
+ {term: 'vivir', source: 'vivían', rule: 'v', reasons: ['imperfect']},
+ ],
+ },
+ {
+ category: 'progressive',
+ valid: true,
+ tests: [
+ {term: 'hablar', source: 'hablando', rule: 'v', reasons: ['progressive']},
+ {term: 'comer', source: 'comiendo', rule: 'v', reasons: ['progressive']},
+ {term: 'vivir', source: 'viviendo', rule: 'v', reasons: ['progressive']},
+ ],
+ },
+ {
+ category: 'imperative',
+ valid: true,
+ tests: [
+ {term: 'hablar', source: 'habla', rule: 'v', reasons: ['imperative']},
+ {term: 'hablar', source: 'hablad', rule: 'v', reasons: ['imperative']},
+ {term: 'comer', source: 'come', rule: 'v', reasons: ['imperative']},
+ {term: 'comer', source: 'comed', rule: 'v', reasons: ['imperative']},
+ {term: 'vivir', source: 'vive', rule: 'v', reasons: ['imperative']},
+ {term: 'vivir', source: 'vivid', rule: 'v', reasons: ['imperative']},
+ ],
+ },
+ {
+ category: 'conditional',
+ valid: true,
+ tests: [
+ {term: 'hablar', source: 'hablaría', rule: 'v', reasons: ['conditional']},
+ {term: 'hablar', source: 'hablarías', rule: 'v', reasons: ['conditional']},
+ {term: 'hablar', source: 'hablaría', rule: 'v', reasons: ['conditional']},
+ {term: 'hablar', source: 'hablaríamos', rule: 'v', reasons: ['conditional']},
+ {term: 'hablar', source: 'hablaríais', rule: 'v', reasons: ['conditional']},
+ {term: 'hablar', source: 'hablarían', rule: 'v', reasons: ['conditional']},
+ {term: 'comer', source: 'comería', rule: 'v', reasons: ['conditional']},
+ {term: 'comer', source: 'comerías', rule: 'v', reasons: ['conditional']},
+ {term: 'comer', source: 'comería', rule: 'v', reasons: ['conditional']},
+ {term: 'comer', source: 'comeríamos', rule: 'v', reasons: ['conditional']},
+ {term: 'comer', source: 'comeríais', rule: 'v', reasons: ['conditional']},
+ {term: 'comer', source: 'comerían', rule: 'v', reasons: ['conditional']},
+ {term: 'vivir', source: 'viviría', rule: 'v', reasons: ['conditional']},
+ {term: 'vivir', source: 'vivirías', rule: 'v', reasons: ['conditional']},
+ {term: 'vivir', source: 'viviría', rule: 'v', reasons: ['conditional']},
+ {term: 'vivir', source: 'viviríamos', rule: 'v', reasons: ['conditional']},
+ {term: 'vivir', source: 'viviríais', rule: 'v', reasons: ['conditional']},
+ {term: 'vivir', source: 'vivirían', rule: 'v', reasons: ['conditional']},
+ ],
+ },
+ {
+ category: 'future',
+ valid: true,
+ tests: [
+ {term: 'hablar', source: 'hablaré', rule: 'v', reasons: ['future']},
+ {term: 'hablar', source: 'hablarás', rule: 'v', reasons: ['future']},
+ {term: 'hablar', source: 'hablará', rule: 'v', reasons: ['future']},
+ {term: 'hablar', source: 'hablaremos', rule: 'v', reasons: ['future']},
+ {term: 'hablar', source: 'hablaréis', rule: 'v', reasons: ['future']},
+ {term: 'hablar', source: 'hablarán', rule: 'v', reasons: ['future']},
+ {term: 'comer', source: 'comeré', rule: 'v', reasons: ['future']},
+ {term: 'comer', source: 'comerás', rule: 'v', reasons: ['future']},
+ {term: 'comer', source: 'comerá', rule: 'v', reasons: ['future']},
+ {term: 'comer', source: 'comeremos', rule: 'v', reasons: ['future']},
+ {term: 'comer', source: 'comeréis', rule: 'v', reasons: ['future']},
+ {term: 'comer', source: 'comerán', rule: 'v', reasons: ['future']},
+ {term: 'vivir', source: 'viviré', rule: 'v', reasons: ['future']},
+ {term: 'vivir', source: 'vivirás', rule: 'v', reasons: ['future']},
+ {term: 'vivir', source: 'vivirá', rule: 'v', reasons: ['future']},
+ {term: 'vivir', source: 'viviremos', rule: 'v', reasons: ['future']},
+ {term: 'vivir', source: 'viviréis', rule: 'v', reasons: ['future']},
+ {term: 'vivir', source: 'vivirán', rule: 'v', reasons: ['future']},
+ ],
+ },
+ {
+ category: 'present subjunctive',
+ valid: true,
+ tests: [
+ {term: 'hablar', source: 'hable', rule: 'v', reasons: ['present subjunctive']},
+ {term: 'hablar', source: 'hables', rule: 'v', reasons: ['present subjunctive']},
+ {term: 'hablar', source: 'hable', rule: 'v', reasons: ['present subjunctive']},
+ {term: 'hablar', source: 'hablemos', rule: 'v', reasons: ['present subjunctive']},
+ {term: 'hablar', source: 'habléis', rule: 'v', reasons: ['present subjunctive']},
+ {term: 'hablar', source: 'hablen', rule: 'v', reasons: ['present subjunctive']},
+ {term: 'comer', source: 'coma', rule: 'v', reasons: ['present subjunctive']},
+ {term: 'comer', source: 'comas', rule: 'v', reasons: ['present subjunctive']},
+ {term: 'comer', source: 'coma', rule: 'v', reasons: ['present subjunctive']},
+ {term: 'comer', source: 'comamos', rule: 'v', reasons: ['present subjunctive']},
+ {term: 'comer', source: 'comáis', rule: 'v', reasons: ['present subjunctive']},
+ {term: 'comer', source: 'coman', rule: 'v', reasons: ['present subjunctive']},
+ {term: 'vivir', source: 'viva', rule: 'v', reasons: ['present subjunctive']},
+ {term: 'vivir', source: 'vivas', rule: 'v', reasons: ['present subjunctive']},
+ {term: 'vivir', source: 'viva', rule: 'v', reasons: ['present subjunctive']},
+ {term: 'vivir', source: 'vivamos', rule: 'v', reasons: ['present subjunctive']},
+ {term: 'vivir', source: 'viváis', rule: 'v', reasons: ['present subjunctive']},
+ {term: 'vivir', source: 'vivan', rule: 'v', reasons: ['present subjunctive']},
+ ],
+ },
+
];
const languageTransformer = new LanguageTransformer();