Debian Codegraph @

reports/partition.ll

raw
1 /*
2 * @progname partition.ll
3 * @version 11
4 * @author Eggert
5 * @category
6 * @output GEDCOM
7 * @description
8
9 This program partitions individuals in a database into disjoint
10 partitions. A partition is composed of people related by one or more
11 multiples of the following relations: parent, sibling, child, spouse.
12 There is no known relationship between people in different partitions.
13
14
15 partition - a LifeLines database partitioning program
16 by Jim Eggert ([email protected])
17 Version 1, 19 November 1992 (unreleased)
18 Version 2, 20 November 1992 (completely revamped using queues)
19 Version 3, 23 November 1992 (added GEDCOM TRLR line,
20 changed to key-based queues)
21 Version 4, 1 December 1992 (slight code updates)
22 Version 5, 9 January 1993 (added birth and death dates to full)
23 Version 6, 30 January 1993 (now writes multiple GEDCOM output files)
24 This version requires LifeLines v2.3.3 or later.
25 Version 7, 21 September1994 (can partition about selected person)
26 Version 8, 31 March 1995 (allow non-traditional families)
27 Version 9, 23 February 1999 (changed to depth-first algorithm)
28 Version 10, 24 September 2001(use cumcount, not forindi loop variable)
29 Version 11, 7 November 2005 (add header, switch to use gengedcomstrong
30 change output gedcom files to end in .ged
31 changes by Stephen A. Dum)
32
33 This program partitions individuals in a database into disjoint
34 partitions. A partition is composed of people related by one or more
35 multiples of the following relations: parent, sibling, child, spouse.
36 There is no known relationship between people in different partitions.
37 You may select a particular person about whom to construct the largest
38 partition, or you may do the whole database. The partitions are
39 written to the report in overview form or full form with the
40 partitions delimited by a
41 ------------------------------------------------------------
42 long line, or in GEDCOM form to separate partition files. The
43 overview form merely lists the number of people in each partition by
44 the number of hops from the first person found in the partition.
45 (They are found in order of the forindi iterator.) The full form
46 lists each person in each partition, giving the number of hops, key,
47 name, and birth and death dates (if known). The GEDCOM form writes
48 the partitions in GEDCOM format. You will be prompted for a root
49 filename for the GEDCOM files; individual GEDCOM filenames will be of
50 the form root_filename.p, where p is the partition number.
51
52 Each allowed relationship (parent, sibling, child, spouse) is called a
53 hop, and the degree of relationship is called the hop count. While
54 the program is processing, it displays to the screen the number of the
55 partition it is working on followed by a colon, then the cumulative
56 number of individuals in that partition for each hop increment.
57
58 */
59
60 global(include_new)
61 global(plist)
62 global(hlist)
63 global(mark)
64 global(pset)
65 global(pcount)
66
67 global(hopcount)
68 global(prev_hopcount)
69 global(prev_pcount)
70 global(setcount)
71 global(cumcount)
72
73 proc include(person,hops,setcount,report_type)
74 {
75 if (person) {
76 set(pkey,key(person))
77 if (lookup(mark,pkey)) {
78 set(include_new,0)
79 }
80 else {
81 set(pkey2,save(pkey))
82 enqueue(plist,pkey2)
83 enqueue(hlist,hops)
84 insert(mark,pkey2,setcount)
85 addtoset(pset,person,hops)
86 incr(pcount)
87 if (not(mod(pcount,100))) {
88 print(d(pcount),"/",d(length(plist))," ")
89 }
90 set(include_new,1)
91 if (eq(report_type,1)) {
92 d(setcount) col(6) d(hops)
93 col(11) pkey col(18) name(person)
94 col(48) stddate(birth(person))
95 col(62) stddate(death(person)) "\n"
96 }
97 }
98 }
99 }
100
101 proc main ()
102 {
103 table(mark)
104 list(plist)
105 list(hlist)
106 indiset(pset)
107
108 dayformat(0)
109 monthformat(4)
110 dateformat(0)
111
112 getindimsg(person_root,
113 "Enter a person for just one partition, nothing for all partitions:")
114 getintmsg(report_type,
115 "Enter 0 for overview, 1 for full, 2 for GEDCOM report:")
116 if (eq(report_type,2)) {
117 if (person_root) {
118 set(prompt,"Enter filename for GEDCOM partition:")
119 }
120 else {
121 set(prompt,"Enter root filename for GEDCOM partitions:")
122 }
123 getstrmsg(gedcom_root,prompt)
124 set(gedcom_root,save(concat(gedcom_root,"_")))
125 }
126 else { set(gedcom_root,0) }
127
128 set(setcount,1)
129 set(pcount,0)
130 set(hopcount,1)
131 set(prev_hopcount,neg(1))
132 set(prev_pcount,0)
133 set(cumcount,0)
134 if (eq(report_type,1)) {
135 "Ptn Hops Key Person"
136 col(48) "Birthdate" col(62) "Deathdate\n"
137 }
138 if (person_root) {
139 call do_one_partition(person_root,report_type,gedcom_root)
140 }
141 else {
142 forindi(person,num) {
143 call do_one_partition(person,report_type,gedcom_root)
144 }
145 if (le(report_type,1)) {
146 "Entire database contains " d(cumcount) " individual"
147 if (gt(cumcount,1)) { "s" }
148 " in " d(sub(setcount,1)) " partition"
149 if (gt(setcount,2)) { "s" }
150 ".\n"
151 }
152 }
153 }
154
155 proc do_one_partition(person,report_type,gedcom_root) {
156 list(hopcountlist)
157 call include(person,hopcount,setcount,report_type)
158 if (include_new) {
159 if (eq(report_type,0)) {
160 "Ptn Hops Individuals\n"
161 }
162 print("\n",d(setcount),": ")
163 while (pkey,pop(plist)) {
164 set(person,indi(pkey))
165 set(hopcount,pop(hlist))
166 /* print(pkey,d(hopcount)) */
167 setel(hopcountlist,hopcount,add(1,getel(hopcountlist,hopcount)))
168 incr(hopcount)
169
170 /* Look for family links and follow them to the families,
171 then look for links to other individuals in those families.
172 Nonstandard linking tags may be added here.
173 */
174
175 fornodes(inode(person),node) {
176 set(t,tag(node))
177 if (or(not(strcmp(t,"FAMS")),
178 not(strcmp(t,"FAMC")))) {
179 set(family,fam(value(node)))
180 fornodes(fnode(family),node2) {
181 set(t,tag(node2))
182 if (or(not(strcmp(t,"HUSB")),
183 not(strcmp(t,"WIFE")),
184 not(strcmp(t,"CHIL")))) {
185 call include(indi(value(node2)),
186 hopcount,setcount,report_type)
187 }
188 }
189 }
190 }
191 }
192 if (eq(report_type,0)) {
193 forlist(hopcountlist,counter,hops) {
194 print(d(setcount),d(counter), " ")
195 }
196 }
197 if (le(report_type,1)) {
198 "Partition " d(setcount) " contains " d(pcount)
199 " individual"
200 if (gt(pcount,1)) { "s" }
201 ".\n"
202 "------------------------------------------------------------\n"
203 }
204 if (eq(report_type,2)) {
205 newfile(concat(gedcom_root,d(setcount),".ged"),0)
206 /* output a gedcom header */
207 "0 HEAD\n"
208 "1 SOUR Lifelines\n"
209 "2 VERS " version() "\n"
210 "1 DEST ANY\n"
211 "1 DATE " date(gettoday()) "\n"
212 "1 SUBM\n"
213 "1 GEDC\n"
214 "2 VERS 5.5\n"
215 "2 FORM LINEAGE-LINKED\n"
216 "1 CHAR ASCII\n"
217 gengedcomstrong(pset)
218 "0 TRLR\n"
219 }
220 set(cumcount,add(cumcount,pcount))
221 indiset(pset)
222 set(pcount,0)
223 set(hopcount,0)
224 set(prev_hopcount,neg(1))
225 set(prev_pcount,pcount)
226 incr(setcount)
227 }
228 }