const consPhoneme = [ ["b", "p", "f"], ["d", "t"], ["g", "k"], ["h", "f"], ["j", "q", "zh", "ch", "z", "c"], ["x", "sh", "s"], ["l", "r"], ["B", "P", "F"], ["D", "T"], ["G", "K"], ["H", "F"], ["J", "Q", "Zh", "Ch", "Z", "C"], ["X", "Sh", "S"], ["L", "R"], ["H", "F"], ["ng"], ]; const vowPhoneme = [ ["ā", "á", "ǎ", "à"], ["ī", "í", "ǐ", "ì"], ["ū", "ú", "ǔ", "ù"], ["ē", "é", "ě", "è"], ["ō", "ó", "ǒ", "ò"], ]; let consPhonemeType; let foundConsPhoneme = []; let foundVowPhoneme = []; let consWrongList = []; let wrongList = []; let consWrong; let vowWrong; let zhCheck = -1; let chCheck = -1; let shCheck = -1; let ngCheck = -1; let ZhCheck = -1; let ChCheck = -1; let ShCheck = -1; let NgCheck = -1; function mkWrongChoice(choice){ foundConsPhoneme = []; foundVowPhoneme = []; consWrongList = []; wrongList = []; //zh, ch, sh, ng の例外処理が必要 zhCheck = choice.indexOf("zh"); chCheck = choice.indexOf("ch"); shCheck = choice.indexOf("sh"); ngCheck = choice.indexOf("ng"); ZhCheck = choice.indexOf("Zh"); ChCheck = choice.indexOf("Ch"); ShCheck = choice.indexOf("Sh"); NgCheck = choice.indexOf("Ng"); //子音探索 for(let i = 0; i < consPhoneme.length; ++i){ for(let j = 0; j < consPhoneme[i].length; ++j){ if(choice.indexOf(consPhoneme[i][j]) != -1){ //hの例外処理 if(consPhoneme[i][j] == "h"){ if(zhCheck + chCheck + shCheck + ZhCheck + ChCheck + ShCheck > -6){ if(zhCheck + 1 == choice.indexOf(consPhoneme[i][j])){ continue; }else if(chCheck + 1 == choice.indexOf(consPhoneme[i][j])){ continue; }else if(shCheck + 1 == choice.indexOf(consPhoneme[i][j])){ continue; }else if(ZhCheck + 1 == choice.indexOf(consPhoneme[i][j])){ continue; }else if(ChCheck + 1 == choice.indexOf(consPhoneme[i][j])){ continue; }else if(ShCheck + 1 == choice.indexOf(consPhoneme[i][j])){ continue; }else{ foundConsPhoneme.push([i, j]); } }else{ foundConsPhoneme.push([i, j]); } //zの例外処理 }else if(consPhoneme[i][j] == "z" && zhCheck != -1){ if(zhCheck == choice.indexOf(consPhoneme[i][j])){ continue; }else{ foundConsPhoneme.push([i, j]); } //cの例外処理 }else if(consPhoneme[i][j] == "c" && chCheck != -1){ if(chCheck == choice.indexOf(consPhoneme[i][j])){ continue; }else{ foundConsPhoneme.push([i, j]); } //sの例外処理 }else if(consPhoneme[i][j] == "s" && shCheck != -1){ if(shCheck == choice.indexOf(consPhoneme[i][j])){ continue; }else{ foundConsPhoneme.push([i, j]); } //Zの例外処理 }else if(consPhoneme[i][j] == "Z" && ZhCheck != -1){ if(ZhCheck == choice.indexOf(consPhoneme[i][j])){ continue; }else{ foundConsPhoneme.push([i, j]); } //Cの例外処理 }else if(consPhoneme[i][j] == "C" && ChCheck != -1){ if(ChCheck == choice.indexOf(consPhoneme[i][j])){ continue; }else{ foundConsPhoneme.push([i, j]); } //Sの例外処理 }else if(consPhoneme[i][j] == "S" && ShCheck != -1){ if(ShCheck == choice.indexOf(consPhoneme[i][j])){ continue; }else{ foundConsPhoneme.push([i, j]); } //gの例外処理 }else if(consPhoneme[i][j] == "g"){ if(ngCheck + NgCheck > -2){ if(ngCheck + 1 == choice.indexOf(consPhoneme[i][j])){ continue; }else if(NgCheck + 1 == choice.indexOf(consPhoneme[i][j])){ continue; }else{ foundConsPhoneme.push([i, j]); } }else{ foundConsPhoneme.push([i, j]); } //例外でない状態 }else{ foundConsPhoneme.push([i, j]); } //素通り }else{ continue; } } } //同グループの自分以外の子音に置換される for(let i = 0; i < foundConsPhoneme.length; ++i){ if(consPhoneme[foundConsPhoneme[i][0]][foundConsPhoneme[i][1]] == "ng"){ consWrong = choice.replace("ng", "n") consWrongList.push(consWrong) }else{ for(let j = 0; j < consPhoneme[foundConsPhoneme[i][0]].length; j++){ if(j == foundConsPhoneme[i][1]) continue; consWrong = choice.replace(consPhoneme[foundConsPhoneme[i][0]][foundConsPhoneme[i][1]], consPhoneme[foundConsPhoneme[i][0]][j]) consWrongList.push(consWrong) } } } consWrongList.push(choice) //母音探索 for(let i = 0; i < vowPhoneme.length; ++i){ for(let j = 0; j < vowPhoneme[i].length; ++j){ if(choice.indexOf(vowPhoneme[i][j]) != -1){ foundVowPhoneme.push([i, j]); }else{ continue; } } } //consWrongListの全語の母音が、同グループの自分以外の母音に置換される for(let k = 0; k < consWrongList.length; ++k){ for(let i = 0; i < foundVowPhoneme.length; ++i){ if(vowPhoneme[foundVowPhoneme[i][0]][foundVowPhoneme[i][1]] == "ng"){ vowWrong = consWrongList[k].replace("ng", "n") wrongList.push(vowWrong) }else{ for(let j = 0; j < vowPhoneme[foundVowPhoneme[i][0]].length; j++){ if(j == foundVowPhoneme[i][1]) continue; vowWrong = consWrongList[k].replace(vowPhoneme[foundVowPhoneme[i][0]][foundVowPhoneme[i][1]], vowPhoneme[foundVowPhoneme[i][0]][j]) wrongList.push(vowWrong) } } } } console.log({wrongList}); return wrongList; }