UNPKG

@jirimracek/conjugate-esp

Version:

Spanish verb conjugator, castellano, voseo, canarias, formal

501 lines 22.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseModel = exports.SUBJUNTIVO_COMP_KEYS = exports.INDICATIVO_COMP_KEYS = exports.SUBJUNTIVO_SIMPLE_KEYS = exports.INDICATIVO_SIMPLE_KEYS = void 0; const stringutils_1 = require("./stringutils"); const NO_IMPERATIVO_AFIRMATIVO = [ 'imper', 'tercio', 'terciop', 'bimorfop', 'omorfo', 'osmorfo', 'ogmorfo' ]; exports.INDICATIVO_SIMPLE_KEYS = [ 'Presente', 'PreteritoImperfecto', 'PreteritoIndefinido', 'FuturoImperfecto', 'CondicionalSimple' ]; exports.SUBJUNTIVO_SIMPLE_KEYS = [ 'Presente', 'PreteritoImperfectoRa', 'PreteritoImperfectoSe', 'FuturoImperfecto' ]; exports.INDICATIVO_COMP_KEYS = [ 'PreteritoPerfecto', 'PreteritoPluscuamperfecto', 'PreteritoAnterior', 'FuturoPerfecto', 'CondicionalCompuesto' ]; exports.SUBJUNTIVO_COMP_KEYS = [ 'PreteritoPerfecto', 'PreteritoPluscuamperfectoRa', 'PreteritoPluscuamperfectoSe', 'FuturoPerfecto' ]; const NO_IMPERATIVO_NEGATIVO = ['imper', 'tercio', 'terciop', 'bimorfop', 'ogmorfo']; const DASH6 = '------'; class BaseModel { constructor(verb, region, attributes) { this.stem = ''; this.participioCompuesto = ''; this.verb = verb; this.reflexive = verb.endsWith('se'); this.stem = verb.replace(this.reflexive ? /....$/ : /..$/, ''); this.region = region; this.attributes = attributes; this.defectiveAttributes = attributes['D']; this.version = (attributes.V ? attributes.V : '0'); this.auxHaber = this.initAuxiliaryHaber(region); this.reflexPronouns = (() => [ 'me', region !== 'formal' ? 'te' : 'se', 'se', 'nos', region !== 'castellano' ? 'se' : 'os', 'se' ])(); this.table = { Impersonal: { Infinitivo: '', Gerundio: '', Participio: '' }, Indicativo: { Presente: [], PreteritoImperfecto: [], PreteritoIndefinido: [], FuturoImperfecto: [], CondicionalSimple: [], PreteritoPerfecto: [], PreteritoPluscuamperfecto: [], PreteritoAnterior: [], FuturoPerfecto: [], CondicionalCompuesto: [] }, Subjuntivo: { Presente: [], PreteritoImperfectoRa: [], PreteritoImperfectoSe: [], FuturoImperfecto: [], PreteritoPerfecto: [], PreteritoPluscuamperfectoRa: [], PreteritoPluscuamperfectoSe: [], FuturoPerfecto: [] }, Imperativo: { Afirmativo: Array.from(DASH6), Negativo: Array.from(DASH6) } }; this.desinences = { Impersonal: { Infinitivo: '', Gerundio: '', Participio: '' }, Indicativo: { Presente: [], PreteritoImperfecto: [], PreteritoIndefinido: [], FuturoImperfecto: [], CondicionalSimple: [] }, Subjuntivo: { Presente: [], PreteritoImperfectoRa: [], PreteritoImperfectoSe: [], FuturoImperfecto: [] } }; } initAuxiliaryHaber(region) { return { Indicativo: { PreteritoPerfecto: ['he', region !== 'formal' ? 'has' : 'ha', 'ha', 'hemos', region !== 'castellano' ? 'han' : 'habéis', 'han'], PreteritoPluscuamperfecto: ['había', region !== 'formal' ? 'habías' : 'había', 'había', 'habíamos', region !== 'castellano' ? 'habían' : 'habíais', 'habían'], PreteritoAnterior: ['hube', region !== 'formal' ? 'hubiste' : 'hubo', 'hubo', 'hubimos', region !== 'castellano' ? 'hubieron' : 'hubisteis', 'hubieron'], FuturoPerfecto: ['habré', region !== 'formal' ? 'habrás' : 'habrá', 'habrá', 'habremos', region !== 'castellano' ? 'habrán' : 'habréis', 'habrán'], CondicionalCompuesto: ['habría', region !== 'formal' ? 'habrías' : 'habría', 'habría', 'habríamos', region !== 'castellano' ? 'habrían' : 'habríais', 'habrían'] }, Subjuntivo: { PreteritoPerfecto: ['haya', region !== 'formal' ? 'hayas' : 'haya', 'haya', 'hayamos', region !== 'castellano' ? 'hayan' : 'hayáis', 'hayan'], PreteritoPluscuamperfectoRa: ['hubiera', region !== 'formal' ? 'hubieras' : 'hubiera', 'hubiera', 'hubiéramos', region !== 'castellano' ? 'hubieran' : 'hubierais', 'hubieran'], PreteritoPluscuamperfectoSe: ['hubiese', region !== 'formal' ? 'hubieses' : 'hubiese', 'hubiese', 'hubiésemos', region !== 'castellano' ? 'hubiesen' : 'hubieseis', 'hubiesen'], FuturoPerfecto: ['hubiere', region !== 'formal' ? 'hubieres' : 'hubiere', 'hubiere', 'hubiéremos', region !== 'castellano' ? 'hubieren' : 'hubiereis', 'hubieren'] } }; } getConjugation() { this.setInfinitivo(); this.setGerundio(); this.setParticipio(); this.setIndicativoPresente(); this.setIndicativoPreteritoImperfecto(); this.setIndicativoPreteritoIndefinido(); this.setIndicativoFuturoImperfecto(); this.setIndicativoCondicionalSimple(); this.setSubjuntivoPresente(); this.setSubjuntivoPreteritoImperfectoRa(); this.setSubjuntivoPreteritoImperfectoSe(); this.setSubjuntivoFuturoImperfecto(); this.setCompuestos(); this.setImperativoAfirmativo(); this.setImperativoNegativo(); this.applyDefectiveAttributes(); return this.table; } setInfinitivo() { this.table.Impersonal.Infinitivo = `${this.stem}${this.desinences.Impersonal.Infinitivo}`; } setGerundio(root) { this.table.Impersonal.Gerundio = `${root ? root : this.stem}${this.desinences.Impersonal.Gerundio}`; } setParticipio() { this.participioCompuesto = `${this.stem}${this.desinences.Impersonal.Participio}`; this.table.Impersonal.Participio = this.participioCompuesto; } setTable(mode, key, roots) { if (mode === 'Indicativo') { this.table[mode][key] = this.desinences[mode][key] .map((desinence, index) => `${this.reflexive ? this.reflexPronouns[index] : ''} ${roots ? roots[index] : this.stem}${desinence}`.trim()); } if (mode === 'Subjuntivo') { this.table[mode][key] = this.desinences[mode][key] .map((desinence, index) => `${this.reflexive ? this.reflexPronouns[index] : ''} ${roots ? roots[index] : this.stem}${desinence}`.trim()); } } setIndicativoPresente() { this.setTable('Indicativo', 'Presente'); } setIndicativoPreteritoImperfecto() { this.setTable('Indicativo', 'PreteritoImperfecto'); } setIndicativoPreteritoIndefinido() { this.setTable('Indicativo', 'PreteritoIndefinido'); } setIndicativoFuturoImperfecto() { this.setTable('Indicativo', 'FuturoImperfecto'); } setIndicativoCondicionalSimple() { this.setTable('Indicativo', 'CondicionalSimple'); } setSubjuntivoPresente() { this.setTable('Subjuntivo', 'Presente'); } setSubjuntivoPreteritoImperfectoRa() { this.setTable('Subjuntivo', 'PreteritoImperfectoRa'); } setSubjuntivoPreteritoImperfectoSe() { this.setTable('Subjuntivo', 'PreteritoImperfectoSe'); } setSubjuntivoFuturoImperfecto() { this.setTable('Subjuntivo', 'FuturoImperfecto'); } setCompuestos() { exports.INDICATIVO_COMP_KEYS.forEach(time => this.table.Indicativo[time] = this.auxHaber.Indicativo[time].map((aux, index) => `${this.reflexive ? this.reflexPronouns[index] : ''} ${aux} ${this.participioCompuesto}`.trim())); exports.SUBJUNTIVO_COMP_KEYS.forEach(time => this.table.Subjuntivo[time] = this.auxHaber.Subjuntivo[time].map((aux, index) => `${this.reflexive ? this.reflexPronouns[index] : ''} ${aux} ${this.participioCompuesto}`.trim())); } setImperativoAfirmativo() { if (NO_IMPERATIVO_AFIRMATIVO.includes(this.defectiveAttributes)) { return; } if (!this.reflexive) { if (this.region !== 'formal') { this.table.Imperativo.Afirmativo[1] = this.table.Indicativo.Presente[1].replace(/s$/, ''); } else { this.table.Imperativo.Afirmativo[1] = this.table.Subjuntivo.Presente[1]; } } else { switch (this.region) { case 'formal': this.table.Imperativo.Afirmativo[1] = stringutils_1.esdrujula(this.table.Subjuntivo.Presente[1].replace(/^(.*) (.*)$/, '$2$1')); break; case 'voseo': this.table.Imperativo.Afirmativo[1] = stringutils_1.clearAccents(this.table.Indicativo.Presente[1].replace(/^(.*) (.*)s$/, '$2$1')); break; default: this.table.Imperativo.Afirmativo[1] = stringutils_1.esdrujula(this.table.Indicativo.Presente[1].replace(/^(.*) (.*)s$/, '$2$1')); break; } } if (!this.reflexive) { this.table.Imperativo.Afirmativo[3] = this.table.Subjuntivo.Presente[3]; } else { this.table.Imperativo.Afirmativo[3] = stringutils_1.esdrujula(this.table.Subjuntivo.Presente[3].replace(/^(.*) (.*)s$/, '$2$1')); } if (this.region === 'castellano') { if (!this.reflexive) { this.table.Imperativo.Afirmativo[4] = `${this.verb.replace(/r$/, 'd')}`; } else { this.table.Imperativo.Afirmativo[4] = `${stringutils_1.strongify(stringutils_1.clearAccents(this.verb.replace(/rse$/, '')), 1)}os`; } } else { if (!this.reflexive) { this.table.Imperativo.Afirmativo[4] = this.table.Subjuntivo.Presente[4]; } else { this.table.Imperativo.Afirmativo[4] = stringutils_1.esdrujula(this.table.Subjuntivo.Presente[4].replace(/^(.*) (.*)$/, '$2$1')); } } } setImperativoAfirmativoMono(regex, subP, subNP) { if (this.region === 'castellano' || this.region === 'canarias') { this.table.Imperativo.Afirmativo[1] = this.table.Imperativo.Afirmativo[1].replace(regex, (match, p1) => { if (/^$/.test(p1) || this.reflexive) return `${p1}${subP}`; return `${p1}${subNP}`; }); } } setImperativoNegativo() { if (NO_IMPERATIVO_NEGATIVO.includes(this.defectiveAttributes)) { return; } [1, 3, 4].forEach(index => this.table.Imperativo.Negativo[index] = `no ${this.table.Subjuntivo.Presente[index]}`); } applyDefectiveAttributes() { switch (this.defectiveAttributes) { case 'imorfo': if (/^[^ií]/.test(this.desinences.Impersonal.Gerundio)) { this.table.Impersonal.Gerundio = '-'; } Object.keys(this.desinences.Indicativo).forEach(time => { this.desinences.Indicativo[time].forEach((d, i) => { if (/^[^ií]/.test(d)) { this.table.Indicativo[time][i] = '-'; } }); }); Object.keys(this.desinences.Subjuntivo).forEach(time => { this.desinences.Subjuntivo[time].forEach((d, i) => { if (/^[^ií]/.test(d)) { this.table.Subjuntivo[time][i] = '-'; } }); }); [1, 3, 4].forEach(index => { const last = this.table.Imperativo.Afirmativo[index].split(' ').pop(); if (last && /^[^ií]/.test(last[this.stem.length])) { this.table.Imperativo.Afirmativo[index] = '-'; } this.table.Imperativo.Negativo[index] = '-'; }); break; case 'eimorfo': Object.keys(this.desinences.Indicativo).forEach(time => { this.desinences.Indicativo[time].forEach((d, i) => { if (/^[^iíeé]/.test(d)) { this.table.Indicativo[time][i] = '-'; } }); }); Object.keys(this.desinences.Subjuntivo).forEach(time => { this.desinences.Subjuntivo[time].forEach((d, i) => { if (/^[^iíeé]/.test(d)) { this.table.Subjuntivo[time][i] = '-'; } }); }); [1, 3, 4].forEach(index => { const last = this.table.Imperativo.Afirmativo[index].split(' ').pop(); if (last && /^[^iíeé]/.test(last[this.stem.length])) { this.table.Imperativo.Afirmativo[index] = '-'; } this.table.Imperativo.Negativo[index] = '-'; }); this.table.Indicativo.PreteritoPerfecto[0] = '-'; this.table.Subjuntivo.PreteritoPerfecto = Array.from(DASH6); break; case 'imper': Object.keys(this.table.Indicativo).forEach(time => { [0, 1, 3, 4, 5].forEach(index => this.table.Indicativo[time][index] = '-'); this.table.Indicativo[time][2] = this.table.Indicativo[time][2].replace(/^se /, ''); }); Object.keys(this.table.Subjuntivo).forEach(time => { [0, 1, 3, 4, 5].forEach(index => this.table.Subjuntivo[time][index] = '-'); this.table.Subjuntivo[time][2] = this.table.Subjuntivo[time][2].replace(/^se /, ''); }); break; case 'tercio': ['Gerundio', 'Participio'].forEach(v => this.table.Impersonal[v] = '-'); exports.INDICATIVO_SIMPLE_KEYS.forEach(time => [0, 1, 3, 4].forEach(i => this.table.Indicativo[time][i] = '-')); exports.SUBJUNTIVO_SIMPLE_KEYS.forEach(time => [0, 1, 3, 4].forEach(i => this.table.Subjuntivo[time][i] = '-')); exports.INDICATIVO_COMP_KEYS.forEach(time => this.table.Indicativo[time] = Array.from(DASH6)); exports.SUBJUNTIVO_COMP_KEYS.forEach(time => this.table.Subjuntivo[time] = Array.from(DASH6)); break; case 'terciop': Object.keys(this.table.Indicativo).forEach(time => { [0, 1, 3, 4].forEach(index => this.table.Indicativo[time][index] = '-'); [2, 5].forEach(index => this.table.Indicativo[time][index] = this.table.Indicativo[time][index].replace(/^se /, '')); }); Object.keys(this.table.Subjuntivo).forEach(time => { [0, 1, 3, 4].forEach(index => this.table.Subjuntivo[time][index] = '-'); [2, 5].forEach(index => this.table.Subjuntivo[time][index] = this.table.Subjuntivo[time][index].replace(/^se /, '')); }); break; case 'bimorfop': this.table.Impersonal.Gerundio = '-'; Object.keys(this.table.Indicativo).forEach(time => this.table.Indicativo[time] = Array.from(DASH6)); Object.keys(this.table.Subjuntivo).forEach(time => this.table.Subjuntivo[time] = Array.from(DASH6)); Object.keys(this.table.Imperativo).forEach(time => this.table.Imperativo[time] = Array.from(DASH6)); break; case 'bimorfog': this.table.Impersonal.Participio = '-'; Object.keys(this.table.Indicativo).forEach(time => this.table.Indicativo[time] = Array.from(DASH6)); Object.keys(this.table.Subjuntivo).forEach(time => this.table.Subjuntivo[time] = Array.from(DASH6)); Object.keys(this.table.Imperativo).forEach(time => this.table.Imperativo[time] = Array.from(DASH6)); break; case 'trimorfo': ['Gerundio', 'Participio'].forEach(v => this.table.Impersonal[v] = '-'); Object.keys(this.table.Indicativo).forEach(time => this.table.Indicativo[time] = Array.from(DASH6)); Object.keys(this.table.Subjuntivo).forEach(time => this.table.Subjuntivo[time] = Array.from(DASH6)); Object.keys(this.table.Imperativo).forEach(mode => [2, 3].forEach(index => this.table.Imperativo[mode][index] = '-')); break; case 'omorfo': ['PreteritoIndefinido', 'FuturoImperfecto', 'CondicionalSimple', 'PreteritoAnterior', 'FuturoPerfecto', 'CondicionalCompuesto'].forEach(mode => this.table.Indicativo[mode] = Array.from(DASH6)); ['FuturoImperfecto', 'FuturoPerfecto'].forEach(time => this.table.Subjuntivo[time] = Array.from(DASH6)); this.table.Imperativo.Negativo[3] = '-'; break; case 'ogmorfo': ['Infinitivo', 'Gerundio', 'Participio'].forEach(v => this.table.Impersonal[v] = '-'); ['Presente', 'PreteritoImperfecto', 'FuturoImperfecto', 'CondicionalSimple', ...exports.INDICATIVO_COMP_KEYS].forEach(mode => this.table.Indicativo[mode] = Array.from(DASH6)); ['Presente', 'FuturoImperfecto', ...exports.SUBJUNTIVO_COMP_KEYS].forEach(mode => this.table.Subjuntivo[mode] = Array.from(DASH6)); break; case 'osmorfo': this.table.Impersonal.Participio = '-'; ['PreteritoIndefinido', 'FuturoImperfecto', 'CondicionalSimple', ...exports.INDICATIVO_COMP_KEYS].forEach(mode => this.table.Indicativo[mode] = Array.from(DASH6)); ['FuturoImperfecto', ...exports.SUBJUNTIVO_COMP_KEYS].forEach(mode => this.table.Subjuntivo[mode] = Array.from(DASH6)); this.table.Imperativo.Negativo[3] = '-'; break; } } setIndicativoPresentePattern125(dot, star) { switch (this.region) { case 'castellano': this.setTable('Indicativo', 'Presente', [dot, star, star, this.stem, this.stem, star]); break; case 'voseo': this.setTable('Indicativo', 'Presente', [dot, this.stem, star, this.stem, star, star]); break; case 'canarias': case 'formal': this.setTable('Indicativo', 'Presente', [dot, star, star, this.stem, star, star]); break; } } setSubjuntivoPresentePattern0125(dot, star = this.stem) { switch (this.region) { case 'castellano': this.setTable('Subjuntivo', 'Presente', [dot, dot, dot, star, star, dot]); break; case 'voseo': case 'canarias': case 'formal': this.setTable('Subjuntivo', 'Presente', [dot, dot, dot, star, dot, dot]); break; } } setIndicativoPreteritoIndefinidoPattern0(dot) { this.setTable('Indicativo', 'PreteritoIndefinido', [dot, ...Array.from('12345').map(() => this.stem)]); } setIndicativoPreteritoIndefinidoPattern25(dot) { switch (this.region) { case 'castellano': this.setTable('Indicativo', 'PreteritoIndefinido', [this.stem, this.stem, dot, this.stem, this.stem, dot]); break; case 'voseo': case 'canarias': this.setTable('Indicativo', 'PreteritoIndefinido', [this.stem, this.stem, dot, this.stem, dot, dot]); break; case 'formal': this.setTable('Indicativo', 'PreteritoIndefinido', [this.stem, dot, dot, this.stem, dot, dot]); break; } } } exports.BaseModel = BaseModel; //# sourceMappingURL=basemodel.js.map