File: extract_set.li

package info (click to toggle)
lifelines 3.0.50-2
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 11,140 kB
  • ctags: 6,517
  • sloc: ansic: 57,468; xml: 8,014; sh: 4,255; makefile: 848; yacc: 601; perl: 170; sed: 16
file content (270 lines) | stat: -rw-r--r-- 7,234 bytes parent folder | download | duplicates (5)
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
/* 
 * @progname       extract_set.li
 * @version        1.5
 * @author         Scott McGee (smcgee@microware.com)
 * @category       
 * @output         function values
 * @description    

A library containing routines to allow extraction of a set of related persons
from a database.

The function extract_set() is passed a starting indi, and traverses selected
persons relatives until no selections are left. It returns an indi set of 
the selected persons.

The do_info() function will return a string containing the name and birth/
death type info on the indi passed as a parameter.

@(#)extract_set.li	1.5 10/13/95
*/

func extract_set(indi){
  list(w)      /* working list */
  indiset(o)   /* output set */
  indiset(out) /* output set */
  table(t)     /* table of seen persons */
  indiset(us)  /* temporary set */

  set(first, 1)
  set(count, 1)
  enqueue(w, indi)
  while (indi, dequeue(w)) {
    if (not(lookup(t, key(indi)))) {
      insert(t, key(indi), 1)
      if (askabout(indi)) {
        addtoset(o, indi, count)
        incr(count)
        if (j, father(indi)) { 
          enqueue(w, j)
        }
        if (j, mother(indi)) { 
          enqueue(w, j)
        }
        families(indi, f, s, n) {
          if(s) {
            enqueue(w, s)
          }
          children(f, j, m) {
            enqueue(w, j)
          }
        }
      }
    }
  }
  print("You selected ", d(lengthset(o)), " individuals.\n")
  set(useout, 0)
  set(msg, "Do you want all the ancestors of these people added to this set? (y or n) ")
  getstr(answer, msg)
  if(eqstr(lower(trim(answer, 1)), "y")) {
    set(anc, ancestorset(o))
    if(anc) {
      print("Found ", 
            d(lengthset(difference(anc, intersect(anc, o)))),
            " additional ancestors.\n")
      set(out, union(o, anc))
      set(rel, get_relatives(out))
      if(rel){
        print("Found ",
              d(lengthset(difference(rel, intersect(rel, out)))),
              " additional relatives.\n")
        set(out, union(out, rel))
      }
      set(useout, 1)
    }else{
      print("no ancestors found\n")
    }
  }else{
    set(msg, concat("Do you want all the ancestors of ", name(first_indi), 
                    " added to this set? (y or n) "))
    getstr(answer, msg)
    if(eqstr(lower(trim(answer, 1)), "y")) {
      set(m, 1)
      addtoset(us, first_indi, m)
      if(us) {
        set(anc, ancestorset(us))
        if(anc) {
          print("Found ",
                d(lengthset(difference(anc, intersect(anc, o)))),
                " additional ancestors.\n")
          set(out, union(o, anc))
          set(rel, get_relatives(out))
          if(rel){
            print("Found ",
                  d(lengthset(difference(rel, intersect(rel, out)))),
                  " additional relatives.\n")
            set(out, union(out, rel))
          }
          set(useout, 1)
        }else{
          print("no ancestors found\n")
        }
      }else{
        print("error: nobody in 'us' set\n")
      }
    }
  }
  set(msg, "Do you want all the descendants of these people added to this set? (y or n) ")
  getstr(answer, msg)
  if(eqstr(lower(trim(answer, 1)), "y")) {
    set(anc, descendantset(o))
    if(anc) {
      if(useout){
        print("Found ", 
              d(lengthset(difference(anc, intersect(anc, out)))),
              " additional descendants.\n")
        set(out, union(out, anc))
      }else{
        print("Found ", 
              d(lengthset(difference(anc, intersect(anc, o)))),
              " additional descendants.\n")
        set(out, union(o, anc))
      }
      set(rel, get_relatives(union(o, anc)))
      if(rel){
        print("Found ",
              d(lengthset(difference(rel, intersect(rel, out)))),
              " additional relatives.\n")
        set(out, union(out, rel))
      }
    }else{
      print("no descendantss found\n")
    }
  }else{
    set(msg, concat("Do you want all the descendants of ", name(first_indi), 
                    " added to this set? (y or n) "))
    getstr(answer, msg)
    if(eqstr(lower(trim(answer, 1)), "y")) {
      set(m, 1)
      addtoset(us, first_indi, m)
      if(us) {
        set(anc, descendantset(us))
        if(anc) {
          if(useout){
            print("Found ", 
                  d(lengthset(difference(anc, intersect(anc, out)))),
                  " additional descendants.\n")
            set(out, union(out, anc))
          }else{
            print("Found ", 
                  d(lengthset(difference(anc, intersect(anc, o)))),
                  " additional descendants.\n")
            set(out, union(o, anc))
          }
          set(rel, get_relatives(anc))
          if(rel){
            print("Found ",
                  d(lengthset(difference(rel, intersect(rel, out)))),
                  " additional relatives.\n")
            set(out, union(out, rel))
          }
        }else{
          print("no descendants found\n")
        }
      }else{
        print("error: nobody in 'us' set\n")
      }
    }
    if(not(useout)){
      set(out, o)
    }
  }
  return(out)
}

func askabout (indi) {
  if(not(first)) {
    call showinfo(indi)
    set(s, concat("Do you want ", name(indi), 
                  " in your output files? (y or n) "))
    getstr(a, s)
    return (eqstr(lower(trim(a, 1)), "y"))
  }else{
    set(first, 0)
    return (1)
  }
}

proc showinfo (indi) {
  print(name(indi), do_info(indi), " (", key(indi), ")\n\n")
  set(did_afn, afn(indi))
  print("Father: ", name(father(indi)), do_info(father(indi)), "\n")
  print("Mother: ", name(mother(indi)), do_info(mother(indi)), "\n\n\n\n\n\n\n")
  set(f, 0) set(s, 0)
  families(indi, fa, sp, n) {
    if (eq(1, n)) {
      set(f, fa)
      set(s, sp)
    }
  }
  print("Married: ", long(marriage(f)), "\n")
  print("Spouse: ", name(s), do_info(s), "\n\n\n\n\n")
  if(not(did_afn)){
    print("\n")
  }
}

func do_info(me){
  if(not(me)){
    return("")
  }else{
    set(out, " -")
    if (evt, birth(me)) {
      set(out, concat(out, " born ", short(evt)))
    }
    else {
      if (evt, baptism(me)) {
        set(out, concat(out, " baptised ", short(evt)))
      }
      else {
        if (evt, bapt(me)) {
          set(out, concat(out, " baptised ", short(evt)))
        }
      }
    }
    if (evt, death(me)) {
      set(out, concat(out, " died ", short(evt)))
    }
    return(out)
  }
}

func afn(indi){
  if(indi){
    fornodes(inode(indi), subnode){
      if(eqstr(tag(subnode), "AFN")){
        print("AFN ", value(subnode), "\n")
        return(1)
      }
    }
  }
  return(0)
}

func get_relatives(in_set){
  set(msg, "Do you want to add all relatives within a given link distance? (y or n) ")
  getstr(answer, msg)
  if(eqstr(lower(trim(answer, 1)), "y")) {
  
    getint(n, "Please enter link distance.")

    /* create set with all ancestors and descendents */

    indiset(out_set)
    indiset(t)       /* temporary working set */

    /* create set of additional, linked-to persons */

    set(t, in_set)
    while (gt(n, 0)) {
      set(a, parentset(t))
      set(b, childset(t))
      set(c, spouseset(t))
      set(t, union(t, union(a, union(b, c))))
      set(n, sub(n, 1))
    }
    set(out_set, t)
    return(out_set)
  }
  return(0)
}