-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dictionary.java
308 lines (259 loc) · 8.69 KB
/
Dictionary.java
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package kamusi_proj;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.LinkedList;
/**
*
* @author HP
*/
public class Dictionary {
Word word;
LinkedList allwords=new LinkedList();
LinkedList sallwords=new LinkedList();
LinkedList allwordtypes=new LinkedList();
LinkedList allwordforms=new LinkedList();
LinkedList wordids=new LinkedList();
LinkedList swordids=new LinkedList();
public Dictionary()
{
LoadAllwords();
}
public Dictionary(String z)
{
LoadAllwords(z);
LoadAllwords();
}
public LinkedList getAllwords()
{
return allwords;
}
public LinkedList getsAllwords()
{
return sallwords;
}
public LinkedList getAllwordtypes()
{
return allwordtypes;
}
public LinkedList getAllwordforms()
{
return allwordforms;
}
public void LoadAllwords()
{
Connection con=null;
try
{
con=DBconnect.dbconnect();
//getting words
String wordsql="SELECT * FROM wordentries ORDER BY word;";
Statement st=con.createStatement();
ResultSet resultb=st.executeQuery(wordsql);
//System.out.println(result2.next());
//int countme=0;
while(resultb.next())
{
String w="<b>"+resultb.getString("word")+"</b>";
allwords.add(w);
wordids.add(resultb.getInt("wid"));
}
}catch(Exception t)
{
t.printStackTrace();
}
DBconnect.connectclose(con);
}
public void LoadAllwords(String search)
{
Connection con=null;
try
{
con=DBconnect.dbconnect();
//getting words
String wordsql="SELECT * FROM wordentries where word like '%"+search+"' or '%"+search+"%' or '"+search+"%' ORDER BY word;";
Statement st=con.createStatement();
ResultSet resultb=st.executeQuery(wordsql);
//System.out.println(result2.next());
//int countme=0;
while(resultb.next())
{
String w="<b>"+resultb.getString("word")+"</b>";
System.out.println(w);
sallwords.add(w);
swordids.add(resultb.getInt("wid"));
}
}catch(Exception t)
{
t.printStackTrace();
}
DBconnect.connectclose(con);
}
public LinkedList getwordids()
{
return wordids;
}
public LinkedList getswordids()
{
return swordids;
}
public String[] loadAllderv(int x)
{
String derivs[]=new String[10];
String dsymbol[]=new String[10];
String derivdef[]=new String[10];
//getting word types
Connection con=null;
try
{
con=DBconnect.dbconnect();
String formsql="select*from wordentries,wordderiv,derivtypes where wordderiv.wid=wordentries.wid and wordderiv.derivtype=derivtypes.type and wordentries.wid='"+x+"';";
Statement st=con.createStatement();
//getting word forms
ResultSet fresult=st.executeQuery(formsql);
int count=0;
while(fresult.next())
{
if(fresult.getString("derivword")!="")
{
count++;
dsymbol[count]="<font color=\"green\">"+fresult.getString("symbol")+"</font>";
derivdef[count]="<b>"+fresult.getString("derivword")+"</b>";
derivs[count]=dsymbol[count]+""+derivdef[count];
}
}
}catch(Exception e)
{
e.printStackTrace();
}
//countme++;
DBconnect.connectclose(con);
return derivs;
}
public String getWordForm(int f)
{
String wordform="";
//getting word types
Connection con=null;
try
{
con=DBconnect.dbconnect();
String formsql="select*from forms,wform where forms.fid=wform.fid and wform.wid='"+f+"';";
Statement st=con.createStatement();
//getting word forms
ResultSet fresult=st.executeQuery(formsql);
while(fresult.next())
{
String symbol="<font color=\"green\">"+fresult.getString("fsymbol")+"</font>";
String fdef="<b>"+fresult.getString("fdefinition")+"</b>";
wordform=symbol+""+fdef;
}
}catch(Exception e)
{
e.printStackTrace();
}
//countme++;
DBconnect.connectclose(con);
return wordform;
}
public String[] getAllexpressions(int ex)
{
String expression[]=new String[30];
String symbol[]=new String[30];
String express[]=new String[30];
String xmean[]=new String[30];
//getting word types
Connection con=null;
try
{
con=DBconnect.dbconnect();
String expsql="select*from wordentries,expressions,exptypes where wordentries.wid=expressions.wid and expressions.exptype=exptypes.exptype and wordentries.wid='"+ex+"';";
Statement st=con.createStatement();
//getting word forms
ResultSet fresult=st.executeQuery(expsql);
int count=0;
while(fresult.next())
{
if(fresult.getString("expression")!=""){
count++;
symbol[count]="<font color=\"green\">"+fresult.getString("expsymbol")+"</font>";
express[count]="<b>"+fresult.getString("expression")+"</b>";
xmean[count]="<b>"+fresult.getString("expmeaning")+"</b>";
expression[count]=symbol[count]+""+express[count]+""+xmean[count];
}
}
}catch(Exception e)
{
e.printStackTrace();
}
//countme++;
DBconnect.connectclose(con);
return expression;
}
public String getWordType(int t)
{
String wordtype="";
//getting word types
Connection con=null;
try
{
con=DBconnect.dbconnect();
String typesql="select*from wordentries,wtypes where wordentries.w_type=wtypes.tid and wordentries.wid='"+t+"';";
Statement st=con.createStatement();
ResultSet typeresult=st.executeQuery(typesql);
while(typeresult.next())
{
wordtype="<b><i>"+typeresult.getString("symbol")+"</i></b>";
}
}catch(Exception x)
{
x.printStackTrace();
}
return wordtype;
}
public void printSelectedWords(String keyword)
{
}
public String[] fetchwordmeanings(int w)
{
Connection con=null;
String[] m=new String[10];
String[] example=new String[10];
String meaning[]=new String[10];
try
{
con=DBconnect.dbconnect();
Statement st=con.createStatement();
//getting word meanings
String msql="select * from wmeanings,Mreferences,wordentries where wmeanings.rfid=Mreferences.rfid and wmeanings.wid=wordentries.wid and wmeanings.wid='"+w+"';";
ResultSet mresult=st.executeQuery(msql);
int count=0;
while(mresult.next())
{
if(mresult.getString("meaning")!=""){
count++;
if(mresult.getString("referenced").equals("noref")){
m[count]="<i>"+mresult.getString("meaning")+"</i>";
}else{m[count]="<i>"+mresult.getString("meaning")+"</i>"+"."+"<b>rab."+mresult.getString("referenced")+"</b>";
}
example[count]="<b>"+mresult.getString("example")+"</b>.";
//System.out.println(count);
meaning[count]=m[count]+":"+example[count];
// count++;
//System.out.println(count+mresult.getString("meaning"));
}
}
}
catch(Exception t)
{
t.printStackTrace();
}
DBconnect.connectclose(con);
return meaning;
}
}