forked from sarim/ibus-avro
-
Notifications
You must be signed in to change notification settings - Fork 4
/
dbsearch.js
executable file
·173 lines (147 loc) · 4.78 KB
/
dbsearch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
=============================================================================
*****************************************************************************
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.
The Original Code is jsAvroPhonetic
The Initial Developer of the Original Code is
Mehdi Hasan Khan <[email protected]>
Copyright (C) OmicronLab (http://www.omicronlab.com). All Rights Reserved.
Contributor(s): ______________________________________.
*****************************************************************************
=============================================================================
*/
const db = imports.avrodict;
const RegexServer = imports.avroregexlib;
const utfconv = imports.utf8;
function DBSearch () {
this._init();
}
DBSearch.prototype = {
search: function (enText) {
var lmc = enText.toLowerCase().charAt(0);
var tableList = [];
switch (lmc) {
case 'a':
tableList = ["a", "aa", "e", "oi", "o", "nya", "y"];
break;
case 'b':
tableList = ["b", "bh"];
break;
case 'c':
tableList = ["c", "ch", "k"];
break;
case 'd':
tableList = ["d", "dh", "dd", "ddh"];
break;
case 'e':
tableList = ["i", "ii", "e", "y"];
break;
case 'f':
tableList = ["ph"];
break;
case 'g':
tableList = ["g", "gh", "j"];
break;
case 'h':
tableList = ["h"];
break;
case 'i':
tableList = ["i", "ii", "y"];
break;
case 'j':
tableList = ["j", "jh", "z"];
break;
case 'k':
tableList = ["k", "kh"];
break;
case 'l':
tableList = ["l"];
break;
case 'm':
tableList = ["h", "m"];
break;
case 'n':
tableList = ["n", "nya", "nga", "nn"];
break;
case 'o':
tableList = ["a", "u", "uu", "oi", "o", "ou", "y"];
break;
case 'p':
tableList = ["p", "ph"];
break;
case 'q':
tableList = ["k"];
break;
case 'r':
tableList = ["rri", "h", "r", "rr", "rrh"];
break;
case 's':
tableList = ["s", "sh", "ss"];
break;
case 't':
tableList = ["t", "th", "tt", "tth", "khandatta"];
break;
case 'u':
tableList = ["u", "uu", "y"];
break;
case 'v':
tableList = ["bh"];
break;
case 'w':
tableList = ["o"];
break;
case 'x':
tableList = ["e", "k"];
break;
case 'y':
tableList = ["i", "y"];
break;
case 'z':
tableList = ["h", "j", "jh", "z"];
break;
default:
break;
}
var pattern = this._regex.parse(enText);
pattern = '^' + pattern + '$';
var retWords = [];
for(i in tableList) {
var table = 'w_' + tableList[i];
retWords = retWords.concat(this._searchInArray(pattern, db.tables[table]));
}
return retWords;
},
_searchInArray: function(pattern, wArray){
var retWords = [];
var word = '';
var re = new RegExp(pattern);
for (w in wArray){
word = wArray[w];
if (re.test(word)){
retWords.push(word);
}
}
return retWords;
},
_printWords: function (enText) {
var words = this.search(enText);
for (w in words){
print(words[w]);
}
},
_init: function () {
this._regex = new RegexServer.AvroRegex();
}
}
/* --------- */
/* Test code */
/* --------- */
// var __dbSearch = new DBSearch ();
// __dbSearch._printWords('onirban');