firstAndLast method
Implementation
Map firstAndLast(String latin) {
var ret = {};
String firstStr = latin.substring(0, 1);
String secondStr = latin.substring(1, 2);
String lastStr = latin.substring(latin.length - 1, latin.length);
String prelastStr = latin.substring(latin.length - 2, latin.length - 1);
String resultFirst = "";
var resultLast = [];
if (wordMap.containsKey(firstStr)) {
resultFirst = wordMap[firstStr][3];
String x = firstStr;
//2020.3.13
// solving b,p,k,f before o,u
if (x == "b" || x == "p" || x == "k" || x == "f") {
String y = secondStr;
if (y == "o" || y == "u" || y == "v" || y == "U") {
resultFirst = wordMap[x][4];
}
}
// solving h,g before e,i,w
if (x == "h" || x == "g") {
String y = secondStr;
if (y == "e" || y == "i" || y == "w") {
resultFirst = wordMap[x][4];
}
}
//2021.3.13
// solving h,g before u
if (x == "h" || x == "g") {
String y = secondStr;
if (y == "u" || y == "U") {
resultFirst = wordMap[x][5];
}
}
//solving last letter;
if (wordMap.containsKey(lastStr)) {
String pTemp = wordMap[lastStr][9];
if (pTemp.isNotEmpty) {
//resultLast = pTemp;
resultLast.add(pTemp);
}
}
x = prelastStr;
// solving a after b,p,k,f test haha baba
if (x == "b" || x == "p" || x == "k" || x == "f") {
String y = lastStr;
if (y == "a") {
//resultLast = wordMap[y][10];
if (resultLast.isNotEmpty) {
resultLast.clear();
}
resultLast.add(wordMap[y][10]);
}
}
// solving e after h,g
if (x == "h" || x == "g") {
String y = lastStr;
if (y == "e") {
//resultLast = wordMap[y][9];
if (resultLast.isNotEmpty) {
resultLast.clear();
}
resultLast.add(wordMap[y][9]);
}
}
// solving i after b,p,k,f,h,g
if (x == "b" ||
x == "p" ||
x == "k" ||
x == "f" ||
x == "h" ||
x == "g") {
String y = lastStr;
if (y == "i") {
//resultLast = wordMap[y][10];
if (resultLast.isNotEmpty) {
resultLast.clear();
}
resultLast.add(wordMap[y][10]);
}
}
// solving o after b,p,k,f
if (x == "b" || x == "p" || x == "k" || x == "f") {
String y = lastStr;
if (y == "o" || y == "v") {
//resultLast = wordMap[y][10];
if (resultLast.isNotEmpty) {
resultLast.clear();
}
resultLast.add(wordMap[y][10]);
}
}
// solving u after b,p,k,f,h,g
if (x == "b" ||
x == "p" ||
x == "k" ||
x == "f" ||
x == "h" ||
x == "g") {
String y = lastStr;
if (y == "u") {
//resultLast = wordMap[y][10];
if (resultLast.isNotEmpty) {
resultLast.clear();
}
resultLast.add(wordMap[y][10]);
}
}
// solving h g after i,e,u, U
if (x == "i" || x == "e" || x == "u" || x == "U") {
String y = lastStr;
if (y == "g" || y == "h") {
//resultLast = wordMap[y][11];
if (resultLast.isNotEmpty) {
resultLast.clear();
}
resultLast.add(wordMap[y][11]);
}
}
// solving g after n
if (x == "n") {
String y = lastStr;
if (y == "g") {
//resultLast = wordMap[y][11];
if (resultLast.isNotEmpty) {
resultLast.clear();
}
resultLast.add(wordMap[y][11]);
}
}
// solving a, e after n, m, l, y, r
if (x == "n" || x == "m" || x == "l" || x == "y" || x == "r") {
String y = lastStr;
if (y == "a" || y == "e") {
//resultLast = wordMap[y][11];
if (resultLast.isNotEmpty) {
resultLast.clear();
}
resultLast.add(wordMap[y][11]);
}
}
// solving e after c, v, z, q, d
if (x == "c" || x == "v" || x == "z" || x == "q" || x == "d") {
String y = lastStr;
if (y == "e") {
//resultLast = wordMap[y][10];
if (resultLast.isNotEmpty) {
resultLast.clear();
}
resultLast.add(wordMap[y][10]);
}
}
// solving a, after h, g
if (x == "h" || x == "g") {
String y = lastStr;
if (y == "a") {
//resultLast = wordMap[y][11];
if (resultLast.isNotEmpty) {
resultLast.clear();
}
resultLast.add(wordMap[y][11]);
}
}
// solving a, after n, m, h, g, for isolated na, ma, ha, ga
if (x == "n" || x == "m" || x == "h" || x == "g") {
String y = lastStr;
if (y == "a") {
if (2 == latin.length) {
//resultLast = wordMap[y][9];
if (resultLast.isNotEmpty) {
resultLast.clear();
}
resultLast.add(wordMap[y][9]);
}
}
}
}
ret['first'] = resultFirst;
ret['last'] = resultLast;
return ret;
}