Debian Codegraph @

reports/igi-merge.ll

raw
1 /*
2 * @progname igi-merge.ll
3 * @version 4.0
4 * @author Eggert
5 * @category
6 * @output GEDCOM
7 * @description
8
9 This program helps you merge IGI data. IGI data consists of "families"
10 which are actually events. A real family may be documented by several
11 events in the IGI database, and thus be represented by several "families".
12 This program will help you to locate and merge those "families" back into
13 real families again.
14
15 igi-merge - a LifeLines IGI database merging program
16 by Jim Eggert ([email protected])
17 Version 1, 2 February 1993 Requires LifeLines 2.3.3 or later.
18 Version 2, 17 February 1993 bug fix, better suggestions
19 Version 3, 15 March 1993 more tunable suggestions,
20 added windup and restart
21 Version 4, 9 November 1994 Requires LifeLines 3.0.1 or later.
22 Minor windup bug fix.
23
24 The program locates candidate "families" to be merged by comparing the
25 soundex, double initials of husband to husband and wife to wife, and
26 event years. (Double initials are like "JO" for John. Any double
27 initials are allowed to match. Hence George Michael will match Mike,
28 and Betty Lou will match Lois Amelia.) If the comparison indicates a
29 possible match, the program prompts you for approval to merge. If you
30 answer with y or Yes or yazbotchit, the program will merge those two
31 families, otherwise it will not. The two husbands will be merged
32 together, as will the two wives.
33
34 The comparison is made following a strictness code entered at the
35 beginning of the program execution. The user is prompted for the
36 strictness level, which means more precisely:
37 1 soundexes and double initials must match
38 2 soundexes must match
39 3 soundexes and double initials must match, but empty soundexes match anything
40 4 soundexes must match, but empty soundexes match anything
41 5 double intitials must match
42 6 nothing needs match
43 I usually use the strictness in a multiple-pass method: First I run
44 igi-merge with strictness 1. I import the resulting GEDCOM file into
45 an empty LL database, and run igi-merge with strictness 2 or 3. And so
46 on until I am satisfied.
47
48 In any case, the event years are always used for declaring matches.
49 Two families match only if their event years are within forty years of
50 each other. If the events are marriage events, however, they must be
51 within five years of each other. If a family has more than one event
52 associated with it (for partially merged IGI data, for example), any
53 marriage event has precedence.
54
55 After families are merged, the program puts the children in birth order,
56 and attempts to locate children who are really the same. It prompts you
57 for approval to merge any two children born or christened in the same year.
58
59 Any merged individuals will retain one copy of each name variant and of
60 each variant sex. (There shouldn't be any of the latter!) Other data,
61 such as birth and marriage events etc, are simply copied; duplicate
62 information may therefore be retained after the merge. You are urged
63 to edit the resulting file to look for and possibly delete such
64 duplication.
65
66 The resulting data is written to a GEDCOM file. You may read this back
67 into a LifeLines database if you wish.
68
69 If you run out of time (because, for example, you are merging ten
70 thousand families), you can invoke windup. If you answer the family
71 merge question with w (or windup, or Whatever), the program will act as
72 if you answered all the remaining queries negatively.
73
74 If you want to be really fancy, before you issue the w command, write
75 down the families that you are being queried about. Then later you
76 can read the resulting GEDCOM file into a new LifeLines database, and
77 start up igi-merge again. When asked what comparison strictness to
78 use, answer with zero. You will be prompted for the two families to
79 restart the program at. Make sure that you enter the top family
80 first, otherwise it won't work. The program will then resume your
81 previous igi-merge session where you had left off.
82
83 With windup and restart, you don't really have to have a single block
84 of time to be able to merge a large dataset.
85
86 The program does some rudimentary checking to see if the source data
87 really is IGI-like. If not, it complains, but keeps on running
88 anyway. Because it only writes a GEDCOM file, this program can't
89 corrupt your database, so don't worry.
90
91 The user interface depends on the size of the LifeLines screen,
92 I have marked the sensitive lines with a commented #
93 */
94
95 global(famged)
96 global(gedsex)
97 global(names)
98 global(ptable)
99 global(event_year)
100 global(event_string)
101 global(event_type) /* 1=birth, 2=baptism, 3=marriage,
102 and in the future 4=death, 5=burial */
103 global(compare_level)
104 global(windup)
105
106 func get_yesno(prompt) {
107 set(yes,0)
108 set(windup,0)
109 getstrmsg(yesno,prompt)
110 if (gt(strlen(yesno),0)) {
111 if (not(strcmp(upper(trim(yesno,1)),"Y"))) { set(yes,1) }
112 if (not(strcmp(upper(trim(yesno,1)),"W"))) { set(windup,1) }
113 }
114 return(yes)
115 }
116
117 /* Note that marriage events have priority! */
118 proc get_event(family) {
119 set(event_year,0)
120 if (e,marriage(family)) {
121 extractdate(e,day,month,event_year)
122 set(event_string,"m. ")
123 set(event_type,3)
124 }
125 else {
126 children(family,child,cnum) {
127 if (eq(cnum,1)) {
128 if (e,birth(child)) {
129 set(event_string,concat(name(child)," b. "))
130 extractdate(e,day,month,event_year)
131 set(event_type,1)
132 }
133 elsif (e,baptism(child)) {
134 set(event_string,concat(name(child)," c. "))
135 extractdate(e,day,month,event_year)
136 set(event_type,2)
137 }
138 }
139 }
140 }
141 if (not(event_year)) {
142 /* print("Event year not found.\n") */
143 set(event_string,concat(event_string,"date unknown"))
144 }
145 else {
146 set(event_string,concat(event_string,d(event_year)))
147 }
148 if (p,place(e)) {
149 set(event_string,concat(event_string," "))
150 set(event_string,concat(event_string,p))
151 }
152 set(event_string,save(trim(event_string,73))) /*#*/
153 }
154
155 proc write_ged_indi(person,newperson,ftag,famkey) {
156 if (not(person)) { break() }
157 if (lookup(ptable,key(person))) {
158 print("Database doesn't look like IGI data.\n")
159 print(" - ", key(person), " ", name(person), "\n")
160 }
161 insert(ptable,save(key(person)),famkey)
162 set(n,inode(person))
163 if (newperson) {
164 while (dequeue(names)) { "" }
165 set(gedsex,"X")
166 }
167 traverse(n,node,level) {
168 if (level) {
169 set(t,tag(node))
170 if (and(strcmp(t,"FAMS"),strcmp(t,"FAMC"))) {
171 set(write_line,1)
172 if (not(strcmp(t,"NAME"))) {
173 if (newperson) {
174 enqueue(names,save(value(node)))
175 }
176 else {
177 set(thisname,save(value(node)))
178 forlist(names,prevname,pnum) {
179 if (not(strcmp(thisname,prevname))) {
180 set(write_line,0)
181 }
182 }
183 if (write_line) { enqueue(names,thisname) }
184 }
185 }
186 if (not(strcmp(t,"SEX"))) {
187 if (newperson) { set(gedsex,save(value(node))) }
188 elsif (not(strcmp(gedsex,value(node)))) {
189 set(write_line,0)
190 }
191 else { set(gedsex,save(value(node))) }
192 }
193 if (write_line) { d(level) " " t " " value(node) "\n" }
194 }
195 elsif (newperson) {
196 d(level) " " t " @" famkey "@\n"
197 }
198 }
199 elsif (newperson) { "0 " xref(node) " INDI\n" }
200 }
201 if (newperson) {
202 enqueue(famged,ftag)
203 enqueue(famged,save(key(person)))
204 enqueue(famged,"@\n")
205 }
206 }
207
208 proc write_ged_fam(fam) {
209 if (not(fam)) { break() }
210 set(n,fnode(fam))
211 traverse(n,node,level) {
212 if (not(level)) { continue() }
213 if (eq(level,1)) { set(levelonetag,save(tag(node))) }
214 if (and(and(strcmp(levelonetag,"HUSB"),
215 strcmp(levelonetag,"WIFE")),
216 strcmp(levelonetag,"CHIL"))) {
217 enqueue(famged,save(d(level)))
218 enqueue(famged," ")
219 enqueue(famged,save(tag(node)))
220 enqueue(famged," ")
221 enqueue(famged,save(value(node)))
222 enqueue(famged,"\n")
223 }
224 }
225 }
226
227 func compare(aint,bint) {
228 if (lt(aint,bint)) { return(neg(1)) }
229 elsif (gt(aint,bint)) { return(1) }
230 else { return(0) }
231 }
232
233 proc bubblesort(alist,ilist)
234 {
235 /* print("bubblesorting list of length ") print(d(length(alist))) */
236 /* print(" entries.\n") */
237 while (dequeue(ilist)) { "" }
238 forlist(alist,ael,index) { enqueue(ilist,index) }
239 while (gt(index,0)) {
240 set(bubblepos,index)
241 set(bubbleindex,getel(ilist,bubblepos))
242 set(abubble,getel(alist,bubbleindex))
243 set(movedup,0)
244 set(comparison,neg(1))
245 while (and(gt(bubblepos,1),lt(comparison,0))) {
246 set(bubbleupindex,getel(ilist,sub(bubblepos,1)))
247 set(bubbleup,getel(alist,bubbleupindex))
248 set(comparison,compare(abubble,bubbleup))
249 if (lt(comparison,0)) {
250 setel(ilist,bubblepos,bubbleupindex)
251 decr(bubblepos)
252 set(movedup,1)
253 }
254 }
255 if (eq(movedup,0)) {
256 set(comparison,1)
257 while(and(lt(bubblepos,length(alist)),gt(comparison,0))) {
258 set(bubbledownindex,getel(ilist,add(bubblepos,1)))
259 set(bubbledown,getel(alist,bubbledownindex))
260 set(comparison,compare(abubble,bubbledown))
261 if (gt(comparison,0)) {
262 setel(ilist,bubblepos,bubbledownindex)
263 incr(bubblepos)
264 }
265 }
266 }
267 setel(ilist,bubblepos,bubbleindex)
268 if (eq(movedup,0)) { decr(index) }
269 }
270 }
271
272 func sound_compare(asound,bsound) {
273 if (and(strlen(asound),strlen(bsound))) {
274 return(strcmp(asound,bsound))
275 }
276 elsif (ge(compare_level,3)) { return(0) }
277 else { return(1) }
278 }
279
280 func initial_compare(namelist1,namelist2,len2) {
281 forlist(namelist2,this2,n) {
282 if (ge(n,len2)) { break() }
283 set(init2,save(upper(trim(this2,2))))
284 forlist(namelist1,init1,m) {
285 if (not(strcmp(init1,init2))) {
286 return(0)
287 }
288 }
289 }
290 return(1)
291 }
292
293 global(hsound)
294 global(wsound)
295 global(hnamelist)
296 global(wnamelist)
297 global(hexists)
298 global(wexists)
299
300 func names_compare(fam2) {
301 list(namelist)
302 set(hsound2,"")
303 if (and(hexists,husband(fam2))) {
304 if (lt(compare_level,5)) {
305 set(hsound2,save(soundex(husband(fam2))))
306 if (not(strcmp(hsound2,"Z999"))) { set(hsound2,"") }
307 if (s,sound_compare(hsound,hsound2)) { return(s) }
308 }
309 if (mod(compare_level,2)) {
310 extractnames(inode(husband(fam2)),namelist,n1,n2)
311 if (s,initial_compare(hnamelist,namelist,n2)) { return(s) }
312 }
313 }
314 elsif (le(compare_level,2)) { return(1) }
315 if (and(wexists,wife(fam2))) {
316 if (lt(compare_level,5)) {
317 set(wsound2,save(soundex(wife(fam2))))
318 if (not(and(strcmp(wsound2,"Z999"),
319 strcmp(wsound2,hsound2)))) { set(wsound2,"") }
320 if (s,sound_compare(wsound,wsound2)) { return(s) }
321 }
322 if (mod(compare_level,2)) {
323 extractnames(inode(wife(fam2)),namelist,n1,n2)
324 if (n,initial_compare(wnamelist,namelist,n2)) { return(n) }
325 }
326 }
327 elsif (le(compare_level,2)) { return(1) }
328 return(0)
329 }
330
331 proc main() {
332 list(husbands)
333 list(wives)
334 list(childlist)
335 list(childyear)
336 list(childindex)
337 list(childevent)
338 list(names)
339 list(hnamelist)
340 list(wnamelist)
341 table(ftable)
342 table(ptable)
343 list(famged)
344
345 set(compare_level,neg(1))
346 while(or(lt(compare_level,0),gt(compare_level,6))) {
347 getintmsg(compare_level,
348 "Enter comparison strictness (0=restart,1=very...6=not at all)")
349 if (eq(compare_level,0)) {
350 set(restart,1)
351 print("Select first family to restart from")
352 getfam(rfam)
353 set(rfkey,key(rfam))
354 print("Select second family to restart from")
355 getfam(rfam)
356 set(rfkey2,key(rfam))
357 getintmsg(compare_level,
358 "Enter real comparison strictness (1=very...6=not at all)")
359 }
360 }
361 set(num_merged,0)
362 forfam(fam,fnum) { "" }
363 print("Trying to merge ", d(fnum), " families.\n")
364 set(next_fnum,0)
365 set(windup,0)
366 forfam(fam,fnum) {
367 if (ge(fnum,next_fnum)) {
368 print(d(fnum), " ")
369 incr(next_fnum)
370 }
371 set(famkey,save(key(fam)))
372 if (lookup(ftable,famkey)) { continue() }
373 insert(ftable,famkey,1)
374 enqueue(famged,"0 @")
375 enqueue(famged,famkey)
376 enqueue(famged,"@ FAM\n")
377 if (h,husband(fam)) {
378 enqueue(husbands,save(key(h)))
379 set(hexists,1)
380 }
381 else { set(hexists,0) }
382 if (w,wife(fam)) {
383 enqueue(wives,save(key(w)))
384 set(wexists,1)
385 }
386 else { set(wexists,0) }
387 children(fam,child,cnum) {
388 enqueue(childlist,save(key(child)))
389 }
390 call write_ged_fam(fam)
391 if (and(not(windup),
392 or(and(restart,not(strcmp(key(fam),rfkey))),
393 and(not(restart),or(h,w))))) {
394 set(hname,save(name(h)))
395 set(wname,save(name(w)))
396 set(hsound,save(soundex(h)))
397 if (not(strcmp(hsound,"Z999"))) { set(hsound,"") }
398 set(wsound,save(soundex(w)))
399 if (not(and(strcmp(hsound,wsound),
400 strcmp(wsound,"Z999")))) { set(wsound,"") }
401 if (mod(compare_level,2)) {
402 if (h) {
403 extractnames(inode(h),hnamelist,n1,n2)
404 forlist(hnamelist,this,n) {
405 setel(hnamelist,n,save(upper(trim(this,2))))
406 }
407 while (le(n2,n1)) {
408 set(junk,pop(hnamelist))
409 incr(n2)
410 }
411 }
412 if (w) {
413 extractnames(inode(w),wnamelist,n1,n2)
414 forlist(wnamelist,this,n) {
415 setel(wnamelist,n,save(upper(trim(this,2))))
416 }
417 while (le(n2,n1)) {
418 set(junk,pop(wnamelist))
419 incr(n2)
420 }
421 }
422 }
423 call get_event(fam)
424 set(year,event_year)
425 set(fevent_type,event_type)
426 set(fevent,event_string)
427 forfam(fam2,fnum2) {
428 if (or(windup,
429 and(or(not(restart),strcmp(key(fam2),rfkey2)),
430 or(restart,le(fnum2,fnum))))) {
431 continue() }
432 set(restart,0)
433 set(famkey2,save(key(fam2)))
434 if (not(lookup(ftable,famkey2))) {
435 if (not(names_compare(fam2))) {
436 call get_event(fam2)
437 set(ydiff,sub(event_year,year))
438 if (lt(ydiff,0)) { set(ydiff,neg(ydiff)) }
439 /* if soundexes are identical, and event years are close, ask user */
440 set(askit,0)
441 if (and(eq(event_type,3),eq(event_type,3))) {
442 if (lt(ydiff,5)) { set(askit,1) }
443 }
444 elsif (lt(ydiff,40)) { set(askit,1) }
445 if (askit) {
446 print("\n\n\n\n", hname, "\n", wname, "\n") /*#*/
447 print(fevent, "\n\n\n\n\n\n\n\n\n") /*#*/
448 print(name(husband(fam2)), "\n")
449 print(name(wife(fam2)), "\n")
450 print(event_string)
451 set(yes,get_yesno("Merge these families? (y/n/w)"))
452 print("\n")
453 if (yes) {
454 incr(num_merged)
455 insert(ftable,famkey2,2)
456 children(fam2,child,cnum) {
457 enqueue(childlist,save(key(child)))
458 }
459 call write_ged_fam(fam2)
460 enqueue(husbands,save(key(husband(fam2))))
461 enqueue(wives,save(key(wife(fam2))))
462 }
463 elsif (windup) {
464 print("Winding up...")
465 }
466 }
467 }
468 }
469 }
470 }
471 /* write out the parents */
472 if (hkey,dequeue(husbands)) {
473 set(h,indi(hkey))
474 call write_ged_indi(h,1,"1 HUSB @",famkey)
475 while (hkey,dequeue(husbands)) {
476 set(h,indi(hkey))
477 call write_ged_indi(h,0,"",famkey)
478 }
479 }
480 if (wkey,dequeue(wives)) {
481 set(w,indi(wkey))
482 call write_ged_indi(w,1,"1 WIFE @",famkey)
483 while (wkey,dequeue(wives)) {
484 set(w,indi(wkey))
485 call write_ged_indi(w,0,"",famkey)
486 }
487 }
488 /* collect children birthyears */
489 forlist(childlist,childkey,cnum) {
490 set(child,indi(childkey))
491 if (e,birth(child)) {
492 extractdate(e,day,month,year)
493 enqueue(childevent," b. ")
494 }
495 elsif (e,baptism(child)) {
496 extractdate(e,day,month,year)
497 enqueue(childevent," c. ")
498 }
499 enqueue(childyear,year)
500 }
501 /* sort by birthyear */
502 call bubblesort(childyear,childindex)
503 set(prev_year,neg(1))
504 /* merge and write children */
505 forlist(childindex,index,inum) {
506 set(child,indi(getel(childlist,index)))
507 set(merge_child,0)
508 if (and(not(windup),
509 eq(getel(childyear,index),prev_year))) {
510 set(merge_child,1)
511 print("\n\n\n\n\n") /*#*/
512 print(prev_name, prev_event, d(prev_year))
513 print("\n\n\n\n\n\n\n\n\n\n\n") /*#*/
514 }
515 set(prev_name,save(name(child)))
516 set(prev_event,getel(childevent,index))
517 set(prev_year,getel(childyear,index))
518 if (merge_child) {
519 print(prev_name, prev_event, d(prev_year))
520 set(yes,get_yesno("Merge these children? (y/n)"))
521 print("\n")
522 if (yes) { set(merge_child,2) }
523 }
524 if (eq(merge_child,2)) {
525 call write_ged_indi(child,0,"",famkey)
526 }
527 else {
528 call write_ged_indi(child,1,"1 CHIL @",famkey)
529 }
530 }
531 /* empty out children data */
532 while (not(empty(childlist))) {
533 set(e,dequeue(childlist))
534 set(e,dequeue(childevent))
535 set(e,dequeue(childyear))
536 set(e,dequeue(childindex))
537 }
538 /* write out the family part of the GEDCOM file */
539 while(not(empty(famged))) { dequeue(famged) }
540 }
541 "0 TRLR\n"
542 print("\nMerged ", d(num_merged), " of ", d(fnum), " families.\n")
543 }