-
Notifications
You must be signed in to change notification settings - Fork 0
/
LYG10DWithChineseMixStringSort10D.java
614 lines (595 loc) · 20 KB
/
LYG10DWithChineseMixStringSort10D.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
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
package LYG4DQS4D;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
//20200314 集成了最新的小高峰过滤催化排序5代思想。
//20200818 集成了最新的小高峰过滤催化排序9代思想。
//罗瑶光
import java.util.Map;
import sample.App3;
public class LYG10DWithChineseMixStringSort10D{
Map<String, Boolean> find= new HashMap<>();
Map<String, String> pinyin;
int range;
int deeps;
public void quick4DChineseStringArray1D(String[] strings, int scale, Map<String, String> map, int range, int deeps) {
this.pinyin= map;
this.range= range;
this.deeps= deeps;
processKernel(strings, 0, strings.length- 1, scale, 0);
}
public boolean quick4DChineseStringArrayWithSmallInTwoChar(String[] strings, int leftPosition
, int rightPosition, int scale, Map<String, String> map, int range, int deeps) {
this.pinyin= map;
this.range= range;
this.deeps= deeps;
String oldValue=strings[0].toString();
processKernel(strings, leftPosition, rightPosition, scale, 0);
if(oldValue.equalsIgnoreCase(strings[0])){
return true;
}else {
return false;
}
}
private void processKernel(String[] kernel, int leftPosition
, int rightPosition, int scale, int point) {
int rightPositionReflection= rightPosition;
if(point> scale) {
return;
}
processQS4DLYG9D(kernel, leftPosition, rightPosition, scale, point, 0);
int i;
for(i= leftPosition; i<= rightPosition; i++) {
if(!(kernel[i].length()<= point|| kernel[leftPosition].length()<= point)) {
if(kernel[i].charAt(point)!= kernel[leftPosition].charAt(point)){
rightPositionReflection= i- 1;
processKernel(kernel, leftPosition, rightPositionReflection, scale, point+ 1);
leftPosition= i;
}
}
}
if(leftPosition!= rightPosition) {
processKernel(kernel, leftPosition, i- 1, scale, point+ 1);
}
}
private void processSort(String[] kernel, int leftPosition
, int rightPosition, int scale, int point) {
if(point> scale) {
return;
}
for(int i= leftPosition; i<= rightPosition; i++) {
Here:
for(int j= i; j<= rightPosition; j++) {
if(i== j) {
continue Here;
}
if(kernel[i].length()<= point|| kernel[j].length()<= point) {
if(kernel[i].length()< kernel[j].length()) {
for(int p= 0; p< scale; p++) {
if(!(kernel[i].length()<= p|| kernel[j].length()<= p)) {
if(kernel[i].charAt(p)!= kernel[j].charAt(p)) {
continue Here;
}
}
}
String temp= kernel[i].toString();;
kernel[i]= kernel[j].toString();;
kernel[j]= temp;
}
continue Here;
}else {
boolean hasXi= pinyin.containsKey(""+ kernel[i].charAt(point));
boolean hasXj= pinyin.containsKey(""+ kernel[j].charAt(point));
if(!(!hasXi|| !hasXj)){
String[] js= new String[2];
js[0]= this.pinyin.get(""+ kernel[i].charAt(point));
js[1]= this.pinyin.get(""+ kernel[j].charAt(point));
boolean change= processSortPinYin(js, 3);
if(!(!change|| i>= j)) {
String temp= kernel[i].toString();;
kernel[i]= kernel[j].toString();;
kernel[j]= temp;
}
continue Here;
}else if(!(hasXi|| !hasXj)){
if(i< j) {
if(!(i== rightPosition+1 || j== rightPosition+1)) {
String temp= kernel[i].toString();
kernel[i]= kernel[j].toString();
kernel[j]= temp;
}
}
continue Here;
}else if(!(hasXi|| hasXj)){
if(kernel[i].toLowerCase().charAt(point)
> kernel[j].toLowerCase().charAt(point)) {
if(i< j) {
String temp= kernel[i].toString();
kernel[i]= kernel[j].toString();
kernel[j]= temp;
}
continue Here;
}
if(kernel[i].toLowerCase().charAt(point)
== kernel[j].toLowerCase().charAt(point)) {
if(kernel[i].charAt(point)> kernel[j].charAt(point)) {
if(i< j) {
String temp= kernel[i].toString();
kernel[i]= kernel[j].toString();
kernel[j]= temp;
}
}
}
}
}
}
}
}
// private void processQS4DLYG5D(String[] kernel, int leftPosition
// , int rightPosition, int scale, int point, int deep) {
// if(leftPosition< rightPosition){
// int c= rightPosition- leftPosition;
// if(!(c > this.range|| deep> this.deeps)) {//增加了deep
// processSort(kernel, leftPosition, rightPosition, scale, point);
// return;
// }
// int pos= partition(kernel, leftPosition, rightPosition, scale, point);
// processQS4DLYG5D(kernel, leftPosition, pos- 1, scale, point, deep+ 1);
// processQS4DLYG5D(kernel, pos+ 1, rightPosition, scale, point, deep+ 1);
// }
// }
private void processQS4DLYG9D(String[] kernel, int leftPosition
, int rightPosition, int scale, int point, int deep) {
if(leftPosition< rightPosition){
int c= rightPosition- leftPosition+ 1;
if(!(c< this.range|| deep> this.deeps)) {//增加了deep
int pos= partition(kernel, leftPosition, rightPosition, scale, point);
if(leftPosition< pos- 1) {
processQS4DLYG9D(kernel, leftPosition, pos- 1, scale, point, deep+ 1);
}
if(pos+ 1< rightPosition) {
processQS4DLYG9D(kernel, pos+ 1, rightPosition, scale, point, deep+ 1);
}
return;
}
processSort(kernel, leftPosition, rightPosition, scale, point);
return;
}
}
private boolean findSmall(String[] kernel, int scale, int point
, int i, int j, int rightPosition) {
if(kernel[i].length()<= point|| kernel[j].length()<= point) {
if(kernel[i].length()< kernel[j].length()) {
for(int p= 0; p< scale; p++) {
if(!(kernel[i].length()<= p|| kernel[j].length()<= p)) {
if(kernel[i].charAt(p)!= kernel[j].charAt(p)) {
return false;
}
}
}
return true;
}
return false;
}else {
boolean hasXi= pinyin.containsKey(""+ kernel[i].charAt(point));
boolean hasXj= pinyin.containsKey(""+ kernel[j].charAt(point));
if(!(!hasXi|| !hasXj)){
String[] js= new String[2];
js[0]= this.pinyin.get(""+ kernel[i].charAt(point));
js[1]= this.pinyin.get(""+ kernel[j].charAt(point));
boolean change= processSortPinYin(js, 3);
if(!(!change|| i>= j)) {
return true;
}
return false;
}else if(!(hasXi|| hasXj)){
if(kernel[i].toLowerCase().charAt(point)
> kernel[j].toLowerCase().charAt(point)) {
if(i< j) {
return true;
}
return false;
}else if(kernel[i].toLowerCase().charAt(point)
== kernel[j].toLowerCase().charAt(point)) {
if(kernel[i].charAt(point)> kernel[j].charAt(point)) {
if(i< j) {
return true;
}
return false;
}
return false;
}
return false;
}else if(!(hasXi|| !hasXj)){
if(i< j) {
if(!(i== rightPosition || j== rightPosition)) {
return true;
}
return false;
}
return false;
}
}
return false;
}
private boolean findSmallWithTwoChar(String x1, String x2
, int scale, int point) {
if(x1.length()<= point|| x2.length()<= point) {
if(x1.length()< x2.length()) {
for(int p= 0; p< scale; p++) {
if(!(x1.length()<= p|| x2.length()<= p)) {
if(x1.charAt(p)!= x2.charAt(p)) {
return false;
}
}
}
return true;
}
return false;
}else {
boolean hasX1= pinyin.containsKey(""+ x1.charAt(point));
boolean hasX2= pinyin.containsKey(""+ x2.charAt(point));
if(!(!hasX1|| !hasX2)){
String[] js= new String[2];
js[0]= this.pinyin.get(""+ x1.charAt(point));
js[1]= this.pinyin.get(""+ x2.charAt(point));
boolean change= processSortPinYin(js, 3);
if(change) {
return true;
}
return false;
}else if(!(hasX1|| hasX2)){
if(x1.toLowerCase().charAt(point)> x2.toLowerCase().charAt(point)) {
return true;
}else if(x1.toLowerCase().charAt(point)== x2.toLowerCase().charAt(point)) {
if(x1.charAt(point)> x2.charAt(point)) {
return true;
}
return false;
}
return false;
}else if(!(hasX1|| !hasX2)){
return true;
}
}
return false;
}
private int partition(String[] array, int leftPosition, int rightPosition, int scale, int point) {
String x= findSmall(array, scale, point, leftPosition, rightPosition, rightPosition)
? array[rightPosition]: array[leftPosition];
int leftPositionReflection= leftPosition;
while(leftPositionReflection++ < rightPosition) {
while(!(findSmallWithTwoChar(array[leftPositionReflection++]
, x, scale, point)|| leftPositionReflection> rightPosition)) {}
while(findSmallWithTwoChar(array[rightPosition--], x, scale, point)){}
if(--leftPositionReflection< ++rightPosition){
String temp= array[rightPosition].toString();;
array[rightPosition]= array[leftPositionReflection].toString();;
array[leftPositionReflection]= temp;
}
}
array[leftPosition]= array[rightPosition].toString();
array[rightPosition]= x;
return rightPosition;
}
private boolean processSortPinYin(String[] kernel, int scale) {
for(int k= 0; k< scale; k++) {
if(kernel[0].length()<= k|| kernel[1].length()<= k) {
if(kernel[0].length()< kernel[1].length()) {
return true;
}
return false;
}
if(kernel[0].toLowerCase().charAt(k)
> kernel[1].toLowerCase().charAt(k)) {
return true;
}
if(kernel[0].toLowerCase().charAt(k)
< kernel[1].toLowerCase().charAt(k)) {
return false;
}
}
if(kernel[0].length()< kernel[1].length()) {
return true;
}
return false;
}
public boolean findSmallWithTwoCharWithPinYin(Map<String, String> pinyinMap, String x1, String x2
, int scale, int point){
if(x1.length()<= point|| x2.length()<= point) {
if(x1.length()< x2.length()) {
for(int p= 0; p< scale; p++) {
if(!(x1.length()<= p|| x2.length()<= p)) {
if(x1.charAt(p)!= x2.charAt(p)) {
return false;
}
}
}
return true;
}
return false;
}else {
boolean hasX1= pinyinMap.containsKey(""+ x1.charAt(point));
boolean hasX2= pinyinMap.containsKey(""+ x2.charAt(point));
if(!(!hasX1|| !hasX2)){
String[] js= new String[2];
js[0]= pinyinMap.get(""+ x1.charAt(point));
js[1]= pinyinMap.get(""+ x2.charAt(point));
boolean change= processSortPinYin(js, 3);
if(change) {
return true;
}
return false;
}else if(!(hasX1|| hasX2)){
if(x1.toLowerCase().charAt(point)> x2.toLowerCase().charAt(point)) {
return true;
}else if(x1.toLowerCase().charAt(point)== x2.toLowerCase().charAt(point)) {
if(x1.charAt(point)> x2.charAt(point)) {
return true;
}
return false;
}
return false;
}else if(!(hasX1|| !hasX2)){
return true;
}
}
return false;
}
public static void main(String []v) {
try {
InputStream inputStreamc= new App3().getClass().getResourceAsStream("poscc.lyg");
BufferedReader cReaderc= new BufferedReader(new InputStreamReader(inputStreamc, "UTF8"));
InputStream inputStreamp= new App3().getClass().getResourceAsStream("poscp.lyg");
BufferedReader cReaderp= new BufferedReader(new InputStreamReader(inputStreamp, "UTF8"));
//index
String cInputStringc;
String cInputStringp;
Map<String, String> map= new HashMap<>();
while ((cInputStringp= cReaderp.readLine())!= null) {
cInputStringc= cReaderc.readLine();
String[] words= cInputStringp.split("/")[0].split(" ");
for(int i= 0; i< words.length; i++) {
if(!map.containsKey(""+ cInputStringc.charAt(i))) {
if(!cInputStringc.contains("字母")&& !cInputStringc.contains("标点")
&& !cInputStringc.contains("数字")&& !cInputStringc.contains("数词")) {
map.put(""+ cInputStringc.charAt(i), words[i]);
}
}
}
}
String[] strings1D= new String[3];
strings1D[0]= "dh罗韵律";
strings1D[1]= "dh罗瑶林";
strings1D[2]= "dh罗瑶光";
LYG10DWithChineseMixStringSort10D lYG10DWithChineseMixStringSort10D= new LYG10DWithChineseMixStringSort10D();
lYG10DWithChineseMixStringSort10D.quick4DChineseStringArray1D(strings1D, 30, map, 7, 70);
for(String string:strings1D) {
System.out.println(string);
}
String[][] strings2D= new String[14][3];
strings2D[0][1]= "dh罗韵律";
strings2D[1][1]= "dh罗瑶d林";
strings2D[2][1]= "dh罗瑶光";
strings2D[3][1]= "dh罗韵律";
strings2D[4][1]= "dh罗瑶g林";
strings2D[5][1]= "dhv罗瑶光";
strings2D[6][1]= "dh罗韵律";
strings2D[7][1]= "dh罗b瑶林";
strings2D[8][1]= "dh罗瑶光";
strings2D[9][1]= "dh罗韵律";
strings2D[10][1]= "dh罗瑶m林";
strings2D[11][1]= "dh罗瑶光";
strings2D[12][1]= "dh罗b瑶光";
strings2D[13][1]= "dh罗瑶光";
lYG10DWithChineseMixStringSort10D.quick4DChineseStringArray2D(strings2D, 30, map, 7, 70, 1);
for(String[] string:strings2D) {
System.out.println(string[1]);
}
}catch(Exception e) {
}
}
public void quick4DChineseStringArray2D(String[][] strings2d, int scale, Map<String, String> map
, int range, int deeps, int culumn) {
this.pinyin= map;
this.range= range;
this.deeps= deeps;
processKernel2D(strings2d, 0, strings2d.length- 1, scale, 0, culumn);
}
private void processKernel2D(String[][] kernel, int leftPosition
, int rightPosition, int scale, int point, int culumn) {
int rightPositionReflection= rightPosition;
if(point> scale) {
return;
}
processQS4DLYG9D2D(kernel, leftPosition, rightPosition, scale, point, 0, culumn);
int i;
for(i= leftPosition; i<= rightPosition; i++) {
if(!(kernel[i][culumn].length()<= point
|| kernel[leftPosition][culumn].length()<= point)) {
if(kernel[i][culumn].charAt(point)
!= kernel[leftPosition][culumn].charAt(point)){
rightPositionReflection= i- 1;
processKernel2D(kernel, leftPosition, rightPositionReflection, scale, point+ 1, culumn);
leftPosition= i;
}
}
}
if(leftPosition!= rightPosition) {
processKernel2D(kernel, leftPosition, i- 1, scale, point+ 1, culumn);
}
}
private void processQS4DLYG9D2D(String[][] kernel, int leftPosition
, int rightPosition, int scale, int point, int deep, int culumn) {
if(leftPosition< rightPosition){
int c= rightPosition- leftPosition+ 1;
if(!(c< this.range|| deep> this.deeps)) {//增加了deep
int pos= partition2D(kernel, leftPosition, rightPosition, scale, point, culumn);
if(leftPosition< pos- 1) {
processQS4DLYG9D2D(kernel, leftPosition, pos- 1, scale, point, deep+ 1, culumn);
}
if(pos+ 1< rightPosition) {
processQS4DLYG9D2D(kernel, pos+ 1, rightPosition, scale, point, deep+ 1, culumn);
}
return;
}
processSort2D(kernel, leftPosition, rightPosition, scale, point, culumn);
return;
}
}
private int partition2D(String[][] array, int leftPosition, int rightPosition
, int scale, int point, int culumn) {
String[] x= findSmall2D(array, scale, point, leftPosition, rightPosition, rightPosition, culumn)
? array[rightPosition]: array[leftPosition];
int leftPositionReflection= leftPosition;
while(leftPositionReflection++ < rightPosition) {
while(!(findSmallWithTwoChar(array[leftPositionReflection++][culumn]
, x[culumn], scale, point)|| leftPositionReflection> rightPosition)) {}
while(findSmallWithTwoChar(array[rightPosition--][culumn]
, x[culumn], scale, point)){}
if(--leftPositionReflection< ++rightPosition){
String[] temp= array[rightPosition].clone();;
array[rightPosition]= array[leftPositionReflection].clone();;
array[leftPositionReflection]= temp.clone();
}
}
array[leftPosition]= array[rightPosition].clone();
array[rightPosition]= x.clone();
return rightPosition;
}
private boolean findSmall2D(String[][] kernel, int scale, int point
, int i, int j, int rightPosition, int culumn) {
if(kernel[i][culumn].length()<= point
|| kernel[j][culumn].length()<= point) {
if(kernel[i][culumn].length()< kernel[j][culumn].length()) {
for(int p= 0; p< scale; p++) {
if(!(kernel[i][culumn].length()<= p|| kernel[j][culumn].length()<= p)) {
if(kernel[i][culumn].charAt(p)!= kernel[j][culumn].charAt(p)) {
return false;
}
}
}
return true;
}
return false;
}else {
boolean hasXi= pinyin.containsKey(""+ kernel[i][culumn].charAt(point));
boolean hasXj= pinyin.containsKey(""+ kernel[j][culumn].charAt(point));
if(!(!hasXi|| !hasXj)){
String[] js= new String[2];
js[0]= this.pinyin.get(""+ kernel[i][culumn].charAt(point));
js[1]= this.pinyin.get(""+ kernel[j][culumn].charAt(point));
boolean change= processSortPinYin(js, 3);
if(!(!change|| i>= j)) {
return true;
}
return false;
}else if(!(hasXi|| hasXj)){
if(kernel[i][culumn].toLowerCase().charAt(point)
> kernel[j][culumn].toLowerCase().charAt(point)) {
if(i< j) {
return true;
}
return false;
}else if(kernel[i][culumn].toLowerCase().charAt(point)
== kernel[j][culumn].toLowerCase().charAt(point)) {
if(kernel[i][culumn].charAt(point)
> kernel[j][culumn].charAt(point)) {
if(i< j) {
return true;
}
return false;
}
return false;
}
return false;
}else if(!(hasXi|| !hasXj)){
if(i< j) {
if(!(i== rightPosition || j== rightPosition)) {
return true;
}
return false;
}
return false;
}
}
return false;
}
private void processSort2D(String[][] kernel, int leftPosition
, int rightPosition, int scale, int point, int culumn) {
if(point> scale) {
return;
}
for(int i= leftPosition; i<= rightPosition; i++) {
Here:
for(int j= i; j<= rightPosition; j++) {
if(i== j) {
continue Here;
}
if(kernel[i][culumn].length()<= point
|| kernel[j][culumn].length()<= point) {
if(kernel[i][culumn].length()< kernel[j][culumn].length()) {
for(int p= 0; p< scale; p++) {
if(!(kernel[i][culumn].length()<= p
|| kernel[j][culumn].length()<= p)) {
if(kernel[i][culumn].charAt(p)
!= kernel[j][culumn].charAt(p)) {
continue Here;
}
}
}
String[] temp= kernel[i].clone();;
kernel[i]= kernel[j].clone();;
kernel[j]= temp.clone();
}
continue Here;
}else {
boolean hasXi= pinyin.containsKey(""+ kernel[i][culumn].charAt(point));
boolean hasXj= pinyin.containsKey(""+ kernel[j][culumn].charAt(point));
if(!(!hasXi|| !hasXj)){
String[] js= new String[2];
js[0]= this.pinyin.get(""+ kernel[i][culumn].charAt(point));
js[1]= this.pinyin.get(""+ kernel[j][culumn].charAt(point));
boolean change= processSortPinYin(js, 3);
if(!(!change|| i>= j)) {
String[] temp= kernel[i].clone();
kernel[i]= kernel[j].clone();
kernel[j]= temp.clone();
}
continue Here;
}else if(!(hasXi|| !hasXj)){
if(i< j) {
if(!(i== rightPosition+1 || j== rightPosition+1)) {
String[] temp= kernel[i].clone();
kernel[i]= kernel[j].clone();
kernel[j]= temp.clone();
}
}
continue Here;
}else if(!(hasXi|| hasXj)){
if(kernel[i][culumn].toLowerCase().charAt(point)
> kernel[j][culumn].toLowerCase().charAt(point)) {
if(i< j) {
String[] temp= kernel[i].clone();
kernel[i]= kernel[j].clone();
kernel[j]= temp.clone();
}
continue Here;
}
if(kernel[i][culumn].toLowerCase().charAt(point)
== kernel[j][culumn].toLowerCase().charAt(point)) {
if(kernel[i][culumn].charAt(point)> kernel[j][culumn].charAt(point)) {
if(i< j) {
String[] temp= kernel[i].clone();
kernel[i]= kernel[j].clone();
kernel[j]= temp.clone();
}
}
}
}
}
}
}
}
}