Debian Codegraph @

reports/extract_set.li

raw
1 /*
2 * @progname extract_set.li
3 * @version 1.5
4 * @author Scott McGee ([email protected])
5 * @category
6 * @output function values
7 * @description
8
9 A library containing routines to allow extraction of a set of related persons
10 from a database.
11
12 The function extract_set() is passed a starting indi, and traverses selected
13 persons relatives until no selections are left. It returns an indi set of
14 the selected persons.
15
16 The do_info() function will return a string containing the name and birth/
17 death type info on the indi passed as a parameter.
18
19 @(#)extract_set.li 1.5 10/13/95
20 */
21
22 func extract_set(indi){
23 list(w) /* working list */
24 indiset(o) /* output set */
25 indiset(out) /* output set */
26 table(t) /* table of seen persons */
27 indiset(us) /* temporary set */
28
29 set(first, 1)
30 set(count, 1)
31 enqueue(w, indi)
32 while (indi, dequeue(w)) {
33 if (not(lookup(t, key(indi)))) {
34 insert(t, key(indi), 1)
35 if (askabout(indi)) {
36 addtoset(o, indi, count)
37 incr(count)
38 if (j, father(indi)) {
39 enqueue(w, j)
40 }
41 if (j, mother(indi)) {
42 enqueue(w, j)
43 }
44 families(indi, f, s, n) {
45 if(s) {
46 enqueue(w, s)
47 }
48 children(f, j, m) {
49 enqueue(w, j)
50 }
51 }
52 }
53 }
54 }
55 print("You selected ", d(lengthset(o)), " individuals.\n")
56 set(useout, 0)
57 set(msg, "Do you want all the ancestors of these people added to this set? (y or n) ")
58 getstr(answer, msg)
59 if(eqstr(lower(trim(answer, 1)), "y")) {
60 set(anc, ancestorset(o))
61 if(anc) {
62 print("Found ",
63 d(lengthset(difference(anc, intersect(anc, o)))),
64 " additional ancestors.\n")
65 set(out, union(o, anc))
66 set(rel, get_relatives(out))
67 if(rel){
68 print("Found ",
69 d(lengthset(difference(rel, intersect(rel, out)))),
70 " additional relatives.\n")
71 set(out, union(out, rel))
72 }
73 set(useout, 1)
74 }else{
75 print("no ancestors found\n")
76 }
77 }else{
78 set(msg, concat("Do you want all the ancestors of ", name(first_indi),
79 " added to this set? (y or n) "))
80 getstr(answer, msg)
81 if(eqstr(lower(trim(answer, 1)), "y")) {
82 set(m, 1)
83 addtoset(us, first_indi, m)
84 if(us) {
85 set(anc, ancestorset(us))
86 if(anc) {
87 print("Found ",
88 d(lengthset(difference(anc, intersect(anc, o)))),
89 " additional ancestors.\n")
90 set(out, union(o, anc))
91 set(rel, get_relatives(out))
92 if(rel){
93 print("Found ",
94 d(lengthset(difference(rel, intersect(rel, out)))),
95 " additional relatives.\n")
96 set(out, union(out, rel))
97 }
98 set(useout, 1)
99 }else{
100 print("no ancestors found\n")
101 }
102 }else{
103 print("error: nobody in 'us' set\n")
104 }
105 }
106 }
107 set(msg, "Do you want all the descendants of these people added to this set? (y or n) ")
108 getstr(answer, msg)
109 if(eqstr(lower(trim(answer, 1)), "y")) {
110 set(anc, descendantset(o))
111 if(anc) {
112 if(useout){
113 print("Found ",
114 d(lengthset(difference(anc, intersect(anc, out)))),
115 " additional descendants.\n")
116 set(out, union(out, anc))
117 }else{
118 print("Found ",
119 d(lengthset(difference(anc, intersect(anc, o)))),
120 " additional descendants.\n")
121 set(out, union(o, anc))
122 }
123 set(rel, get_relatives(union(o, anc)))
124 if(rel){
125 print("Found ",
126 d(lengthset(difference(rel, intersect(rel, out)))),
127 " additional relatives.\n")
128 set(out, union(out, rel))
129 }
130 }else{
131 print("no descendantss found\n")
132 }
133 }else{
134 set(msg, concat("Do you want all the descendants of ", name(first_indi),
135 " added to this set? (y or n) "))
136 getstr(answer, msg)
137 if(eqstr(lower(trim(answer, 1)), "y")) {
138 set(m, 1)
139 addtoset(us, first_indi, m)
140 if(us) {
141 set(anc, descendantset(us))
142 if(anc) {
143 if(useout){
144 print("Found ",
145 d(lengthset(difference(anc, intersect(anc, out)))),
146 " additional descendants.\n")
147 set(out, union(out, anc))
148 }else{
149 print("Found ",
150 d(lengthset(difference(anc, intersect(anc, o)))),
151 " additional descendants.\n")
152 set(out, union(o, anc))
153 }
154 set(rel, get_relatives(anc))
155 if(rel){
156 print("Found ",
157 d(lengthset(difference(rel, intersect(rel, out)))),
158 " additional relatives.\n")
159 set(out, union(out, rel))
160 }
161 }else{
162 print("no descendants found\n")
163 }
164 }else{
165 print("error: nobody in 'us' set\n")
166 }
167 }
168 if(not(useout)){
169 set(out, o)
170 }
171 }
172 return(out)
173 }
174
175 func askabout (indi) {
176 if(not(first)) {
177 call showinfo(indi)
178 set(s, concat("Do you want ", name(indi),
179 " in your output files? (y or n) "))
180 getstr(a, s)
181 return (eqstr(lower(trim(a, 1)), "y"))
182 }else{
183 set(first, 0)
184 return (1)
185 }
186 }
187
188 proc showinfo (indi) {
189 print(name(indi), do_info(indi), " (", key(indi), ")\n\n")
190 set(did_afn, afn(indi))
191 print("Father: ", name(father(indi)), do_info(father(indi)), "\n")
192 print("Mother: ", name(mother(indi)), do_info(mother(indi)), "\n\n\n\n\n\n\n")
193 set(f, 0) set(s, 0)
194 families(indi, fa, sp, n) {
195 if (eq(1, n)) {
196 set(f, fa)
197 set(s, sp)
198 }
199 }
200 print("Married: ", long(marriage(f)), "\n")
201 print("Spouse: ", name(s), do_info(s), "\n\n\n\n\n")
202 if(not(did_afn)){
203 print("\n")
204 }
205 }
206
207 func do_info(me){
208 if(not(me)){
209 return("")
210 }else{
211 set(out, " -")
212 if (evt, birth(me)) {
213 set(out, concat(out, " born ", short(evt)))
214 }
215 else {
216 if (evt, baptism(me)) {
217 set(out, concat(out, " baptised ", short(evt)))
218 }
219 else {
220 if (evt, bapt(me)) {
221 set(out, concat(out, " baptised ", short(evt)))
222 }
223 }
224 }
225 if (evt, death(me)) {
226 set(out, concat(out, " died ", short(evt)))
227 }
228 return(out)
229 }
230 }
231
232 func afn(indi){
233 if(indi){
234 fornodes(inode(indi), subnode){
235 if(eqstr(tag(subnode), "AFN")){
236 print("AFN ", value(subnode), "\n")
237 return(1)
238 }
239 }
240 }
241 return(0)
242 }
243
244 func get_relatives(in_set){
245 set(msg, "Do you want to add all relatives within a given link distance? (y or n) ")
246 getstr(answer, msg)
247 if(eqstr(lower(trim(answer, 1)), "y")) {
248
249 getint(n, "Please enter link distance.")
250
251 /* create set with all ancestors and descendents */
252
253 indiset(out_set)
254 indiset(t) /* temporary working set */
255
256 /* create set of additional, linked-to persons */
257
258 set(t, in_set)
259 while (gt(n, 0)) {
260 set(a, parentset(t))
261 set(b, childset(t))
262 set(c, spouseset(t))
263 set(t, union(t, union(a, union(b, c))))
264 set(n, sub(n, 1))
265 }
266 set(out_set, t)
267 return(out_set)
268 }
269 return(0)
270 }