1// sinhala unicode -> easy singlish 2var singlish_vowels = [ 3 ['à¶ ', 'a'], 4 ['à¶', 'aa'], 5 ['à¶', 'ae'], 6 ['à¶', 'ae, aee'], 7 ['à¶', 'i'], 8 ['à¶', 'ii'], 9 ['à¶', 'u'], 10 ['à¶', 'uu'], 11 ['à¶', 'e'], 12 ['à¶', 'ee'], 13 ['à¶', 'o'], 14 ['à¶', 'oo'], 15 ['à¶', 'ai'], // sinhala only begin 16 ['à¶', 'ou'], 17 ['à¶', 'ru'], 18 ['à¶', 'ru, ruu'], 19 ['à¶', 'li'], 20 ['à¶', 'li, lii'] // sinhala only end 21]; 22 23var singlish_specials = [ 24 ['à¶à·', 'n'], 25 ['à¶', 'n, m'], 26 ['à¶', 'n, m'] // sinhala only 27]; 28 29var singlish_consonants = [ 30 ['à¶', 'k'], 31 ['à¶', 'g'], 32 ['à¶ ', 'c, ch'], 33 ['à¶¢', 'j'], 34 ['ඤ', 'n, kn'], 35 ['à¶§', 't'], 36 ['à¶©', 'd'], 37 ['à¶«', 'n'], 38 ['à¶', 'th'], 39 ['ද', 'd'], 40 ['à¶±', 'n'], 41 ['à¶´', 'p'], 42 ['à¶¶', 'b'], 43 ['ම', 'm'], 44 ['ය', 'y'], 45 ['à¶»', 'r'], 46 ['à¶½', 'l'], 47 ['à·', 'v, w'], 48 ['à·', 'sh'], 49 ['à·', 'sh'], 50 ['à·', 's'], 51 ['à·', 'h'], 52 ['à· ', 'l'], 53 ['à·', 'f'], 54 55 ['à¶', 'kh, k'], 56 ['ඨ', 'th'], 57 ['à¶', 'gh'], 58 ['à¶', 'ng'], 59 ['à¶¡', 'ch'], 60 ['à¶£', 'jh'], 61 ['ඦ', 'nj'], 62 ['ඪ', 'dh'], 63 ['ඬ', 'nd'], 64 ['à¶®', 'th'], 65 ['à¶°', 'dh'], 66 ['à¶³', 'nd'], 67 ['à¶µ', 'ph'], 68 ['à¶·', 'bh'], 69 ['à¶¹', 'mb'], 70 ['à¶¥', 'gn'] // sinhala only 71]; 72 73// sinh before, sinh after, roman after 74var singlish_combinations = [ 75 ['à·', ''], //à¶à· 76 ['', 'a'], //à¶ 77 ['à·', 'a, aa'], //à¶à· 78 ['à·', 'ae'], 79 ['à·', 'ae, aee'], 80 ['à·', 'i'], 81 ['à·', 'i, ii'], 82 ['à·', 'u'], 83 ['à·', 'u, uu'], 84 ['à·', 'e'], 85 ['à·', 'e, ee'], 86 ['à·', 'ei'], 87 ['à·', 'o'], 88 ['à·', 'o, oo'], 89 90 ['à·âà¶»', 'ra'], //à¶à·âà¶» 91 ['à·âà¶»à·', 'ra, raa'], //à¶à·âර෠92 ['à·âà¶»à·', 'rae'], 93 ['à·âà¶»à·', 'rae, raee'], 94 ['à·âà¶»à·', 'ri'], 95 ['à·âà¶»à·', 'ri, rii'], 96 ['à·âà¶»à·', 're'], 97 ['à·âà¶»à·', 're, ree'], 98 ['à·âà¶»à·', 'rei'], 99 ['à·âà¶»à·', 'ro'], 100 ['à·âà¶»à·', 'ro, roo'], 101 102 ['à·âය', 'ya'], //à¶à·âය 103 ['à·âයà·', 'ya, yaa'], //à¶à·âය෠104 ['à·âයà·', 'yae'], 105 ['à·âයà·', 'yae, yaee'], 106 ['à·âයà·', 'yi'], 107 ['à·âයà·', 'yi, yii'], 108 ['à·âයà·', 'yu'], 109 ['à·âයà·', 'yu, yuu'], 110 ['à·âයà·', 'ye'], 111 ['à·âයà·', 'ye, yee'], 112 ['à·âයà·', 'yei'], 113 ['à·âයà·', 'yo'], 114 ['à·âයà·', 'yo, yoo'], 115 116 ['à·', 'ru'], // sinhala only begin 117 ['à·²', 'ru, ruu'], 118 ['à·', 'au'], 119 ['à·', 'li'], 120 ['à·³', 'li, lii'] // sinhala only end 121]; 122 123var singlishMapping = []; 124var maxSinglishKeyLen = 0; 125function addToSinglishMapping(values, pSinhStr, pRomanStr) { 126 $.each(values, function (_1, pair) { 127 sinh = pair[0] + pSinhStr; 128 129 romans = pair[1].split(','); 130 pRomans = pRomanStr.split(','); 131 $.each(romans, function (_2, roman) { 132 $.each(pRomans, function (_2, pRoman) { 133 mapIndex = roman.trim() + pRoman.trim(); 134 if (mapIndex in singlishMapping) { 135 singlishMapping[mapIndex].push(sinh); 136 } else { 137 singlishMapping[mapIndex] = [sinh]; 138 maxSinglishKeyLen = Math.max(mapIndex.length, maxSinglishKeyLen); 139 } 140 }); 141 }); 142 }); 143} 144 145addToSinglishMapping(singlish_vowels, '', ''); 146addToSinglishMapping(singlish_specials, '', ''); 147$.each(singlish_combinations, function(i, combi) { 148 addToSinglishMapping(singlish_consonants, combi[0], combi[1]); 149}); 150console.log(singlishMapping); 151console.log('maxSinglishKeyLen: '+ maxSinglishKeyLen); 152 153 154function getPossibleMatches(input) { 155 var matches = []; 156 for (var len = 1; len <= maxSinglishKeyLen && len <= input.length; len++) { 157 var prefix = input.slice(0, len); var rest = input.slice(len); 158 matches = matches.concat(permuteMatches(prefix, rest)); 159 } 160 return matches; 161} 162 163function permuteMatches(prefix, rest) { 164 // if prefix is all sinhala then pass through the prefix - this allows sinhala and singlish mixing and ending dot 165 var prefixMappings = isSinglishQuery(prefix) ? singlishMapping[prefix] : [prefix]; 166 if (!prefixMappings) { // recursion ending condition 167 return []; 168 } 169 if (!rest) { // recursion ending condition 170 return prefixMappings; 171 } 172 var restMappings = getPossibleMatches(rest); 173 var fullMappings = []; 174 $.each(restMappings, function (_1, restM) { 175 $.each(prefixMappings, function (_2, prefixM) { 176 fullMappings.push(prefixM + restM); 177 }); 178 }); 179 return fullMappings; 180} 181 182function isSinglishQuery(query) { 183 var A = "A".charCodeAt(0); 184 var Z = "Z".charCodeAt(0); 185 var a = "a".charCodeAt(0); 186 var z = "z".charCodeAt(0); 187 188 for (var i = 0; i < query.length; i++) {
189 var c = query.charCodeAt(i); 190 if ((c <= Z && c >= A) || (c <= z && c >= a)) { 191 return true; 192 } 193 } 194 return false; 195}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.