-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathMdTest.java
More file actions
358 lines (358 loc) · 13.4 KB
/
MdTest.java
File metadata and controls
358 lines (358 loc) · 13.4 KB
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
//package test;
//
//import java.io.IOException;
//import java.util.ArrayList;
//import java.util.zip.DataFormatException;
//
//import com.knziha.plod.PlainDict.PlainDictAppOptions;
//import com.knziha.plod.dictionary.Utils.BU;
//import com.knziha.plod.dictionarymodels.mdict;
//import com.knziha.plod.dictionary.mdictRes;
//import com.knziha.plod.dictionarymodels.resultRecorderScattered2;
//import com.knziha.rbtree.RBTree_additive;
//
//
//
///**
// * TESTS
// * @author KnIfER
// * @date 2017/12/30
// */
//public class MdTest {
// public static long stst;//static start time
//
//
// //static ArrayList<Integer> fuzzy_search_result;
// static int d=0;
// public static void main(String[] args) throws IOException, DataFormatException {
//
// //assign Mdx File here!
// PlainDictAppOptions opt = new PlainDictAppOptions();
// mdict md = new mdict("D:\\assets\\mdicts\\藏英Rang Jung Ye She 2003词典,liuzhean,20070921.mdx", opt);//牛津高阶英汉双解词典.mdx
// //final mdict md = new mdict("E:\\mdict\\MDictPC\\doc\\清华大学藏战国竹简(伍).mdx");
//
// //A keyword to search! //简明英汉汉英词典.mdx 古生物图鉴.mdx
// String key = "茉";//abduco@拉丁语英语 马连鞍@有毒植物 happy@English-Chinese
// //CMN.show(md.getRecordAt(md.lookUp("龤")));
// //md.printDictInfo();
//
// //A bunch of tests~
//
// //![0]Basic query and extraction of contents
// if(false)
// { /* false true */
// CMN.show("\n\n——————————————————————basic query——————————————————————");
// md = new mdict("E:\\assets\\mdicts\\拉鲁斯法语词典.mdx", opt);
// key = "abces";
// //CMN.show("查询 "+key+" : "+md.getEntryAt(md.lookUp(key)));
// stst=System.currentTimeMillis();
// CMN.show("结果html contents of "+key+" : "+md.getRecordAt(md.lookUp(key)));
// CMN.show("时耗 time used: "+(System.currentTimeMillis()-stst)+"ms");
//
//
// //CMN.show(""+md.lookUp("茉莉"));
// }
//
//
// /*![6]Advanced mdicts conjunction search.*/
// /*联合搜索测试*/
// if(false)
// { /* false true */
// CMN.show("\n\n——————————————————————searching in a bunch of dicts——————————————————————");
//
// ArrayList<mdict> mdxs = new ArrayList<mdict>();
//
// /*somewhat《English-Chinese essential》、《oxford English-Chinese advanced》*/
// for(int i=0;i<1;i++)
// mdxs.add(new mdict("E:\\assets\\mdicts\\简明英汉汉英词典.mdx", opt));
// //mdxs.add(new mdict("C:\\antiquafortuna\\MDictPC\\doc\\牛津高阶英汉双解词典.mdx"));
//
//
// RBTree_additive combining_search_tree = new RBTree_additive();
// stst=System.currentTimeMillis();
//
// key = "a and";// absolute
// for(int i=0;i<mdxs.size();i++)
// {
// mdxs.get(i).size_confined_lookUp5(key,combining_search_tree,i,30);
// }
//
// CMN.show("时耗 Time used: "+(System.currentTimeMillis()-stst)+"ms");
// CMN.show("联合搜索结果 results: ");
// combining_search_tree.inOrder();
// }
//
//
// //![3]fuzzy search ✔
// if(true)
// { /* false true */
// CMN.show("\n\n—————————————————————— fuzzy search ——————————————————————");
//
// final boolean isCombinedSearching=true;
// final int adapter_idx=0;
// final ArrayList<mdict> mdicts = new ArrayList<>();
// mdicts.add(new mdict("F:\\assets\\mdicts\\牛津高阶英汉双解词典.mdx", opt));
//
// CMN.show("\r\n糊匹配测试START...");
//
// final String keyf = "a*b";
// stst=System.currentTimeMillis();
// if(isCombinedSearching) {
// for(mdict mdx:mdicts) {
// mdx.flowerFindAllKeys(keyf, 0, 30,null);
// }
// }else
// mdicts.get(adapter_idx).flowerFindAllKeys(keyf, 0, 30,null);
// harvestfuzzySearch(isCombinedSearching,adapter_idx,mdicts);
// }
//
// //![3]fuzzy search ✔
// if(false)
// { /* false true */
// CMN.show("\n\n—————————————————————— fuzzy search2 ——————————————————————");
// final boolean isCombinedSearching=true;
// final int adapter_idx=0;
// final ArrayList<mdict> md1 = new ArrayList<>();
// md1.add(new mdict("E:\\assets\\mdicts\\牛津高阶英汉双解词典.mdx" , opt));
// //md1.add(new mdict("E:\\assets\\mdicts\\新日漢大辭典.mdx" ));
// //md1.add(new mdict("E:\\assets\\mdicts\\NameOfPlants.mdx" ));
// //md1.add(new mdict("E:\\assets\\mdicts\\ode2_raw.mdx" ));
// //md1.add(new mdict("E:\\assets\\mdicts\\Irish-En.mdx"));
// //md1.add(new mdict("E:\\assets\\mdicts\\俄汉汉俄辞典.mdx" ));
//
// CMN.show("\r\n糊匹配测试START...");
//
// final String keyf = "c*gr.phy";
// stst=System.currentTimeMillis();
//
// //!!this's being here is very important, put it in the worker-thread will cause lag
// for(int i=0;i<md1.size();i++){//遍历所有词典
// mdict mdtmp = md1.get(i);
// if(mdtmp.combining_search_tree2==null) {
// }
// else
// for(int ti=0;ti<mdtmp.combining_search_tree2.length;ti++){//遍历搜索结果
// if(mdtmp.combining_search_tree2[ti]==null) {
// continue;
// }
// mdtmp.combining_search_tree2[ti].clear();
// }
//
// }
// stst=System.currentTimeMillis(); //获取开始时间
//
// for(int i=0;i<md1.size();i++){
// try {
// md1.get(i).flowerFindAllKeys(keyf,i,30);
// //publisResults();
// //if(isCancelled()) break;
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
//
//
// int[] firstLookUpTable = new int[md1.size()];
// int size=0;
// int resCount=0;
// for(int i=0;i<md1.size();i++){//遍历所有词典
// mdict mdtmp = md1.get(i);
// if(mdtmp.combining_search_tree2==null) {
// }
// else
// //if(mdtmp.combining_search_tree2!=null)
// for(int ti=0;ti<mdtmp.split_keys_thread_number;ti++){
// if(mdtmp.combining_search_tree2[ti]!=null)
// for(int i1=0;i1<mdtmp.combining_search_tree2[ti].size();i1++) {
// CMN.show(mdtmp.getEntryAt(mdtmp.combining_search_tree2[ti].get(i1)));
// resCount++;
// }
// }
// firstLookUpTable[i]=resCount;
//
// }
//
//
// CMN.show("模糊搜索完成! 耗时"+(System.currentTimeMillis()-stst)+"ms,共搜索到 "+resCount+"个词条!");
// }
//
//
// //![6] fulltext search
// if(false)
// { /* false true */
// CMN.show("\n\n—————————————————————— 多线程全文搜索测试 ——————————————————————");
// CMN.show("...\r\n");
// key = "happy";
// stst=System.currentTimeMillis(); //获取STARTtime used
// ArrayList<mdict> mdicts = new ArrayList<>();
// mdicts.add(new mdict("E:\\assets\\mdicts\\高级汉语词典.mdx", opt));//牛津高阶英汉双解词典.mdx
// for(mdict mdTmp:mdicts)
// mdTmp.flowerFindAllContents(key,0,30);
// resultRecorderScattered2 gross = new resultRecorderScattered2(mdicts, null);
// gross.invalidate();
// for(int i=0;i<gross.size();i++) {
// CMN.show(gross.getResAt(i));
// }
// CMN.show("✔ 多线程全文搜索测试 time used: "+(System.currentTimeMillis()-stst)+"ms 共搜索到res count: "+gross.size());
//
// }
//
// //![8]
// if(false)
// { /* false true */
// stst=System.currentTimeMillis();
// stst=System.currentTimeMillis();
// CMN.show("\r\n多线程全文搜索测试START...");
// key = "㑞";
// BU.printBytes(key.getBytes("GB18030"));
// stst=System.currentTimeMillis(); //获取STARTtime used
// md.flowerFindAllContents(key,0,0);
// CMN.show("多线程全文搜索测试 time usedA: "+(System.currentTimeMillis()-stst)+"ms");
// }
//
// //md.flowerFindAllKeys("happy", 0, 0);
//
// //md.prepareItemByKeyInfo(null, 19);
//
// //![3]very simple match middle pattern
//
// //if(false)
// //{ /* false true */
// // CMN.show("\r\n糊匹配测试START...");
// // key = "stizo";
// // stst=System.currentTimeMillis();
// // md.findAllKeys(key);
// // CMN.show("模糊匹配 Contain:"+key+" time used: "+(System.currentTimeMillis()-stst)+"ms");
// //}
// ////![3.1]very simple match middle pattern
// //if(false)
// //{ /* false true */
// // CMN.show("\r\n糊匹配测试START...");
// // key = "stizo";
// // stst=System.currentTimeMillis();
// // md.findAllKeys(key);
// // CMN.show("模糊匹配 Contain:"+key+" time used: "+(System.currentTimeMillis()-stst)+"ms");
// //}
//
// //mdictRes m = new mdictRes("E:\\mdict\\MDictPC\\doc\\wordsmyth2018.mdd");
// //m.printAllKeys();
// //CMN.show(":::>"+m.getEntryAt(m.lookUp("\\pic\\wolfSnow.jpg")));
// //BU.printBytes3(m.getRecordAt(m.lookUp("\\一.tif")),"一.tif");
//
// if(false) {
// stst = System.currentTimeMillis();
// //for(int i=0;i<100000;i++)
// // md.lookUp("龤"); //entry 龤 is at end
//
// //for(int i=0;i<100000;i++)
// // md.lookUp("拭");
// CMN.show("模糊搜索完成! 耗时"+(System.currentTimeMillis()-stst)+"ms,共搜索到 ");
// }
//
//
// //mdict m = new mdict("E:\\assets\\mdicts\\简明英汉汉英词典.mdx");
// //CMN.show(m.lookUp("a and")+"");
//
// //mdict m = new mdict("E:\\assets\\mdicts\\TCM_Textbook.mdx");
// //m.printAllKeys();
// //CMN.show(m.getEntryAt(m.lookUp("\\VMpix\\ShengWuPix\\shengwuhuaxueyufenzishengwuxue279.jpg"))+"");
// //CMN.show(m.getRecordAt(0)+"");
// //CMN.show((m.getEntryAt(m.lookUp("\hex111111.jpg")))+"");
// //CMN.show((m.getEntryAt(m.lookUp("目的")))+"");
//
// if(false) {
// mdict m = new mdict("E:\\assets\\mdicts\\诗经集注(注解两种)\\诗经集注(注解两种).mdx", opt);
// //m.printAllKeys();
// CMN.show(m.getRecordAt(m.lookUp("七月"))+"");
//
// mdictRes m1 = new mdictRes("F:\\NVPACK\\mds\\zhwiki-20180601_V1.3.mdd");
// //m.printAllKeys();
// CMN.show(m1.getEntryAt(m1.lookUp("\\pic\\ja\\jaglion.jpg"))+"");
// stst = System.currentTimeMillis();
// int cc=0;
// while(cc<1000) {
// m1.getRecordAt(m1.lookUp("\\pic\\ja\\jaglion.jpg"));
// cc++;
// }
// CMN.show("getEntryAt时间"+(System.currentTimeMillis()-stst));
//
//
//
// m = new mdict("F:\\NVPACK\\mds\\zhwiki-20180601_V1.3.mdx", opt);
// stst = System.currentTimeMillis();
// cc=0;
// while(cc<1) {
// for(int i=0;i<m.get_num_key_blocks()/100;i++) {
// m.prepareItemByKeyInfo(null, i, null);
// }
// cc++;
// }
// //m.fetch_keyBlocksHeaderTextKeyID();
// CMN.show("prepareItemByKeyInfo时间"+(System.currentTimeMillis()-stst));
//
// }
//
//
// //BU.printFile(m1.getRecordAt(m1.lookUp("\\pic\\ja\\jaglion.jpg")), 0, 0, "F:\\0tmp\\"+m1.getEntryAt(m1.lookUp("\\pic\\ja\\jaglion.jpg")).replace("\\","_"));
//}
//
//
//
//
//
//
//
// public static void harvestfuzzySearch(boolean isCombinedSearching,int adapter_idx,ArrayList<mdict> mdicts) {
// int fuzzy_task_count=-10086;
// for (mdict mdI:mdicts) {
// if(fuzzy_task_count==-10086){
// if(isCombinedSearching){
// fuzzy_task_count = mdicts.size();
// }else{
// fuzzy_task_count = 1;
// }
// }
// fuzzy_task_count--;
// if(fuzzy_task_count<=0){
// int cc = 0;
// if(isCombinedSearching){
// for(int i=0;i<mdicts.size();i++){
// mdict mdtmp = mdicts.get(i);
// //if(mdtmp.combining_search_tree2!=null)
// for(int ti=0;ti<mdtmp.split_keys_thread_number;ti++){
// if(mdtmp.combining_search_tree2[ti]!=null)
// for(int i1=0;i1<mdtmp.combining_search_tree2[ti].size();i1++) {
// CMN.show(mdtmp.getEntryAt(mdtmp.combining_search_tree2[ti].get(i1)));
// cc++;
// }
// }
// mdtmp.combining_search_tree2 = null;
// }
// }else{//单独搜索
// mdict mdtmp;
// mdtmp = mdicts.get(adapter_idx);
// for(int ti=0;ti<mdtmp.split_keys_thread_number;ti++){
// if(mdtmp.combining_search_tree2[ti]!=null)
// for(int i1=0;i1<mdtmp.combining_search_tree2[ti].size();i1++) {
// CMN.show(mdtmp.getEntryAt(mdtmp.combining_search_tree2[ti].get(i1)));
// cc++;
// }
// }
// mdtmp.combining_search_tree2 = null;
// }
//
// CMN.show("模糊搜索完成! 耗时"+(System.currentTimeMillis()-stst)+"ms,共搜索到 "+cc+"个词条!");
//
// fuzzy_task_count=-10086;
// }
// }
// };
//
//
//
//
//
//}
//
//