// Create lists of phonetically balanced CVC
// (consonant-vowel-consonant) monosyllabic 
// nonsense words
// The phonetic balance is optimized for Spanish
// (Argentinean variant).
//
// Variables:
// phons:    Names of the phonemes
// letters:  Letters used to represent the phonemes
// Pphons:   Empirical probability of the phonemes 
// CVC_list: Vector of CVC words whose phonemes have
//           the same probability as in a long text
//           for each position in the CVCs  
// 
// ------------------------------
// Federico Miyara
// 2024-11-27
// 2025-01-14

// Data
phons  =   ["a"        "b"        "bb"       "s"        "k"   ..
            "ch"       "d"        "dd"       "e"        "f"   ..
            "gg"       "j"        "i"        "l"        "m"   ..
            "n"        "nn"       "o"        "p"        "r"   ..
            "rr"       "sh"       "t"        "u"        "x"   ..
            "yy"];
letters =  ["a"        "b"        "b"        "s"        "k"   ..
            "ch"       "d"        "d"        "e"        "f"   ..
            "g"        "j"        "i"        "l"        "m"   ..
            "n"        "ñ"        "o"        "p"        "r"   ..
            "r"        "sh"       "t"        "u"        "x"   ..
            "y"];
Pphons =   [13.810247  0.3790809  2.6674982  8.6511912  3.8818308 ..
            0.2729329  0.8915102  3.8903226  13.657527  0.6141986 ..
            0.9847877  0.8203910  7.2780347  5.1760398  3.0639608 ..
            6.7738319  0.1373289  9.7749000  2.6307444  5.8414548 ..
            0.6644862  0.0074304  4.4174799  3.0096926  0.1097305 ..
            0.5933671];

// Indices of consonants that can be at the
// beginning. For instance, intervocalic /b/
// and /d/ are excluded 
Xcons1 = [2 4 5 6 7 10 11 12 14 15 16 17 19 21 22 23 25 26];

// Indices of vowels
Xvowel = [1 9 13 18 24];

// Indices of consonants that can be at the 
// end. For instance, prevocalic /b/ and /d/
// as well as /ñ/ and /rr/ are excluded
Xcons2 = [3 4 5 6 8 10 11 12 14 15 16 19 20 22 23 25];

// Indices corresponding to initial consonants
// sampled from Xcons1 assuming probabilities
// proportional to the corresponding ones from
// Pfons (these probabilities are regarding to
// any appearances in a long text, but are not
// probabilities if some phonemes are excluded
// since they do not add to 1. 
C1 = samplef(100, Xcons1, Pphons(Xcons1));

// Indices corresponding to vowels sampled from 
// Xvowel assuming probabilities proportional to
// the corresponding ones from Pfons
V =  samplef(100, Xvowel, Pphons(Xvowel));

// Indices corresponding to ending consonants
// sampled from Xcons2 assuming probabilities
// proportional to the corresponding ones from
// Pfons 
C2 = samplef(100, Xcons2, Pphons(Xcons2));

// List of CVC words
CVC_list = letters(C1) + letters(V) + letters(C2);

// Prepare list for display in a human-readable
// way
cvc_list = matrix(CVC_list, 10,10)
CVC = emptystr(10,1);
for i=1:10
   for j=1:10
      CVC(i) = CVC(i) + cvc_list(i,j) + "  ";
   end
end
// Display list
mprintf("\nLista de sílabas CVC\n")
mprintf("%s \n",CVC)

