transcriptor-fonologico
Version:
Un simple transcriptor fonológico para la lengua española.
130 lines • 4.98 kB
JavaScript
"use strict";
function Transcribir(texto,v,y,s,n,l) {
// Texto configuración.
texto = texto.toString();
if ( texto.length == 0 ) { return ""; };
if ( v == 1 || v == 2 || v == 3 ) { true; } else { return false; }; // Versión : 1 o 2 o 3
if ( y == 0 || y == 1 ) { true; } else { return false; }; // Yeísmo : 0 o 1
if ( s == 0 || s == 1 ) { true; } else { return false; }; // Seseo : 0 o 1
if ( n == 0 || n == 1 ) { true; } else { return false; }; // Neísmo : 0 o 1
if ( l == 0 || l == 1 ) { true; } else { return false; }; // Leleo : 0 o 1
// Versión 1
// Mayúsculas a minúsculas
texto = texto.toLowerCase();
// Tildes arreglo.
texto = texto.replace(/á/g,"aá").replace(/é/g,"eé").replace(/í/g,"ií").replace(/ó/g,"oó").replace(/ú/g,"uú");
// La letra 'v' se reemplaza por la letra 'b'.
texto = texto.replace(/v/g,"b");
// Combinación nb arreglo.
texto = texto.replace(/nb/g,"mb");
// La letra 'c' se reemplaza por la letra 'z' en las combinaciones 'ce' y 'ci'.
texto = texto.replace(/ce/g,"ze").replace(/ci/g,"zi");
// La letra fuerte 'g' se reemplaza por la letra 'j' en las combinaciones 'ge' y 'gi'.
texto = texto.replace(/ge/g,"je").replace(/gi/g,"ji");
// El dígrafo 'gu' se reemplaza por la letra suave 'g' en las combinaciones 'gue' y 'gui'.
texto = texto.replace(/gue/g,"ge").replace(/gui/g,"gi");
// El dígrafo 'qu' se reemplaza por la letra 'k' en las combinaciones 'que' y 'qui'.
texto = texto.replace(/que/g,"ke").replace(/qui/g,"ki");
// La letra 'q' se reemplaza por la letra 'k'.
texto = texto.replace(/q/g,"k");
// La letra 'c' se reemplaza por la letra 'k'.
texto = texto.replace(/ch/g,"æý");
texto = texto.replace(/c/g,"k");
texto = texto.replace(/æý/g,"ch");
// La letra vocal 'y' se reemplaza por la letra vocal 'i'.
texto = texto.replace(/ya/g,"çaç").replace(/ye/g,"çeç").replace(/yi/g,"çiç").replace(/yo/g,"çoç").replace(/yu/g,"çuç");
texto = texto.replace(/y/g,"i");
texto = texto.replace(/çaç/g,"ya").replace(/çeç/g,"ye").replace(/çiç/g,"yi").replace(/çoç/g,"yo").replace(/çuç/g,"yu");
// La letra muda 'h' desaparece.
texto = texto.replace(/ch/g,"æý");
texto = texto.replace(/h/g,"");
texto = texto.replace(/æý/g,"ch");
// La diéresis 'ü' desaparece.
texto = texto.replace(/ü/g,"u");
// La letra fuerte 'r' se reemplaza por el dígrafo 'rr'.
texto = " " + texto;
texto = texto.replace(/([^a-zA-ZáéíóúüñÁÉÍÓÚÜÑ.-])r/g,"$1rr");
texto = texto.replace(/nr/g,"nrr").replace(/lr/g,"lrr").replace(/sr/g,"srr");
texto = texto.trim();
// La letra 'x' se reemplaza por las letras 'k','s','j' o la combinación 'ks' según el contexto.
texto = " " + texto;
texto = texto.replace(/([^a-zA-ZáéíóúüñÁÉÍÓÚÜÑ.-])x/g,"$1çæç");
texto = texto.replace(/x/g,"ks").replace(/kss/g,"ks").replace(/ksz/g,"kz");
texto = texto.replace(/çæç/g,"s");
texto = texto.trim();
// Yeísmo
// El dígrafo 'll' se reemplaza por la letra 'y'.
if ( y == 1 ) {
texto = texto.replace(/ll/g,"y");
};
// Seseo
// La letra 'z' se reemplaza por la letra 's'.
if ( s == 1 ) {
texto = texto.replace(/z/g,"s");
};
// Neísmo
// La letra 'ñ' se reemplaza por la combinación 'ni'.
if ( n == 1 ) {
texto = texto.replace(/ñi/g,"ni").replace(/ñ/g,"ni");
};
// Leleo
// El dígrafo 'rr' y la letra 'r' se reemplazan por la letra 'l'.
if ( l == 1 ) {
texto = texto.replace(/rr/g,"l");
texto = texto.replace(/r/g,"l");
};
// Versión 2
// El dígrafo 'ch' se reemplaza por la letra 'c'.
if ( v == 2 ) {
texto = texto.replace(/ch/g,"c");
};
// El dígrafo 'll' se reemplaza por la letra 'h'.
if ( v == 2 ) {
texto = texto.replace(/ll/g,"h");
};
// El dígrafo 'rr' se reemplaza por la letra 'v'.
if ( v == 2 ) {
texto = texto.replace(/rr/g,"v");
};
// Versión 3
// El dígrafo 'ch' se reemplaza por el símbolo 't͡ʃ'.
if ( v == 3 ) {
texto = texto.replace(/ch/g,"t͡ʃ");
};
// La letra 'j' se reemplaza por la letra 'x'.
if ( v == 3 ) {
texto = texto.replace(/j/g,"x");
};
// El dígrafo 'll' se reemplaza por la letra 'ʎ'.
if ( v == 3 ) {
texto = texto.replace(/ll/g,"ʎ");
};
// La letra 'ñ' se reemplaza por la letra 'ɲ'.
if ( v == 3 ) {
texto = texto.replace(/ñ/g,"ɲ");
};
// La letra 'r' se reemplaza por la letra 'ɾ'.
if ( v == 3 ) {
texto = texto.replace(/rr/g,"æý");
texto = texto.replace(/r/g,"ɾ");
texto = texto.replace(/æý/g,"rr");
};
// El dígrafo 'rr' se reemplaza por la letra 'r'.
if ( v == 3 ) {
texto = texto.replace(/rr/g,"r");
};
// La letra 'y' se reemplaza por la letra 'ʝ'.
if ( v == 3 ) {
texto = texto.replace(/y/g,"ʝ");
};
// La letra 'z' se reemplaza por la letra 'θ'.
if ( v == 3 ) {
texto = texto.replace(/z/g,"θ");
};
// Tildes arreglo.
texto = texto.replace(/aá/g,"á").replace(/eé/g,"é").replace(/ií/g,"í").replace(/oó/g,"ó").replace(/uú/g,"ú");
// Resultado final
return texto;
};
// Módulo
module.exports = { Transcribir };