forked from Frieve-A/Frieve-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextproc.cpp
More file actions
1702 lines (1619 loc) · 52.2 KB
/
Copy pathtextproc.cpp
File metadata and controls
1702 lines (1619 loc) · 52.2 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
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
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//---------------------------------------------------------------------------
#include <math.h>
#include "textproc.h"
//---------------------------------------------------------------------------
TDMatrix::TDMatrix(int num) :
m_nDim(num)
{
m_IDs = new int[m_nDim];
m_Data = new float[m_nDim * m_nDim];
m_IDValue = new TList();
//inline対策
ID(0);
S(0, 0);
}
//---------------------------------------------------------------------------
TDMatrix::~TDMatrix()
{
FreeIDValue();
delete m_IDValue;
delete[] m_Data;
delete[] m_IDs;
}
//---------------------------------------------------------------------------
int &TDMatrix::ID(int idx)
{
return m_IDs[idx];
}
//---------------------------------------------------------------------------
float &TDMatrix::S(int source, int target)
{
return m_Data[source * m_nDim + target];
}
//---------------------------------------------------------------------------
void TDMatrix::FreeIDValue()
{
for (int i = 0 ; i < m_IDValue->Count ; i++){
delete (IDValue*)m_IDValue->Items[i];
}
m_IDValue->Clear();
}
//---------------------------------------------------------------------------
int __fastcall func_IDCmp(void * Item1, void * Item2)
{
return ((IDValue *)Item1)->ID - ((IDValue *)Item2)->ID;
}
//---------------------------------------------------------------------------
void TDMatrix::Finalize()
{
FreeIDValue();
//ソートされたIDとIndexのデータを作る
for (int i = 0 ; i < m_nDim ; i++){
IDValue *IDV = new IDValue;
IDV->ID = ID(i);
IDV->Value = i;
m_IDValue->Add(IDV);
}
m_IDValue->Sort(func_IDCmp);
}
//---------------------------------------------------------------------------
int TDMatrix::SearchIndex(int ID)
{
//IDのIndexを検索
register int step = m_IDValue->Count >> 1;
register int pos = step;
register int count = 0;//1ずつシフトしても見つからなかった回数
while (true){
int Cmp = ID - ((IDValue*)m_IDValue->Items[pos])->ID;
if (Cmp == 0){
return ((IDValue*)m_IDValue->Items[pos])->Value;
}else{
int laststep = step;
step >>= 1;
if (step < 1){
step = 1;
count++;
if (count >= 2){
return -1;
}
}else if (step << 1 != laststep){
count--;
}
if (Cmp < 0){
pos -= step;
if (pos < 0){
return -1;
}
}else{
pos += step;
if (pos >= m_IDValue->Count){
return -1;
}
}
}
}
/*
//IDのIndexを検索
int step = m_IDValue->Count >> 1;
int pos = step;
int count = 0;//1ずつシフトしても見つからなかった回数
while (count < 2 && pos >= 0 && pos < m_IDValue->Count){
int Cmp = ID - ((IDValue*)m_IDValue->Items[pos])->ID;
if (Cmp == 0){
return ((IDValue*)m_IDValue->Items[pos])->Value;
}else{
int laststep = step;
step >>= 1;
if (step < 1){
step = 1;
count++;
}else if (step << 1 != laststep){
count--;
}
if (Cmp < 0){
pos -= step;
}else{
pos += step;
}
}
}
return -1;
*/
}
//---------------------------------------------------------------------------
//コンストラクタ
TFList::TFList() :
m_nSize(0),
m_nCount(0),
m_Data(NULL)
{
}
//---------------------------------------------------------------------------
//デストラクタ
__fastcall TFList::~TFList()
{
Clear();
}
//---------------------------------------------------------------------------
//ポインタリストを倍にする
void TFList::Twice()
{
//次のサイズを決める
void **newdata;
int lastsize = m_nSize;
if (m_nSize){
m_nSize *= 2;
}else{
m_nSize = MINFLISTBUFSIZE;
}
//新しい格納場所を作る
newdata = new void*[m_nSize];
if (lastsize){
//これまでの結果をコピー
memcpy(newdata, m_Data, sizeof(void*) * m_nCount);
delete[] m_Data;
}
//新しい格納場所を代入
m_Data = newdata;
}
//---------------------------------------------------------------------------
//ポインタリストを半分にする
void TFList::Half()
{
//次のサイズを決める
void **newdata;
m_nSize /= 2;
//新しい格納場所を作る
if (m_nSize){
//サイズがある
newdata = new void*[m_nSize];
//これまでの結果をコピー
memcpy(newdata, m_Data, sizeof(void*) * m_nCount);
delete[] m_Data;
//新しい格納場所を代入
m_Data = newdata;
}else{
delete[] m_Data;
m_Data = NULL;
}
}
void __fastcall QuickSort(void **SortList, int L, int R, TFListSortCompare SCompare)
{
register int I = L;
while (I < R){
I = L;
register int J = R;
register void *P = SortList[(L + R) >> 1];
while (I <= J){
while (SCompare(SortList[I], P) < 0){
I++;
}
while (SCompare(SortList[J], P) > 0){
J--;
}
if (I <= J){
register void *T = SortList[I];
SortList[I] = SortList[J];
SortList[J] = T;
I++;
J--;
}
}
if (L < J){
QuickSort(SortList, L, J, SCompare);
}
L = I;
}
/*
int I = L;
while (I < R){
I = L;
int J = R;
void *P = SortList[(L + R) >> 1];
while (I <= J){
while (SCompare(SortList[I], P) < 0){
I++;
}
while (SCompare(SortList[J], P) > 0){
J--;
}
if (I <= J){
void *T = SortList[I];
SortList[I] = SortList[J];
SortList[J] = T;
I++;
J--;
}
}
if (L < J){
QuickSort(SortList, L, J, SCompare);
}
L = I;
}
*/
}
//---------------------------------------------------------------------------
//クイックソート
void TFList::QuickSort(TFListSortCompare CompFunc, int nLeft, int nRight)
{
if (m_nCount <= 1){
return;
}
//ピポット選択
void *p = m_Data[(nLeft + nRight + 1) / 2];
int Left = nLeft;
int Right = nRight;
while (true){
//左からp以上を探す
int lefti = Left;
while (CompFunc(m_Data[lefti], p) > 0){//pより小さい
lefti++;
}
//右からp以下を探す
int righti = Right;
while (CompFunc(m_Data[righti], p) < 0){//pより大きい
righti--;
}
if (lefti < righti){
//並び替え発生
void *tmp = m_Data[righti];
m_Data[righti] = m_Data[lefti];
m_Data[lefti] = tmp;
Left = lefti + 1;
Right = righti - 1;
}else{
//ピポットの左はピポット以下、右はピポット以上になった
//左右に分割してソート
if (nLeft < lefti - 1){
//左をソート
QuickSort(CompFunc, nLeft, lefti - 1);
}
if (lefti < nRight){
//右をソート
QuickSort(CompFunc, lefti, nRight);
}
break;
}
}
}
//---------------------------------------------------------------------------
//数を得る
int TFList::FCount()
{
return m_nCount;
}
//---------------------------------------------------------------------------
//追加
void *TFList::Add(void *p)
{
if (m_nCount >= m_nSize){
//格納場所が足りなければ拡張
Twice();
}
m_Data[m_nCount++] = p;
return p;
}
//---------------------------------------------------------------------------
//変更
void *TFList::Set(int nIndex, void *p)
{
m_Data[nIndex] = p;
return p;
}
//---------------------------------------------------------------------------
//挿入
void *TFList::Insert(int nIndex, void *p)
{
if (nIndex < m_nCount){
if (m_nCount >= m_nSize){
//格納場所が足りなければ拡張
Twice();
}
//挿入箇所以降を1つ後ろにずらす
for (int i = m_nCount ; i > nIndex ; i--){
m_Data[i] = m_Data[i - 1];
}
m_Data[nIndex] = p;
m_nCount++;
return p;
}else{
//最後に挿入(Addと同じ動作)
return Add(p);
}
}
//---------------------------------------------------------------------------
//削除
void TFList::Delete(int nindex)
{
//nindex番目のデータを削除
//nindex以降のデータを1つ手前にシフト
for (int i = nindex ; i < m_nCount - 1 ; i++){
m_Data[i] = m_Data[i + 1];
}
//数を減らす
m_nCount--;
//格納場所が大きすぎたら半分に
if (m_nCount <= m_nSize / 2 && m_nCount > MINFLISTBUFSIZE){
Half();
}
}
//---------------------------------------------------------------------------
//参照
void *TFList::FItems(int nindex)
{
return m_Data[nindex];
}
void TFList::FWrite(int nindex, void *P)
{
m_Data[nindex] = P;
}
//---------------------------------------------------------------------------
//全削除
void TFList::Clear()
{
if (m_nSize){
delete[] m_Data;
m_nSize = 0;
m_nCount = 0;
m_Data = NULL;
}
}
//---------------------------------------------------------------------------
//ソート
void TFList::Sort(TFListSortCompare CompFunc)
{
// QuickSort(CompFunc, 0, Count - 1);
if (m_nCount <= 1){
return;
}
::QuickSort(m_Data, 0, Count - 1, CompFunc);
}
//---------------------------------------------------------------------------
//シャッフル
void TFList::Shuffle()
{
for (int i = 0 ; i < m_nCount ; i++){
int idx = rand() % m_nCount;
void *tmp = m_Data[i];
m_Data[i] = m_Data[idx];
m_Data[idx] = tmp;
}
}
//---------------------------------------------------------------------------
/*
int __fastcall func_pwsCmp(void * Item1, void * Item2)
{
WideString *WS1 = (WideString *)Item1;
WideString *WS2 = (WideString *)Item2;
return WideCompareText(*WS1, *WS2);
}
*/
//#define DEBUG_SPEEDTUNE
#ifdef DEBUG_SPEEDTUNE
#include <mmsystem.hpp>
#endif
//---------------------------------------------------------------------------
TTextDecomposer::TTextDecomposer(TWideStringList *SL, int maxcombi, int maxcount, float pgmin, float pgmax, float &pgpos, bool &terminated, int option) :
m_nMaxCombi(maxcombi)
{
#ifdef DEBUG_SPEEDTUNE
//デバッグ用変数
int debug_orgtotal = 0;//もともとの組み合わせ総数
int debug_fewdeleted = 0;//より短い組み合わせが1回以下しか出現していなかったため削除
int debug_dplxdeleted = 0;//重複で削除された組み合わせの総数
int debug_shortdeleted = 0;//より短い組み合わせがより長い組み合わせと同数だったため削除
int debug_totalremain = 0;//抽出された組み合わせ総数
unsigned int time_bunkai = 0, time_sort = 0, time_rekkyo = 0, t;
#endif
WideString Ret = "\n";
m_Gram = new TWSandValueList*[maxcombi];
//N-gramループ
for (int i = 0 ; i < m_nMaxCombi ; i++){
m_Gram[i] = new TWSandValueList();
}
TWSandValueList *lastgram = NULL;
for (int i = 0 ; i < m_nMaxCombi && !terminated ; i++){
TWideStringList *Tmp = new TWideStringList();//各カードの重複なし組み合わせ格納用
if (i > 0){
if (lastgram->Count == 0){
//もう組み合わせが無い
break;
}
}
TWSandValueList *gram = m_Gram[i];
//カードループ
for (int ic = 0 ; ic < SL->Count ; ic++){
//小文字化
//WideString WS = SL->Strings(ic);
WideString WS;
if (option & 0x1) {
//小文字化禁止
WS = SL->Strings(ic);
}else{
//通常はロバストネスのため小文字に統一
WS = WideLowerCase(SL->Strings(ic));
}
//if (i > 0){
#ifdef DEBUG_SPEEDTUNE
t = timeGetTime();
#endif
//組み合わせ分解
int len = i + 1;
int wslen = WS.Length();
TWideStringList *Tmp2 = new TWideStringList();//カード内の全組み合わせ格納用
/*
for (int i2 = 0 ; i2 < wslen - i ; i2++){
WideString W1 = WS.SubString(i2 + 1, len);
int p = W1.Pos("\n");
if (p == 0){
Tmp2->Add(W1);
}else{
i2 += p - 1;
}
}
//*/
//*
int count = 0;
wchar_t *w1 = &WS[1];
for (int i2 = 0 ; i2 < wslen ; i2++){
if (*w1++ == '\n'){
count = 0;
}else{
if (count < len){
count++;
}
if (count == len){
Tmp2->Add(WS.SubString(i2 - i + 1, len));
}
}
}
//*/
#ifdef DEBUG_SPEEDTUNE
time_bunkai += timeGetTime() - t;
t = timeGetTime();
#endif
Tmp2->Sort();
#ifdef DEBUG_SPEEDTUNE
debug_orgtotal += Tmp2->Count;
time_sort += timeGetTime() - t;
#endif
//重複削除しながらこのカードの組み合わせに追加
//WS = "";
#ifdef DEBUG_SPEEDTUNE
t = timeGetTime();
#endif
if (Tmp2->Count > 0){
if (i > 0){
//2回以上出現している組み合わせを含むより長い組み合わせのみ残す
register int lastindex = 0;
int lastcount = lastgram->Count;
WideString *TSL;//直前の文字列保存用
int tmp2count = Tmp2->Count;
for (int i3 = 0 ; i3 < tmp2count ; i3++){
WideString *TS1 = Tmp2->StringsP(i3);//追加すべきテキスト
//WideString *TS1 = (WideString*)&Tmp2->Strings(i3);//追加すべきテキスト
//bool add = true;
bool add = i3 == 0 ? true : (WideCompareStr(*TSL, *TS1) != 0);
//bool add = i3 == 0 ? true : (wcscmp(TSL, TS1) != 0);
if (add){//Tmp2->Strings(i3)を追加すべき
WideString TSC = TS1->SubString(1, i);//1文字短い追加対象
//WideString TSC = ((WideString)TS1).SubString(1, i);//1文字短い追加対象
int cmp = 1;
while (lastindex < lastcount){
cmp = WideCompareStr(lastgram->Strings(lastindex), TSC);
//cmp = wcscmp(lastgram->Strings(lastindex), TSC);
if (cmp < 0){
lastindex++;
}else{
break;
}
}
if (cmp == 0){
//WS += TS;
//*
Tmp->AddP(TS1);
Tmp2->SetNULL(i3);
//*/
//Tmp->AddA(*TS1);
}
#ifdef DEBUG_SPEEDTUNE
else{
debug_fewdeleted++;
}
#endif
}
#ifdef DEBUG_SPEEDTUNE
else{
debug_fewdeleted++;
}
#endif
TSL = TS1;
}
}else{
//全ての組み合わせを残す
WideString *WSL;
int tmp2count = Tmp2->Count;
for (int i3 = 0 ; i3 < tmp2count ; i3++){
register WideString *TS1 = Tmp2->StringsP(i3);
//register WideString *TS1 = (WideString*)&Tmp2->Strings(i3);
//bool add = true;
bool add = i3 == 0 ? true : *TS1 != Ret && WideCompareStr(*WSL, *TS1) != 0;
if (add){
//Tmp->AddA(*TS1);
Tmp->AddP(TS1);
Tmp2->SetNULL(i3);
}
#ifdef DEBUG_SPEEDTUNE
else{
debug_fewdeleted++;
}
#endif
WSL = TS1;
}
}
}
delete Tmp2;
#ifdef DEBUG_SPEEDTUNE
time_rekkyo += timeGetTime() - t;
#endif
/*
}else{
WideString WSBak = WS;
WS = "";
for (int i3 = 0 ; i3 < WSBak.Length() ; i3++){
WideString W1 = WSBak.SubString(i3 + 1, 1);
if (W1 != Ret){
WS += W1;
}
}
debug_orgtotal += WS.Length();
}
*/
//Tmp += WS;
/*
int len2 = Tmp.Length();
if (len2 % (i + 1) != 0){
Tmp = "";
}
//*/
}//カードループ
//全カードの結果合成
//組み合わせ分解
/*
int len = i + 1;
int count = Tmp.Length() / len;
TWideStringList *Tmp2 = new TWideStringList();//カード内の全組み合わせ格納用
for (int i2 = 0 ; i2 < count ; i2++){
Tmp2->Add(Tmp.SubString(i2 * len + 1, len));
}
Tmp2->Sort();
*/
Tmp->Sort();
//重複削除かつ2回出現したもののみこのカードの組み合わせに追加
int count = 0;
int tmpcount = Tmp->Count;
if (tmpcount > 0){
WideString *WSL = Tmp->StringsP(0);
//WideString *WSL = (WideString*)&Tmp->Strings(0);
for (int i3 = 1 ; i3 < tmpcount ; i3++){
WideString *TS = Tmp->StringsP(i3);
//WideString *TS = (WideString*)&Tmp->Strings(i3);
if (WideCompareStr(*WSL, *TS) != 0){
//異なる
if (count > 0){
count++;
gram->Values(gram->Count - 1) = count;
if (maxcount > 0 && count >= maxcount){
gram->Enabled(gram->Count - 1) = false;
#ifdef DEBUG_SPEEDTUNE
debug_shortdeleted++;
#endif
}
}
#ifdef DEBUG_SPEEDTUNE
debug_dplxdeleted++;
#endif
count = 0;
}else{
//同じ
count ++;
if (count == 1){
//gram->AddA(*TS);
gram->AddP(TS);
Tmp->SetNULL(i3);
}
#ifdef DEBUG_SPEEDTUNE
else{
debug_dplxdeleted++;
}
#endif
}
WSL = TS;
}
if (count > 0){
count++;
gram->Values(gram->Count - 1) = count;
if (maxcount > 0 && count >= maxcount){
gram->Enabled(gram->Count - 1) = false;
#ifdef DEBUG_SPEEDTUNE
debug_shortdeleted++;
#endif
}
}
#ifdef DEBUG_SPEEDTUNE
debug_dplxdeleted++;
#endif
}
/*
//m_Gramとm_GramCountの数が同じかチェック(デバッグ用)
if (gram->Count != m_GramCount[i]->Count){
m_GramCount[i]->Add(NULL);
}
*/
//(N-1)gramと出現回数が同じなら(N-1)gramを削除。同時にindex対応付け
if (i > 0){
int lastindex = 0;
int lastcount = lastgram->Count;
int count = gram->Count;
for (int i3 = 0 ; i3 < count ; i3++){
WideString TSC = gram->Strings(i3).SubString(1, i);//1文字短いテキスト
int cmp = 1;
while (lastindex < lastcount){
if ((cmp = WideCompareStr(lastgram->Strings(lastindex), TSC)) < 0){
lastindex++;
}else{
break;
}
}
if (cmp == 0){
if (lastgram->From(lastindex) == -1){
lastgram->From(lastindex) = i3;
}
if (lastgram->Values(lastindex) == gram->Values(i3)){
if (lastgram->Enabled(lastindex)){
lastgram->Enabled(lastindex) = false;
#ifdef DEBUG_SPEEDTUNE
debug_shortdeleted++;
#endif
}
}
lastgram->To(lastindex) = i3;
}
}
}
//2文字目以降でソート
gram->Sort2();
//2文字目以降で(N-1)gramと出現回数が同じなら(N-1)gramを削除
if (i > 0){
int lastindex = 0;
int lastcount = lastgram->Count;
int count = gram->Count;
for (int i3 = 0 ; i3 < count ; i3++){
WideString TSC = gram->Strings(i3).SubString(2, i);//1文字短いテキスト
int cmp = 1;
while (lastindex < lastcount){
if ((cmp = WideCompareStr(lastgram->Strings(lastindex), TSC)) < 0){
lastindex++;
}else{
break;
}
}
if (cmp == 0){
if (lastgram->Values(lastindex) == gram->Values(i3)){
if (lastgram->Enabled(lastindex)){
lastgram->Enabled(lastindex) = false;
#ifdef DEBUG_SPEEDTUNE
debug_shortdeleted++;
#endif
}
}
}
}
}
//順序を元に(1文字目からのソートに)戻す
gram->Sort();
delete Tmp;
lastgram = gram;
//Progress
if (pgmax > pgmin){
pgpos = ((pgmax - pgmin) * (i + 1)) / m_nMaxCombi + pgmin;
Application->ProcessMessages();
}
}//N-gramループ
//合計計算、シリアル振り
m_nMaxSN = 0;
for (int i = 0 ; i < m_nMaxCombi ; i++){
TWSandValueList *gram = m_Gram[i];
int gramcount = gram->Count;
for (int i3 = 0 ; i3 < gramcount ; i3++) if (gram->Enabled(i3)){
#ifdef DEBUG_SPEEDTUNE
debug_totalremain++;
#endif
gram->SN(i3) = m_nMaxSN++;
}
}
}
//---------------------------------------------------------------------------
TTextDecomposer::~TTextDecomposer()
{
for (int i = 0 ; i < m_nMaxCombi ; i++){
delete m_Gram[i];
}
delete[] m_Gram;
}
//---------------------------------------------------------------------------
/*
WideString *TTextDecomposer::GetStr(int list, int index)
{
return (WideString *)m_Gram[list]->Items[index];
}
*/
//---------------------------------------------------------------------------
//TWideStringList
//---------------------------------------------------------------------------
_fastcall TWideStringList::~TWideStringList()
{
Clear();
}
//---------------------------------------------------------------------------
void _fastcall TWideStringList::Clear()
{
/*
for (int i = Count - 1 ; i >= 0 ; i--){
delete (WideString*)Items[i];
}
*/
for (int i = 0 ; i < Count ; i++){
if (Items[i]){
delete (WideString*)Items[i];
}
}
TFListforTP::Clear();
}
//---------------------------------------------------------------------------
//追加
void TWideStringList::Add(WideString S)
{
WideString *S1 = new WideString;
*S1 = S;
TFListforTP::Add(S1);
}
//---------------------------------------------------------------------------
//追加
void TWideStringList::AddA(WideString &S)
{
WideString *S1 = new WideString;
*S1 = S;
TFListforTP::Add(S1);
}
//---------------------------------------------------------------------------
void TWideStringList::AddP(WideString *S)
{
TFListforTP::Add(S);
}
//---------------------------------------------------------------------------
void TWideStringList::SetNULL(int nindex)
{
Items[nindex] = NULL;
}
//---------------------------------------------------------------------------
//削除
void TWideStringList::Delete(int nindex)
{
if (Items[nindex]){
delete (WideString*)Items[nindex];
}
TFListforTP::Delete(nindex);
}
//---------------------------------------------------------------------------
//参照
WideString &TWideStringList::Strings(int nindex)
{
return *(WideString*)Items[nindex];
}
//---------------------------------------------------------------------------
//参照
WideString *TWideStringList::StringsP(int nindex)
{
return (WideString*)Items[nindex];
}
//---------------------------------------------------------------------------
int __fastcall WideStringSortCompare(void * Item1, void * Item2)
{
return WideCompareStr(*(WideString*)Item1, *(WideString*)Item2);
}
//---------------------------------------------------------------------------
//昇順ソート
void TWideStringList::Sort()
{
TFListforTP::Sort(WideStringSortCompare);
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//TWSandValueList
//---------------------------------------------------------------------------
_fastcall TWSandValueList::~TWSandValueList()
{
Clear();
}
//---------------------------------------------------------------------------
void _fastcall TWSandValueList::Clear()
{
for (int i = 0 ; i < Count ; i++){
delete ((WSandValue*)Items[i])->WS;
delete (WSandValue*)Items[i];
}
TFListforTP::Clear();
}
//---------------------------------------------------------------------------
//追加
void TWSandValueList::Add(WideString S)
{
WSandValue *S1 = new WSandValue;
(*S1).WS = new WideString;
*(*S1).WS = S;
(*S1).Value = 0;
(*S1).Enabled = true;
(*S1).From = -1;
(*S1).To = -1;
(*S1).SN = -1;
TFListforTP::Add(S1);
}
//---------------------------------------------------------------------------
//追加
void TWSandValueList::AddA(WideString &S)
{
WSandValue *S1 = new WSandValue;
(*S1).WS = new WideString;
*(*S1).WS = S;
(*S1).Value = 0;
(*S1).Enabled = true;
(*S1).From = -1;
(*S1).To = -1;
(*S1).SN = -1;
TFListforTP::Add(S1);
}
//---------------------------------------------------------------------------
//追加
void TWSandValueList::AddP(WideString *S)
{
WSandValue *S1 = new WSandValue;
(*S1).WS = S;
(*S1).Value = 0;
(*S1).Enabled = true;
(*S1).From = -1;
(*S1).To = -1;
(*S1).SN = -1;
TFListforTP::Add(S1);
}
//---------------------------------------------------------------------------
//削除
void TWSandValueList::Delete(int nindex)
{
delete ((WSandValue*)Items[nindex])->WS;
delete (WSandValue*)Items[nindex];
TFListforTP::Delete(nindex);
}
//---------------------------------------------------------------------------
//参照
WideString &TWSandValueList::Strings(int nindex)
{
return *(*(WSandValue*)Items[nindex]).WS;
}
//---------------------------------------------------------------------------
//参照
int &TWSandValueList::Values(int nindex)
{
return (*(WSandValue*)Items[nindex]).Value;
}
//---------------------------------------------------------------------------
//参照
bool &TWSandValueList::Enabled(int nindex)
{
return (*(WSandValue*)Items[nindex]).Enabled;
}
//---------------------------------------------------------------------------
//参照
int &TWSandValueList::From(int nindex)
{
return (*(WSandValue*)Items[nindex]).From;
}
//---------------------------------------------------------------------------
//参照
int &TWSandValueList::To(int nindex)
{
return (*(WSandValue*)Items[nindex]).To;
}
//---------------------------------------------------------------------------
//参照
int &TWSandValueList::SN(int nindex)
{
return (*(WSandValue*)Items[nindex]).SN;
}
//---------------------------------------------------------------------------
int _fastcall WSandValueSortCompare(void * Item1, void * Item2)
{
return WideCompareStr(*(*(WSandValue*)Item1).WS, *(*(WSandValue*)Item2).WS);
}
//---------------------------------------------------------------------------
int _fastcall WSandValueSortCompare2(void * Item1, void * Item2)
{
//2文字目以降
return WideCompareStr((*(WSandValue*)Item1).WS->SubString(2, 32767), (*(WSandValue*)Item2).WS->SubString(2, 32767));
}
//---------------------------------------------------------------------------
int _fastcall WSandValueSortCompareValue(void * Item1, void * Item2)
{
//2文字目以降
return (*(WSandValue*)Item1).Value - (*(WSandValue*)Item2).Value;
}
//---------------------------------------------------------------------------
//昇順ソート
void TWSandValueList::Sort()
{