'use strict'; var OmicronLab = {}; OmicronLab.Avro = {}; OmicronLab.Avro.Phonetic = { parse: function(input) { var fixed = this.fixString(input); var output = ""; for(var cur = 0; cur < fixed.length; ++cur) { var start = cur, end = cur + 1, prev = start - 1; var matched = false; for(var i = 0; i < this.data.patterns.length; ++i) { var pattern = this.data.patterns[i]; end = cur + pattern.f.length; if(end <= fixed.length && fixed.substring(start, end) == pattern.f) { prev = start - 1; if(typeof pattern.rules !== 'undefined') { for(var j = 0; j < pattern.rules.length; ++j) { var rule = pattern.rules[j]; var r = true; var chk = 0; for(var k=0; k < rule.matches.length; ++k) { var match = rule.matches[k]; if(match.type === "suffix") { chk = end; } // Prefix else { chk = prev; } // Handle Negative if(typeof match.negative === 'undefined') { match.negative = false; if(match.scope.charAt(0) === '!') { match.negative = true; match.scope = match.scope.substring(1); } } // Handle empty value if(typeof match.value === 'undefined') match.value = ''; // Beginning if(match.scope === "punctuation") { if( ! ( ((chk < 0) && (match.type === "prefix")) || ((chk >= fixed.length) && (match.type === "suffix")) || this.isPunctuation(fixed.charAt(chk)) ) ^ match.negative ) { r = false; break; } } // Vowel else if(match.scope === "vowel") { if( ! ( ( (chk >= 0 && (match.type === "prefix")) || (chk < fixed.length && (match.type === "suffix")) ) && this.isVowel(fixed.charAt(chk)) ) ^ match.negative ) { r = false; break; } } // Consonant else if(match.scope === "consonant") { if( ! ( ( (chk >= 0 && (match.type === "prefix")) || (chk < fixed.length && match.type === ("suffix")) ) && this.isConsonant(fixed.charAt(chk)) ) ^ match.negative ) { r = false; break; } } // Exact else if(match.scope === "exact") { var s, e; if(match.type === "suffix") { s = end; e = end + match.value.length; } // Prefix else { s = start - match.value.length; e = start; } if(!this.isExact(match.value, fixed, s, e, match.negative)) { r = false; break; } } } if(r) { output += rule.r; cur = end - 1; matched = true; break; } } } if(matched == true) break; // Default output += pattern.r; cur = end - 1; matched = true; break; } } if(!matched) { output += fixed.charAt(cur); } } return output; }, fixString: function(input) { var fixed = ''; for(var i=0; i < input.length; ++i) { var cChar = input.charAt(i); if(this.isCaseSensitive(cChar)) { fixed += cChar; } else { fixed += cChar.toLowerCase(); } } return fixed; }, isVowel: function(c) { return (this.data.vowel.indexOf(c.toLowerCase()) >= 0); }, isConsonant: function(c) { return (this.data.consonant.indexOf(c.toLowerCase()) >= 0); }, isPunctuation: function(c) { return (!(this.isVowel(c) || this.isConsonant(c))); }, isExact: function(needle, heystack, start, end, not) { return ((start >= 0 && end < heystack.length && (heystack.substring(start, end) === needle)) ^ not); }, isCaseSensitive: function(c) { return (this.data.casesensitive.indexOf(c.toLowerCase()) >= 0); }, data: { "patterns": [ { "f":"bhl", "r":"ভ্ল" }, { "f":"psh", "r":"পশ" }, { "f":"bdh", "r":"ব্ধ" }, { "f":"bj", "r":"ব্জ" }, { "f":"bd", "r":"ব্দ" }, { "f":"bb", "r":"ব্ব" }, { "f":"bl", "r":"ব্ল" }, { "f":"bh", "r":"ভ" }, { "f":"vl", "r":"ভ্ল" }, { "f":"b", "r":"ব" }, { "f":"v", "r":"ভ" }, { "f":"cNG", "r":"চ্ঞ" }, { "f":"cch", "r":"চ্ছ" }, { "f":"cc", "r":"চ্চ" }, { "f":"ch", "r":"ছ" }, { "f":"c", "r":"চ" }, { "f":"dhn", "r":"ধ্ন" }, { "f":"dhm", "r":"ধ্ম" }, { "f":"dgh", "r":"দ্ঘ" }, { "f":"ddh", "r":"দ্ধ" }, { "f":"dbh", "r":"দ্ভ" }, { "f":"dv", "r":"দ্ভ" }, { "f":"dm", "r":"দ্ম" }, { "f":"DD", "r":"ড্ড" }, { "f":"Dh", "r":"ঢ" }, { "f":"dh", "r":"ধ" }, { "f":"dg", "r":"দ্গ" }, { "f":"dd", "r":"দ্দ" }, { "f":"D", "r":"ড" }, { "f":"d", "r":"দ" }, { "f":"...", "r":"..." }, { "f":".`", "r":"." }, { "f":"..", "r":"।।" }, { "f":"ghn", "r":"ঘ্ন" }, { "f":"Ghn", "r":"ঘ্ন" }, { "f":"gdh", "r":"গ্ধ" }, { "f":"Gdh", "r":"গ্ধ" }, { "f":"gN", "r":"গ্ণ" }, { "f":"GN", "r":"গ্ণ" }, { "f":"gn", "r":"গ্ন" }, { "f":"Gn", "r":"গ্ন" }, { "f":"gm", "r":"গ্ম" }, { "f":"Gm", "r":"গ্ম" }, { "f":"gl", "r":"গ্ল" }, { "f":"Gl", "r":"গ্ল" }, { "f":"gg", "r":"জ্ঞ" }, { "f":"GG", "r":"জ্ঞ" }, { "f":"Gg", "r":"জ্ঞ" }, { "f":"gG", "r":"জ্ঞ" }, { "f":"gh", "r":"ঘ" }, { "f":"Gh", "r":"ঘ" }, { "f":"g", "r":"গ" }, { "f":"G", "r":"গ" }, { "f":"hN", "r":"হ্ণ" }, { "f":"hn", "r":"হ্ন" }, { "f":"hm", "r":"হ্ম" }, { "f":"hl", "r":"হ্ল" }, { "f":"h", "r":"হ" }, { "f":"jjh", "r":"জ্ঝ" }, { "f":"jNG", "r":"জ্ঞ" }, { "f":"jh", "r":"ঝ" }, { "f":"jj", "r":"জ্জ" }, { "f":"j", "r":"জ" }, { "f":"J", "r":"জ" }, { "f":"kkhN", "r":"ক্ষ্ণ" }, { "f":"kShN", "r":"ক্ষ্ণ" }, { "f":"kkhm", "r":"ক্ষ্ম" }, { "f":"kShm", "r":"ক্ষ্ম" }, { "f":"kxN", "r":"ক্ষ্ণ" }, { "f":"kxm", "r":"ক্ষ্ম" }, { "f":"kkh", "r":"ক্ষ" }, { "f":"kSh", "r":"ক্ষ" }, { "f":"ksh", "r":"কশ" }, { "f":"kx", "r":"ক্ষ" }, { "f":"kk", "r":"ক্ক" }, { "f":"kT", "r":"ক্ট" }, { "f":"kt", "r":"ক্ত" }, { "f":"kl", "r":"ক্ল" }, { "f":"ks", "r":"ক্স" }, { "f":"kh", "r":"খ" }, { "f":"k", "r":"ক" }, { "f":"lbh", "r":"ল্ভ" }, { "f":"ldh", "r":"ল্ধ" }, { "f":"lkh", "r":"লখ" }, { "f":"lgh", "r":"লঘ" }, { "f":"lph", "r":"লফ" }, { "f":"lk", "r":"ল্ক" }, { "f":"lg", "r":"ল্গ" }, { "f":"lT", "r":"ল্ট" }, { "f":"lD", "r":"ল্ড" }, { "f":"lp", "r":"ল্প" }, { "f":"lv", "r":"ল্ভ" }, { "f":"lm", "r":"ল্ম" }, { "f":"ll", "r":"ল্ল" }, { "f":"lb", "r":"ল্ব" }, { "f":"l", "r":"ল" }, { "f":"mth", "r":"ম্থ" }, { "f":"mph", "r":"ম্ফ" }, { "f":"mbh", "r":"ম্ভ" }, { "f":"mpl", "r":"মপ্ল" }, { "f":"mn", "r":"ম্ন" }, { "f":"mp", "r":"ম্প" }, { "f":"mv", "r":"ম্ভ" }, { "f":"mm", "r":"ম্ম" }, { "f":"ml", "r":"ম্ল" }, { "f":"mb", "r":"ম্ব" }, { "f":"mf", "r":"ম্ফ" }, { "f":"m", "r":"ম" }, { "f":"0", "r":"০" }, { "f":"1", "r":"১" }, { "f":"2", "r":"২" }, { "f":"3", "r":"৩" }, { "f":"4", "r":"৪" }, { "f":"5", "r":"৫" }, { "f":"6", "r":"৬" }, { "f":"7", "r":"৭" }, { "f":"8", "r":"৮" }, { "f":"9", "r":"৯" }, { "f":"NgkSh", "r":"ঙ্ক্ষ" }, { "f":"Ngkkh", "r":"ঙ্ক্ষ" }, { "f":"NGch", "r":"ঞ্ছ" }, { "f":"Nggh", "r":"ঙ্ঘ" }, { "f":"Ngkh", "r":"ঙ্খ" }, { "f":"NGjh", "r":"ঞ্ঝ" }, { "f":"ngOU", "r":"ঙ্গৌ" }, { "f":"ngOI", "r":"ঙ্গৈ" }, { "f":"Ngkx", "r":"ঙ্ক্ষ" }, { "f":"NGc", "r":"ঞ্চ" }, { "f":"nch", "r":"ঞ্ছ" }, { "f":"njh", "r":"ঞ্ঝ" }, { "f":"ngh", "r":"ঙ্ঘ" }, { "f":"Ngk", "r":"ঙ্ক" }, { "f":"Ngx", "r":"ঙ্ষ" }, { "f":"Ngg", "r":"ঙ্গ" }, { "f":"Ngm", "r":"ঙ্ম" }, { "f":"NGj", "r":"ঞ্জ" }, { "f":"ndh", "r":"ন্ধ" }, { "f":"nTh", "r":"ন্ঠ" }, { "f":"NTh", "r":"ণ্ঠ" }, { "f":"nth", "r":"ন্থ" }, { "f":"nkh", "r":"ঙ্খ" }, { "f":"ngo", "r":"ঙ্গ" }, { "f":"nga", "r":"ঙ্গা" }, { "f":"ngi", "r":"ঙ্গি" }, { "f":"ngI", "r":"ঙ্গী" }, { "f":"ngu", "r":"ঙ্গু" }, { "f":"ngU", "r":"ঙ্গূ" }, { "f":"nge", "r":"ঙ্গে" }, { "f":"ngO", "r":"ঙ্গো" }, { "f":"NDh", "r":"ণ্ঢ" }, { "f":"nsh", "r":"নশ" }, { "f":"Ngr", "r":"ঙর" }, { "f":"NGr", "r":"ঞর" }, { "f":"ngr", "r":"ংর" }, { "f":"nj", "r":"ঞ্জ" }, { "f":"Ng", "r":"ঙ" }, { "f":"NG", "r":"ঞ" }, { "f":"nk", "r":"ঙ্ক" }, { "f":"ng", "r":"ং" }, { "f":"nn", "r":"ন্ন" }, { "f":"NN", "r":"ণ্ণ" }, { "f":"Nn", "r":"ণ্ন" }, { "f":"nm", "r":"ন্ম" }, { "f":"Nm", "r":"ণ্ম" }, { "f":"nd", "r":"ন্দ" }, { "f":"nT", "r":"ন্ট" }, { "f":"NT", "r":"ণ্ট" }, { "f":"nD", "r":"ন্ড" }, { "f":"ND", "r":"ণ্ড" }, { "f":"nt", "r":"ন্ত" }, { "f":"ns", "r":"ন্স" }, { "f":"nc", "r":"ঞ্চ" }, { "f":"n", "r":"ন" }, { "f":"N", "r":"ণ" }, { "f":"OI`", "r":"ৈ" }, { "f":"OU`", "r":"ৌ" }, { "f":"O`", "r":"ো" }, { "f":"OI", "r":"ৈ", "rules": [ { "matches": [ { "type":"prefix", "scope":"!consonant" } ], "r":"ঐ" }, { "matches": [ { "type":"prefix", "scope":"punctuation" } ], "r":"ঐ" } ] }, { "f":"OU", "r":"ৌ", "rules": [ { "matches": [ { "type":"prefix", "scope":"!consonant" } ], "r":"ঔ" }, { "matches": [ { "type":"prefix", "scope":"punctuation" } ], "r":"ঔ" } ] }, { "f":"O", "r":"ো", "rules": [ { "matches": [ { "type":"prefix", "scope":"!consonant" } ], "r":"ও" }, { "matches": [ { "type":"prefix", "scope":"punctuation" } ], "r":"ও" } ] }, { "f":"phl", "r":"ফ্ল" }, { "f":"pT", "r":"প্ট" }, { "f":"pt", "r":"প্ত" }, { "f":"pn", "r":"প্ন" }, { "f":"pp", "r":"প্প" }, { "f":"pl", "r":"প্ল" }, { "f":"ps", "r":"প্স" }, { "f":"ph", "r":"ফ" }, { "f":"fl", "r":"ফ্ল" }, { "f":"f", "r":"ফ" }, { "f":"p", "r":"প" }, { "f":"rri`", "r":"ৃ" }, { "f":"rri", "r":"ৃ", "rules": [ { "matches": [ { "type":"prefix", "scope":"!consonant" } ], "r":"ঋ" }, { "matches": [ { "type":"prefix", "scope":"punctuation" } ], "r":"ঋ" } ] }, { "f":"rrZ", "r":"রর‍্য" }, { "f":"rry", "r":"রর‍্য" }, { "f":"rZ", "r":"র‍্য", "rules": [ { "matches": [ { "type":"prefix", "scope":"consonant" }, { "type":"prefix", "scope":"!exact", "value":"r" }, { "type":"prefix", "scope":"!exact", "value":"y" }, { "type":"prefix", "scope":"!exact", "value":"w" }, { "type":"prefix", "scope":"!exact", "value":"x" } ], "r":"্র্য" } ] }, { "f":"ry", "r":"র‍্য", "rules": [ { "matches": [ { "type":"prefix", "scope":"consonant" }, { "type":"prefix", "scope":"!exact", "value":"r" }, { "type":"prefix", "scope":"!exact", "value":"y" }, { "type":"prefix", "scope":"!exact", "value":"w" }, { "type":"prefix", "scope":"!exact", "value":"x" } ], "r":"্র্য" } ] }, { "f":"rr", "r":"রর", "rules": [ { "matches": [ { "type":"prefix", "scope":"!consonant" }, { "type":"suffix", "scope":"!vowel" }, { "type":"suffix", "scope":"!exact", "value":"r" }, { "type":"suffix", "scope":"!punctuation" } ], "r":"র্" }, { "matches": [ { "type":"prefix", "scope":"consonant" }, { "type":"prefix", "scope":"!exact", "value":"r" } ], "r":"্রর" } ] }, { "f":"Rg", "r":"ড়্গ" }, { "f":"Rh", "r":"ঢ়" }, { "f":"R", "r":"ড়" }, { "f":"r", "r":"র", "rules": [ { "matches": [ { "type":"prefix", "scope":"consonant" }, { "type":"prefix", "scope":"!exact", "value":"r" }, { "type":"prefix", "scope":"!exact", "value":"y" }, { "type":"prefix", "scope":"!exact", "value":"w" }, { "type":"prefix", "scope":"!exact", "value":"x" }, { "type":"prefix", "scope":"!exact", "value":"Z" } ], "r":"্র" } ] }, { "f":"shch", "r":"শ্ছ" }, { "f":"ShTh", "r":"ষ্ঠ" }, { "f":"Shph", "r":"ষ্ফ" }, { "f":"Sch", "r":"শ্ছ" }, { "f":"skl", "r":"স্ক্ল" }, { "f":"skh", "r":"স্খ" }, { "f":"sth", "r":"স্থ" }, { "f":"sph", "r":"স্ফ" }, { "f":"shc", "r":"শ্চ" }, { "f":"sht", "r":"শ্ত" }, { "f":"shn", "r":"শ্ন" }, { "f":"shm", "r":"শ্ম" }, { "f":"shl", "r":"শ্ল" }, { "f":"Shk", "r":"ষ্ক" }, { "f":"ShT", "r":"ষ্ট" }, { "f":"ShN", "r":"ষ্ণ" }, { "f":"Shp", "r":"ষ্প" }, { "f":"Shf", "r":"ষ্ফ" }, { "f":"Shm", "r":"ষ্ম" }, { "f":"spl", "r":"স্প্ল" }, { "f":"sk", "r":"স্ক" }, { "f":"Sc", "r":"শ্চ" }, { "f":"sT", "r":"স্ট" }, { "f":"st", "r":"স্ত" }, { "f":"sn", "r":"স্ন" }, { "f":"sp", "r":"স্প" }, { "f":"sf", "r":"স্ফ" }, { "f":"sm", "r":"স্ম" }, { "f":"sl", "r":"স্ল" }, { "f":"sh", "r":"শ" }, { "f":"Sc", "r":"শ্চ" }, { "f":"St", "r":"শ্ত" }, { "f":"Sn", "r":"শ্ন" }, { "f":"Sm", "r":"শ্ম" }, { "f":"Sl", "r":"শ্ল" }, { "f":"Sh", "r":"ষ" }, { "f":"s", "r":"স" }, { "f":"S", "r":"শ" }, { "f":"oo`", "r":"ু" }, { "f":"oo", "r":"ু", "rules": [ { "matches": [ { "type":"prefix", "scope":"!consonant" }, { "type":"suffix", "scope":"!exact", "value":"`" } ], "r":"উ" }, { "matches": [ { "type":"prefix", "scope":"punctuation" }, { "type":"suffix", "scope":"!exact", "value":"`" } ], "r":"উ" } ] }, { "f":"o`", "r":"" }, { "f":"oZ", "r":"অ্য" }, { "f":"o", "r":"", "rules": [ { "matches": [ { "type":"prefix", "scope":"vowel" }, { "type":"prefix", "scope":"!exact", "value":"o" } ], "r":"ও" }, { "matches": [ { "type":"prefix", "scope":"vowel" }, { "type":"prefix", "scope":"exact", "value":"o" } ], "r":"অ" }, { "matches": [ { "type":"prefix", "scope":"punctuation" } ], "r":"অ" } ] }, { "f":"tth", "r":"ত্থ" }, { "f":"t``", "r":"ৎ" }, { "f":"TT", "r":"ট্ট" }, { "f":"Tm", "r":"ট্ম" }, { "f":"Th", "r":"ঠ" }, { "f":"tn", "r":"ত্ন" }, { "f":"tm", "r":"ত্ম" }, { "f":"th", "r":"থ" }, { "f":"tt", "r":"ত্ত" }, { "f":"T", "r":"ট" }, { "f":"t", "r":"ত" }, { "f":"aZ", "r":"অ্যা" }, { "f":"AZ", "r":"অ্যা" }, { "f":"a`", "r":"া" }, { "f":"A`", "r":"া" }, { "f":"a", "r":"া", "rules": [ { "matches": [ { "type":"prefix", "scope":"punctuation" }, { "type":"suffix", "scope":"!exact", "value":"`" } ], "r":"আ" }, { "matches": [ { "type":"prefix", "scope":"!consonant" }, { "type":"prefix", "scope":"!exact", "value":"a" }, { "type":"suffix", "scope":"!exact", "value":"`" } ], "r":"য়া" }, { "matches": [ { "type":"prefix", "scope":"exact", "value":"a" }, { "type":"suffix", "scope":"!exact", "value":"`" } ], "r":"আ" } ] }, { "f":"i`", "r":"ি" }, { "f":"i", "r":"ি", "rules": [ { "matches": [ { "type":"prefix", "scope":"!consonant" }, { "type":"suffix", "scope":"!exact", "value":"`" } ], "r":"ই" }, { "matches": [ { "type":"prefix", "scope":"punctuation" }, { "type":"suffix", "scope":"!exact", "value":"`" } ], "r":"ই" } ] }, { "f":"I`", "r":"ী" }, { "f":"I", "r":"ী", "rules": [ { "matches": [ { "type":"prefix", "scope":"!consonant" }, { "type":"suffix", "scope":"!exact", "value":"`" } ], "r":"ঈ" }, { "matches": [ { "type":"prefix", "scope":"punctuation" }, { "type":"suffix", "scope":"!exact", "value":"`" } ], "r":"ঈ" } ] }, { "f":"u`", "r":"ু" }, { "f":"u", "r":"ু", "rules": [ { "matches": [ { "type":"prefix", "scope":"!consonant" }, { "type":"suffix", "scope":"!exact", "value":"`" } ], "r":"উ" }, { "matches": [ { "type":"prefix", "scope":"punctuation" }, { "type":"suffix", "scope":"!exact", "value":"`" } ], "r":"উ" } ] }, { "f":"U`", "r":"ূ" }, { "f":"U", "r":"ূ", "rules": [ { "matches": [ { "type":"prefix", "scope":"!consonant" }, { "type":"suffix", "scope":"!exact", "value":"`" } ], "r":"ঊ" }, { "matches": [ { "type":"prefix", "scope":"punctuation" }, { "type":"suffix", "scope":"!exact", "value":"`" } ], "r":"ঊ" } ] }, { "f":"ee`", "r":"ী" }, { "f":"ee", "r":"ী", "rules": [ { "matches": [ { "type":"prefix", "scope":"!consonant" }, { "type":"suffix", "scope":"!exact", "value":"`" } ], "r":"ঈ" }, { "matches": [ { "type":"prefix", "scope":"punctuation" }, { "type":"suffix", "scope":"!exact", "value":"`" } ], "r":"ঈ" } ] }, { "f":"e`", "r":"ে" }, { "f":"e", "r":"ে", "rules": [ { "matches": [ { "type":"prefix", "scope":"!consonant" }, { "type":"suffix", "scope":"!exact", "value":"`" } ], "r":"এ" }, { "matches": [ { "type":"prefix", "scope":"punctuation" }, { "type":"suffix", "scope":"!exact", "value":"`" } ], "r":"এ" } ] }, { "f":"z", "r":"য" }, { "f":"Z", "r":"্য" }, { "f":"y", "r":"্য", "rules": [ { "matches": [ { "type":"prefix", "scope":"!consonant" }, { "type":"prefix", "scope":"!punctuation" } ], "r":"য়" }, { "matches": [ { "type":"prefix", "scope":"punctuation" } ], "r":"ইয়" } ] }, { "f":"Y", "r":"য়" }, { "f":"q", "r":"ক" }, { "f":"w", "r":"ও", "rules": [ { "matches": [ { "type":"prefix", "scope":"punctuation" }, { "type":"suffix", "scope":"vowel" } ], "r":"ওয়" }, { "matches": [ { "type":"prefix", "scope":"consonant" } ], "r":"্ব" } ] }, { "f":"x", "r":"ক্স", "rules": [ { "matches": [ { "type":"prefix", "scope":"punctuation" } ], "r":"এক্স" } ] }, { "f":":`", "r":":" }, { "f":"^`", "r":"^" }, { "f":",,", "r":"্‌" }, { "f":",", "r":"," }, { "f":"`", "r":"" } ], "vowel":"aeiou", "consonant":"bcdfghjklmnpqrstvwxyz", "casesensitive":"oiudgjnrstyz" } }; (function() { var keyboard, buffer = ""; var SPACE = 32; var TAB = 9; var RETURN = 13; var BACKSPACE = 8; function isBufferEmpty() { return buffer == ""; } function clearBuffer() { buffer = ""; } function addToBuffer(keyCode) { if (keyCode == SPACE || keyCode == RETURN || keyCode == TAB) { if (!isBufferEmpty()) { buffer = buffer + String.fromCharCode(keyCode); inputDone(); } else { keyboard.sendKey(keyCode); } } else if (keyCode == BACKSPACE) { backspace(); } else { buffer = buffer + String.fromCharCode(keyCode); } } function backspace() { if (!isBufferEmpty()) { buffer = buffer.substring(0, buffer.length -1); keyboard.setComposition(OmicronLab.Avro.Phonetic.parse(buffer)); } else { keyboard.sendKey(KeyEvent.DOM_VK_BACK_SPACE); } } function inputDone() { var parsedText = OmicronLab.Avro.Phonetic.parse(buffer); keyboard.endComposition(parsedText); clearBuffer(); } InputMethods.jsavrophonetic = { init: init, click: click }; function init(interfaceObject) { keyboard = interfaceObject; } function click(keycode, x, y) { addToBuffer(keycode); if (!isBufferEmpty()) { keyboard.setComposition(OmicronLab.Avro.Phonetic.parse(buffer)); } } })();