-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathconverters.cpp
4685 lines (3772 loc) · 148 KB
/
converters.cpp
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
// converters.cpp
// Copyright (C) 2023 Richard Geldreich, Jr.
#include "ufojson_core.h"
#include "markdown_proc.h"
#include <unordered_map>
#define USE_OPENAI (0)
// Escapes quoted strings.
static std::string escape_string_for_json(const std::string& str)
{
std::string new_str;
for (uint32_t i = 0; i < str.size(); i++)
{
char c = str[i];
if (c == '"')
new_str.push_back('\\');
else if (c == '\\')
new_str.push_back('\\');
else if (c == '\n')
{
new_str.push_back('\\');
new_str.push_back('n');
continue;
}
new_str.push_back(c);
}
return new_str;
}
bool convert_magonia(const char* pSrc_filename, const char* pDst_filename, const char* pSource_override, const char* pRef_override, uint32_t TOTAL_COLS, const char* pType_override, bool parens_flag, uint32_t first_rec_index)
{
string_vec lines;
if (!read_text_file(pSrc_filename, lines, true, nullptr))
panic("Can't open file %s", pSrc_filename);
FILE* pOut_file = ufopen(pDst_filename, "w");
if (!pOut_file)
panic("Can't open file %s", pDst_filename);
fputc(UTF8_BOM0, pOut_file);
fputc(UTF8_BOM1, pOut_file);
fputc(UTF8_BOM2, pOut_file);
fprintf(pOut_file, "{\n");
fprintf(pOut_file, "\"%s Timeline\" : [\n", pSource_override ? pSource_override : "Magonia");
//const uint32_t TOTAL_RECS = 923;
uint32_t cur_line = 0;
uint32_t rec_index = first_rec_index;
while (cur_line < lines.size())
{
if (!lines[cur_line].size())
panic("Line %u is empty", cur_line);
int index = atoi(lines[cur_line++].c_str());
if (index != (int)rec_index)
panic("Unexpected index");
if (cur_line == lines.size())
panic("Out of lines");
std::string first_line(lines[cur_line++]);
std::string date_str(first_line);
if (date_str.size() > TOTAL_COLS)
date_str.resize(TOTAL_COLS);
string_trim(date_str);
if (first_line.size() < (TOTAL_COLS + 1))
{
if (cur_line == lines.size())
panic("Out of lines");
first_line = lines[cur_line++];
if (first_line.size() < (TOTAL_COLS + 1))
panic("Line too small");
}
string_vec desc_lines;
first_line.erase(0, TOTAL_COLS);
string_trim(first_line);
desc_lines.push_back(first_line);
std::string time_str;
for (; ; )
{
if (cur_line == lines.size())
break;
// Absorb empty line which indicates end of record
if (desc_lines.size() == 1)
{
if (!lines[cur_line].size())
{
cur_line++;
break;
}
}
std::string buf(lines[cur_line]);
if ((desc_lines.size() == 1) && (buf.size() < TOTAL_COLS))
{
if (string_find_first(buf, ":") >= 0)
{
// Must be ONLY time
time_str = buf;
string_trim(time_str);
cur_line++;
break;
}
}
if (buf.size() < TOTAL_COLS)
break;
if (desc_lines.size() == 1)
{
if (buf.size() >= TOTAL_COLS)
{
time_str = buf;
time_str.resize(TOTAL_COLS);
string_trim(time_str);
buf.erase(0, TOTAL_COLS);
}
}
string_trim(buf);
desc_lines.push_back(buf);
cur_line++;
}
std::string desc;
for (uint32_t j = 0; j < desc_lines.size(); j++)
{
if (desc.size() && desc.back() == '-')
{
// Don't trim '-' char if the previous char is a digit. This is probably imperfect.
if (!((desc.size() >= 2) && (isdigit((uint8_t)desc[desc.size() - 2]))))
desc.resize(desc.size() - 1);
}
else if (desc.size())
{
desc += " ";
}
desc += desc_lines[j];
}
std::string location;
size_t n = desc.find_first_of('}');
if (n == std::string::npos)
n = desc.find_first_of('.');
if (n == std::string::npos)
panic("Can't find . char");
location = desc;
location.resize(n);
string_trim(location);
if (parens_flag)
{
size_t f = location.find_first_of('(');
size_t e = location.find_last_of(')');
if ((f != std::string::npos) && (e == location.size() - 1))
{
std::string state(location);
state.erase(0, f + 1);
if (state.size())
state.resize(state.size() - 1);
string_trim(state);
location.erase(f, location.size() - f);
string_trim(location);
location += ", ";
location += state;
}
}
desc.erase(0, n + 1);
string_trim(desc);
std::string ref;
if (parens_flag)
{
size_t f = desc.find_last_of('(');
size_t e = desc.find_last_of(')');
if ((f != std::string::npos) && (e != std::string::npos))
{
if ((f < e) && (e == desc.size() - 1))
{
ref = desc.c_str() + f + 1;
if (ref.size())
ref.pop_back();
string_trim(ref);
desc.resize(f);
string_trim(desc);
}
}
}
int year = -1, month = -1, day = -1;
date_prefix_t date_prefix = cNoPrefix;
std::string date_suffix;
std::string temp_date_str(date_str);
if (string_ends_in(temp_date_str, "'s"))
{
temp_date_str.resize(temp_date_str.size() - 2);
date_suffix = "'s";
}
if (string_begins_with(temp_date_str, "End "))
{
date_prefix = cEndOf;
temp_date_str.erase(0, strlen("End "));
string_trim(temp_date_str);
}
else if (string_begins_with(temp_date_str, "Early "))
{
date_prefix = cEarly;
temp_date_str.erase(0, strlen("Early "));
string_trim(temp_date_str);
}
else if (string_begins_with(temp_date_str, "Late "))
{
date_prefix = cLate;
temp_date_str.erase(0, strlen("Late "));
string_trim(temp_date_str);
}
else if (string_begins_with(temp_date_str, "Mid "))
{
date_prefix = cMiddleOf;
temp_date_str.erase(0, strlen("Mid "));
string_trim(temp_date_str);
}
size_t f = date_str.find_first_of(',');
uint32_t m;
for (m = 0; m < 12; m++)
if (string_begins_with(temp_date_str, g_months[m]))
break;
if (m != 12)
{
month = m + 1;
temp_date_str.erase(0, strlen(g_months[m]));
string_trim(temp_date_str);
if (!temp_date_str.size())
panic("Failed parsing date");
f = temp_date_str.find_first_of(',');
if (f != std::string::npos)
{
if (f == 0)
{
temp_date_str.erase(0, 1);
string_trim(temp_date_str);
if (!isdigit(temp_date_str[0]))
panic("Failed parsing date");
year = atoi(temp_date_str.c_str());
if ((year < 34) || (year > 2050))
panic("Failed parsing date");
}
else
{
day = atoi(temp_date_str.c_str());
temp_date_str.erase(0, f + 1);
string_trim(temp_date_str);
if (!isdigit(temp_date_str[0]))
panic("Failed parsing date");
year = atoi(temp_date_str.c_str());
if ((year < 34) || (year > 2050))
panic("Failed parsing date");
}
}
else
{
if (!isdigit(temp_date_str[0]))
panic("Failed parsing date");
year = atoi(temp_date_str.c_str());
if ((year < 34) || (year > 2050))
panic("Failed parsing date");
}
}
else
{
// The Magonia data doesn't use the full range of prefixes we support.
if (string_begins_with(temp_date_str, "Summer,"))
{
date_prefix = cSummer;
temp_date_str.erase(0, strlen("Summer,"));
string_trim(temp_date_str);
}
else if (string_begins_with(temp_date_str, "Spring,"))
{
date_prefix = cSpring;
temp_date_str.erase(0, strlen("Spring,"));
string_trim(temp_date_str);
}
else if (string_begins_with(temp_date_str, "Winter,"))
{
date_prefix = cWinter;
temp_date_str.erase(0, strlen("Winter,"));
string_trim(temp_date_str);
}
else if (string_begins_with(temp_date_str, "Fall,"))
{
date_prefix = cFall;
temp_date_str.erase(0, strlen("Fall,"));
string_trim(temp_date_str);
}
else if (string_begins_with(temp_date_str, "End "))
{
date_prefix = cEndOf;
temp_date_str.erase(0, strlen("End "));
string_trim(temp_date_str);
}
else if (string_begins_with(temp_date_str, "Early "))
{
date_prefix = cEarly;
temp_date_str.erase(0, strlen("Early "));
string_trim(temp_date_str);
}
else if (string_begins_with(temp_date_str, "Late "))
{
date_prefix = cLate;
temp_date_str.erase(0, strlen("Late "));
string_trim(temp_date_str);
}
if (!isdigit(temp_date_str[0]))
panic("Failed parsing date");
year = atoi(temp_date_str.c_str());
if ((year < 34) || (year > 2050))
panic("Failed parsing date");
}
if (pRef_override)
{
if (ref.size())
ref += " ";
ref += pRef_override;
}
else
ref += " ([Vallee](https://web.archive.org/web/20120415100852/http://www.ufoinfo.com/magonia/magonia.shtml))";
//printf("## %u. Date: \"%s\" (%s %i/%i/%i), Time: \"%s\" Location: \"%s\", Ref: \"%s\"\n",
// i, date_str.c_str(), (date_prefix >= 0) ? g_date_prefix_strings[date_prefix] : "", month, day, year, time_str.c_str(), location.c_str(), ref.c_str());
//printf("%s\n", desc.c_str());
if (rec_index > first_rec_index) //1)
fprintf(pOut_file, ",\n");
fprintf(pOut_file, "{\n");
fprintf(pOut_file, " \"date\" : \"");
if (date_prefix >= 0)
fprintf(pOut_file, "%s ", g_date_prefix_strings[date_prefix]);
if (month == -1)
fprintf(pOut_file, "%i%s", year, date_suffix.c_str());
else if (day == -1)
{
if (date_suffix.size())
panic("Invalid date suffix");
fprintf(pOut_file, "%i/%i", month, year);
}
else
{
if (date_suffix.size())
panic("Invalid date suffix");
fprintf(pOut_file, "%i/%i/%i", month, day, year);
}
fprintf(pOut_file, "\",\n");
fprintf(pOut_file, " \"desc\": \"%s\",\n", escape_string_for_json(desc).c_str());
if (location.size())
fprintf(pOut_file, " \"location\" : \"%s\",\n", escape_string_for_json(location).c_str());
if (time_str.size())
fprintf(pOut_file, " \"time\" : \"%s\",\n", time_str.c_str());
if (ref.size())
fprintf(pOut_file, " \"ref\": \"%s\",\n", escape_string_for_json(ref).c_str());
if (pSource_override)
fprintf(pOut_file, " \"source_id\" : \"%s_%u\",\n", pSource_override, rec_index);
else
fprintf(pOut_file, " \"source_id\" : \"Magonia_%u\",\n", rec_index);
fprintf(pOut_file, u8" \"source\" : \"%s\",\n", pSource_override ? pSource_override : u8"ValléeMagonia");
if (pType_override)
fprintf(pOut_file, " \"type\" : \"%s\"\n", pType_override);
else
fprintf(pOut_file, " \"type\" : \"ufo sighting\"\n");
fprintf(pOut_file, "}");
rec_index++;
}
fprintf(pOut_file, "\n] }\n");
fclose(pOut_file);
return true;
}
bool convert_bluebook_unknowns()
{
string_vec lines;
if (!read_text_file("bb_unknowns.txt", lines, true, nullptr))
panic("Can't read file bb_unknowns.txt");
uint32_t cur_line = 0;
uint32_t total_recs = 0;
FILE* pOut_file = ufopen("bb_unknowns.json", "w");
if (!pOut_file)
panic("Can't open output file bb_unknowns.json");
fputc(UTF8_BOM0, pOut_file);
fputc(UTF8_BOM1, pOut_file);
fputc(UTF8_BOM2, pOut_file);
fprintf(pOut_file, "{\n");
fprintf(pOut_file, "\"BlueBookUnknowns Timeline\" : [\n");
while (cur_line < lines.size())
{
std::string rec;
while (cur_line < lines.size())
{
std::string l(lines[cur_line]);
cur_line++;
string_trim(l);
if (!l.size())
break;
if (rec.size() && rec.back() == '-')
rec += l;
else
{
rec += ' ';
rec += l;
}
}
if (rec.size())
{
//printf("%u. %s\n", total_recs + 1, rec.c_str());
size_t semi_ofs = rec.find_first_of(';');
if (semi_ofs == std::string::npos)
panic("Unable to find initial ; char");
std::string date_str(rec);
date_str.resize(semi_ofs);
string_trim(date_str);
rec.erase(0, semi_ofs + 1);
string_trim(rec);
size_t period_ofs = rec.find_first_of(';');
if (period_ofs == std::string::npos)
{
period_ofs = rec.find_first_of('.');
if (period_ofs == std::string::npos)
panic("Unable to find . char");
if (((period_ofs >= 2) && (rec[period_ofs - 1] == 't') && (rec[period_ofs - 2] == 'F')) ||
((period_ofs >= 2) && (rec[period_ofs - 1] == 't') && (rec[period_ofs - 2] == 'M')))
{
period_ofs = rec.find('.', period_ofs + 1);
if (period_ofs == std::string::npos)
panic("Unable to find . char");
}
}
std::string location_str(rec);
location_str.resize(period_ofs);
string_trim(location_str);
rec.erase(0, period_ofs + 1);
string_trim(rec);
size_t time_period_ofs = rec.find_first_of('.');
if (time_period_ofs == std::string::npos)
panic("Unable to find , char");
std::string time_str(rec);
time_str.resize(time_period_ofs);
string_trim(time_str);
rec.erase(0, time_period_ofs + 1);
string_trim(rec);
//printf("Rec: %u\n", total_recs + 1);
//printf("Location: %s\n", location_str.c_str());
//printf("Time: %s\n", time_str.c_str());
//printf("Desc: %s\n", rec.c_str());
std::string json_date;
if ((string_begins_with(date_str, "Spring")) || (string_begins_with(date_str, "Summer")))
{
json_date = date_str;
}
else
{
size_t date_space = date_str.find_first_of(' ');
if (date_space == std::string::npos)
panic("Unable to find space char");
size_t date_comma = date_str.find_first_of(',');
int month;
if (string_begins_with(date_str, "Sept."))
month = 8;
else
{
for (month = 0; month < 12; month++)
{
if (string_begins_with(date_str, g_months[month]))
break;
if (string_begins_with(date_str, g_full_months[month]))
break;
}
if (month == 12)
panic("Failed finding month");
}
char buf[256];
int day, year;
if (date_comma == std::string::npos)
{
year = atoi(date_str.c_str() + date_space + 1);
if ((year < 1900) || (year > 1969))
panic("Invalid year");
sprintf_s(buf, "%u/%u", month + 1, year);
}
else
{
day = atoi(date_str.c_str() + date_space + 1);
if ((day < 1) || (day > 31))
panic("Invalid day");
year = atoi(date_str.c_str() + date_comma + 1);
if ((year < 1900) || (year > 1969))
panic("Invalid year");
sprintf_s(buf, "%u/%u/%u", month + 1, day, year);
}
json_date = buf;
}
//printf("JSON Date: %s\n", date_str.c_str());
//printf("Date: %s\n", json_date.c_str());
fprintf(pOut_file, "{\n");
fprintf(pOut_file, " \"date\" : \"%s\",\n", json_date.c_str());
fprintf(pOut_file, " \"time\" : \"%s\",\n", time_str.c_str());
fprintf(pOut_file, " \"location\" : \"%s\",\n", escape_string_for_json(location_str).c_str());
fprintf(pOut_file, " \"desc\" : \"%s\",\n", escape_string_for_json(rec).c_str());
fprintf(pOut_file, " \"source_id\" : \"BerlinerBBU_%u\",\n", total_recs);
fprintf(pOut_file, " \"source\" : \"BerlinerBBUnknowns\",\n");
fprintf(pOut_file, " \"ref\" : \"[BlueBook Unknowns PDF](https://github.com/richgel999/uap_resources/blob/main/bluebook_uncensored_unknowns_don_berliner.pdf)\",\n");
fprintf(pOut_file, " \"type\" : \"ufo sighting\"\n");
fprintf(pOut_file, "}");
if (cur_line < lines.size())
fprintf(pOut_file, ",");
fprintf(pOut_file, "\n");
total_recs++;
}
}
fprintf(pOut_file, "] }\n");
fclose(pOut_file);
return true;
}
static std::string convert_hall_to_json_date(const std::string& date_str)
{
std::string json_date;
if ((string_begins_with(date_str, "Spring")) ||
(string_begins_with(date_str, "Summer")) ||
(string_begins_with(date_str, "Late")) ||
(string_begins_with(date_str, "Early")))
{
json_date = date_str;
}
else
{
size_t date_space = date_str.find_first_of(' ');
if (date_space == std::string::npos)
panic("Unable to find space char");
size_t date_comma = date_str.find_first_of(',');
int month;
if (string_begins_with(date_str, "Sept."))
month = 8;
else
{
for (month = 0; month < 12; month++)
{
if (string_begins_with(date_str, g_months[month]))
break;
if (string_begins_with(date_str, g_full_months[month]))
break;
}
if (month == 12)
panic("Failed finding month");
}
char buf[256];
int day, year;
if (date_comma == std::string::npos)
{
year = atoi(date_str.c_str() + date_space + 1);
if ((year < 1900) || (year > 2000))
panic("Invalid year");
sprintf_s(buf, "%u/%u", month + 1, year);
}
else
{
day = atoi(date_str.c_str() + date_space + 1);
if ((day < 1) || (day > 31))
panic("Invalid day");
year = atoi(date_str.c_str() + date_comma + 1);
if ((year < 1900) || (year > 2000))
panic("Invalid year");
sprintf_s(buf, "%u/%u/%u", month + 1, day, year);
}
json_date = buf;
}
return json_date;
}
bool convert_hall()
{
string_vec lines;
if (!read_text_file("ufo_evidence_hall.txt", lines, true, nullptr))
panic("Can't read file ufo_evidence_hall.txt");
uint32_t cur_line = 0;
uint32_t total_recs = 0;
FILE* pOut_file = ufopen("ufo_evidence_hall.json", "w");
if (!pOut_file)
panic("Can't open output file ufo_evidence_hall.json");
fputc(UTF8_BOM0, pOut_file);
fputc(UTF8_BOM1, pOut_file);
fputc(UTF8_BOM2, pOut_file);
fprintf(pOut_file, "{\n");
fprintf(pOut_file, "\"UFOEvidenceHall Timeline\" : [\n");
const uint32_t MAX_RECS = 2000;
while (cur_line < lines.size())
{
std::string rec(lines[cur_line]);
cur_line++;
string_trim(rec);
if (rec.empty())
panic("Encountered empty line");
size_t first_semi_ofs = rec.find_first_of(';');
if (first_semi_ofs == std::string::npos)
panic("Can't first first semi");
size_t second_semi_ofs = rec.find_first_of(';');
if (second_semi_ofs == std::string::npos)
panic("Can't find second semi");
while (cur_line < lines.size())
{
std::string l(lines[cur_line]);
string_trim(l);
if (!l.size())
panic("Encountered empty line");
size_t semi_ofs = l.find_first_of(';');
if (semi_ofs != std::string::npos)
break;
cur_line++;
if (rec.size() && rec.back() == '-')
rec += l;
else
{
rec += ' ';
rec += l;
}
}
if (rec.size())
{
//printf("%u. %s\n", total_recs + 1, rec.c_str());
std::string date_str(rec);
date_str.resize(first_semi_ofs);
string_trim(date_str);
rec.erase(0, first_semi_ofs + 1);
string_trim(rec);
second_semi_ofs = rec.find_first_of(';');
if (second_semi_ofs == std::string::npos)
panic("Can't find second semi");
std::string location_str(rec);
location_str.resize(second_semi_ofs);
string_trim(location_str);
if (location_str.size() && location_str.back() == '.')
location_str.pop_back();
rec.erase(0, second_semi_ofs + 1);
string_trim(rec);
//uprintf("Rec: %u\n", total_recs + 1);
//uprintf("Date: %s\n", date_str.c_str());
//uprintf("Location: %s\n", location_str.c_str());
//uprintf("Desc: %s\n", rec.c_str());
std::string json_date(convert_hall_to_json_date(date_str));
std::string json_end_date;
//uprintf("JSON Date: %s\n", date_str.c_str());
//uprintf("Date: %s\n", json_date.c_str());
if (string_begins_with(rec, "to "))
{
size_t dot_ofs = rec.find_first_of('.');
if (dot_ofs == std::string::npos)
panic("Invalid to date");
std::string to_date(rec);
to_date.resize(dot_ofs);
to_date.erase(0, 3);
string_trim(to_date);
rec.erase(0, dot_ofs + 1);
string_trim(rec);
json_end_date = convert_hall_to_json_date(to_date);
}
size_t k = rec.find_last_of('(');
if (k != std::string::npos)
{
if ((string_begins_with(rec.c_str() + k, "(Section ")) ||
(string_begins_with(rec.c_str() + k, "(section ")) ||
(string_begins_with(rec.c_str() + k, "(Sections ")) ||
(string_begins_with(rec.c_str() + k, "(sections ")))
{
rec.erase(k);
string_trim(rec);
}
}
#if USE_OPENAI
std::string prompt_str("Best categorize the following quoted text into one or more of these categories as a json array: sighting, landing, natural phenomenom, newspaper article, report or memo, official, abduction, medical, occupant or alien or creature encounter, or historical event: \"");
prompt_str += rec;
prompt_str += "\"";
std::string type_str;
bool status = invoke_openai(prompt_str, type_str);
if (!status)
panic("invoke_openai failed!\n");
for (size_t i = 0; i < type_str.size(); i++)
{
uint8_t c = type_str[i];
if ((c >= 32) && (c <= 127))
type_str[i] = (char)tolower(c);
}
#else
std::string type_str("[\"sighting\"]");
#endif
fprintf(pOut_file, "{\n");
fprintf(pOut_file, " \"date\" : \"%s\",\n", json_date.c_str());
if (json_end_date.size())
fprintf(pOut_file, " \"end_date\" : \"%s\",\n", json_end_date.c_str());
fprintf(pOut_file, " \"location\" : \"%s\",\n", escape_string_for_json(location_str).c_str());
fprintf(pOut_file, " \"desc\" : \"%s\",\n", escape_string_for_json(rec).c_str());
fprintf(pOut_file, " \"source_id\" : \"HallUFOE2_%u\",\n", total_recs);
fprintf(pOut_file, " \"source\" : \"HallUFOEvidence2\",\n");
fprintf(pOut_file, " \"ref\" : \"[The UFO Evidence by Richard H. Hall](https://www.amazon.com/UFO-Evidence-Richard-Hall/dp/0760706271)\",\n");
if (type_str.size())
fprintf(pOut_file, " \"type\" : %s\n", type_str.c_str());
fprintf(pOut_file, "}");
if (cur_line < lines.size())
fprintf(pOut_file, ",");
fprintf(pOut_file, "\n");
#if USE_OPENAI
fflush(pOut_file);
#endif
total_recs++;
if (total_recs == MAX_RECS)
break;
}
}
fprintf(pOut_file, "] }\n");
fclose(pOut_file);
return true;
}
bool convert_dolan(const char *pSrc_filename, const char *pDst_filename, const char *pSource, const char *pType, const char *pRef)
{
string_vec lines;
if (!read_text_file(pSrc_filename, lines, true, nullptr))
panic("Can't read file %s", pSrc_filename);
uint32_t cur_line = 0;
uint32_t total_recs = 0;
FILE* pOut_file = ufopen(pDst_filename, "w");
if (!pOut_file)
panic("Can't open output file %s", pDst_filename);
fputc(UTF8_BOM0, pOut_file);
fputc(UTF8_BOM1, pOut_file);
fputc(UTF8_BOM2, pOut_file);
fprintf(pOut_file, "{\n");
fprintf(pOut_file, "\" %s Timeline\" : [\n", pSource);
while (cur_line < lines.size())
{
std::string rec(lines[cur_line]);
cur_line++;
string_trim(rec);
if (rec.empty())
panic("Encountered empty line");
if (rec.size() < 54)
panic("Line too small");
std::string date_str(rec);
date_str = string_slice(date_str, 0, 16);
string_trim(date_str);
std::string location_str(string_slice(rec, 16, 36));
string_trim(location_str);
rec = string_slice(rec, 52);
string_trim(rec);
fprintf(pOut_file, "{\n");
fprintf(pOut_file, " \"date\" : \"%s\",\n", date_str.c_str());
fprintf(pOut_file, " \"location\" : \"%s\",\n", escape_string_for_json(location_str).c_str());
fprintf(pOut_file, " \"desc\" : \"%s\",\n", escape_string_for_json(rec).c_str());
if (pType)
fprintf(pOut_file, " \"type\" : \"%s\",\n", pType);
if (pRef)
fprintf(pOut_file, " \"ref\" : \"%s\",\n", escape_string_for_json(pRef).c_str());
fprintf(pOut_file, " \"source_id\" : \"%s_%u\",\n", pSource, total_recs);
fprintf(pOut_file, " \"source\" : \"%s\"\n", pSource);
fprintf(pOut_file, "}");
if (cur_line < lines.size())
fprintf(pOut_file, ",");
fprintf(pOut_file, "\n");
total_recs++;
}
fprintf(pOut_file, "] }\n");
fclose(pOut_file);
return true;
}
static const char* g_bad_urls[] =
{
"https://www.thelivingmoon.com/41pegasus/12insiders/McDonnell%5FDouglas%5FUFO%5FStudies.html",
"https://ufo.com.br/artigos/relatos---piloto-se-arrisca-em-prova-de-fogo-no-parana.html",
"http://boblazardebunked.com/investigating-s4-e115/",
"http://boblazardebunked.com/real-area-51-tech/",
"https://history.nebraska.gov/sites/history.nebraska.gov/files/doc/publications/NH1979UFOs.pdf",
"http://alienhunter.org/about/becoming-the-alien-hunter/",
"http://brumac.8k.com/ChristmasTree/",
"http://dl.lilibook.ir/2016/03/Other-Tongues-Other-Flesh.pdf",
"http://documents.irevues.inist.fr/bitstream/handle/2042/51980/meteo%5F1995%5F11%5F8.pdf",
"http://files.afu.se/Downloads/Magazines/United%20Kingdom/%20Merseyside%20UFO%20Bulletin/Merseyside%20UFO%20Bulletin%20-%20Vol%201%20No%201%20-%201968.pdf",
"http://ufologie.patrickgross.org/1954/19oct1954criteuil.htm",
"http://www.bluebookarchive.org/page.aspx?PageCode=NARA-PBB85-812",
"http://www.bluebookarchive.org/page.aspx?PageCode=NARA-PBB85-813",
"http://www.bluebookarchive.org/page.aspx?PageCode=NARA-PBB85-816",
"http://www.bluebookarchive.org/page.aspx?PageCode=NARA-PBB92-607",
"http://www.bluebookarchive.org/page.aspx?pagecode=NARA-PBB90-354",
"http://www.cheniere.org/",
"http://www.historycommons.org/entity.jsp?entity=james%5Fo%5F%5Fconnell",
"http://www.islandone.org/LEOBiblio/SETI1.HTM",
"http://www.nicap.org/france74.gif",
"http://www.phils.com.au/hollanda.htm",
"http://www.spellconsulting.com/reality/Norway%5FSpiral.html",
"http://www.wsmr-history.org/HallOfFame52.htm",
"http://www.zanoverallsongs.com/bio/",
"https://area51specialprojects.com/area51%5Ftimeline.html",
"https://area51specialprojects.com/u2%5Fpilots.html",
"https://cieloinsolito.com/?p=724",
"https://cieloinsolito.com/wp-content/uploads/2019/09/heretheyare.pdf",
"https://clubdeleonescuernavacaac.club/1965-1966-joaquin-diaz-gonzalez/",
"https://dpo.tothestarsacademy.com/blog/crada-faq",
"https://files.afu.se/Downloads/Magazines/Switzerland/Weltraumbote/Weltraumbote%20-%20No%2001%20-%201955-1956.pdf",
"https://files.afu.se/Downloads/UFO%20reports/Scandinavia/GR%20translations/46-02-21%20Finland%20meteor/1946-02-21%20Report%20Meteor%20over%20Finland%20and%20east%20Sweden.docx",
"https://mauriziobaiata.net/2011/11/10/intervista-ad-eugenio-siragusa-1919-2006-la-verita-non-si-vende-e-non-si-compra/",
"https://psi-encyclopedia.spr.ac.uk/articles/helene-smith",
"https://trinitysecret.com/the-other-lessons-of-trinity/",
"https://ufologie.patrickgross.org/1954/17oct1954cier.htm",
"https://ufologie.patrickgross.org/1954/1oct1954bry.htm",
"https://ufologie.patrickgross.org/1954/4oct1954poncey.htm",
"https://ufoscoop.com/richard-c-doty/",
"https://worldhistoryproject.org/1948/12/20/project-twinkle-established-to-monitor-green-fireball-sightings",
"https://www.abqjournal.com/obits/profiles/0722057profiles11-07-09.htm",
"https://www.alternatewars.com/BBOW/ABC%5FWeapons/US%5FNuclear%5FStockpile.htm",
"https://www.amberley-books.com/community-james-p-templeton",
"https://www.barnesandnoble.com/w/creative-realism-rolf-alexander/1132618455",
"https://www.charlotteobserver.com/latest-news/article125658529.html",
"https://www.hotspotsz.com/former-reporter-recounts-ufo-tale/",
"https://www.modrall.com/attorney/r-e-thompson/",
"https://www.mondenouveau.fr/presence-extraterrestre-ummo-une-imposture-ou-pas/",
"https://www.ourstrangeplanet.com/the-san-luis-valley/guest-editorials/mad-cow-disease-and-cattle-mutilations/",
"https://www.realclearscience.com/articles/2017/12/02/how%5F17th%5Fcentury%5Fdreamers%5Fplanned%5Fto%5Freach%5Fthe%5Fmoon%5F110476.html",
"https://www.rhun.co.nz/files/cia/cia1/44%5Fcia%5Fciaall2.pdf",
"https://www.spacelegalissues.com/the-french-anti-ufo-municipal-law-of-1954/",
"https://www.thevoicebeforethevoid.net/incidentcomplaint-report-by-commander-44-missile-security-squadron-ellsworth-air-force-base-south-dakota/",
"https://www.uapsg.com/2020/07/argentina-ufo-declassification.html",
"https://www.webcitation.org/6mx4huFGk",
"https://www.webcitation.org/6mx4rfU20",
"https://www.webcitation.org/6mx5Youbh",
"https://zazenlife.com/2011/12/18/project-mk-ultra-the-c-i-as-experiments-with-mind-control/"