| 1 |
/* |
| 2 |
* @progname relation.ll |
| 3 |
* @version 5.0 |
| 4 |
* @author Eggert |
| 5 |
* @category |
| 6 |
* @output Text |
| 7 |
* @description |
| 8 |
|
| 9 |
This program calculates the relationship between individuals in a |
| 10 |
database. It does so in three modes. Mode 1 just does one pair of |
| 11 |
individuals and then exits. Mode 2 does any number of pairs with a |
| 12 |
common "from" person. Mode 3 does all pairs with a common "from" |
| 13 |
person. In general, mode 1 is fastest for simple relationships, but |
| 14 |
if you want one complicated relationship, you may as well do them all. |
| 15 |
|
| 16 |
relation - a LifeLines relation computing program |
| 17 |
by Jim Eggert ([email protected]) |
| 18 |
Version 1, 21 November 1992 |
| 19 |
Version 2, 23 November 1992 (completely revamped) |
| 20 |
Version 3, (changed format slightly, modified code somewhat) |
| 21 |
Version 4, 6 July 1993 (added English language) |
| 22 |
Version 5, 6 September 1993 (generified language) |
| 23 |
|
| 24 |
Each computed relation is composed of the minimal combination of |
| 25 |
parent (fm), sibling (bsS), child (zdC), and spouse (hw) giving the |
| 26 |
relational path from the "from" person to the "to" person. Each |
| 27 |
incremental relationship (or hop) is coded as follows, with the |
| 28 |
capital letters denoting a person of unknown gender: |
| 29 |
father f |
| 30 |
mother m |
| 31 |
parent P (not used) |
| 32 |
brother b |
| 33 |
sister s |
| 34 |
sibling S |
| 35 |
son z (sorry) |
| 36 |
daughtr d |
| 37 |
child C |
| 38 |
husband h |
| 39 |
wife w |
| 40 |
spouse O (sorry again, but usually not possible) |
| 41 |
|
| 42 |
The report gives the steps required to go from the first person to |
| 43 |
the second person. Thus the printout |
| 44 |
I93 John JONES fmshwz I95 Fred SMITH |
| 45 |
means that John Jones' father's mother's sister's husband's wife's son |
| 46 |
is Fred Smith. Notice in this case, the sister's husband's wife is |
| 47 |
not the same as the sister, and the husband's wife's son is not the |
| 48 |
same as the husband's son. Thus in more understandable English, John |
| 49 |
Jones' paternal grandmother's sister's husband's wife's son from |
| 50 |
another marriage is Fred Smith. |
| 51 |
|
| 52 |
The program will do a trivial parsing of the path string. You can |
| 53 |
change the language_table to have it print in different languages, as |
| 54 |
long as the word order is unchanged. |
| 55 |
|
| 56 |
If there is no relation, the program says so. That at least should be |
| 57 |
easy to explain. Mode 3 only prints out those individuals who are |
| 58 |
related to the "from" individual. |
| 59 |
*/ |
| 60 |
|
| 61 |
global(plist) |
| 62 |
global(hlist) |
| 63 |
global(mark) |
| 64 |
global(keys) |
| 65 |
global(found) |
| 66 |
global(do_names) |
| 67 |
global(language) |
| 68 |
global(language_table) |
| 69 |
global(token) |
| 70 |
global(untoken) |
| 71 |
|
| 72 |
proc include(person,hops,keypath,path,pathend) |
| 73 |
{ |
| 74 |
if (and(person,eq(found,0))) { |
| 75 |
set(pkey,key(person)) |
| 76 |
if (entry,lookup(mark,pkey)) { |
| 77 |
if (eq(strcmp(entry,"is not related to"),0)) { |
| 78 |
set(found,1) |
| 79 |
list(plist) |
| 80 |
list(hlist) |
| 81 |
insert(mark,pkey,concat(path,pathend)) |
| 82 |
insert(keys,pkey,concat(concat(keypath,"@"),pkey)) |
| 83 |
} |
| 84 |
} |
| 85 |
else { |
| 86 |
enqueue(plist,pkey) |
| 87 |
enqueue(hlist,hops) |
| 88 |
insert(mark,pkey,concat(path,pathend)) |
| 89 |
insert(keys,pkey,concat(concat(keypath,"@"),pkey)) |
| 90 |
} |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
proc get_token(input) { |
| 95 |
/* Parse a token from the input string. |
| 96 |
Tokens are separated by one or more "@"s. |
| 97 |
Set global parameter token to the first token string. |
| 98 |
Set global parameter untoken to the rest of the string after first token. |
| 99 |
*/ |
| 100 |
/* strip leading @s */ |
| 101 |
set(untoken,input) |
| 102 |
set(first_delim,index(untoken,"@",1)) |
| 103 |
while (eq(first_delim,1)) { |
| 104 |
set(untoken,substring(untoken,2,strlen(untoken))) |
| 105 |
set(first_delim,index(untoken,"@",1)) |
| 106 |
} |
| 107 |
/* get token and untoken */ |
| 108 |
if (not(first_delim)) { |
| 109 |
set(token,untoken) |
| 110 |
set(untoken,"") |
| 111 |
} |
| 112 |
else { |
| 113 |
set(token,substring(untoken,1,sub(first_delim,1))) |
| 114 |
set(untoken, |
| 115 |
substring(untoken,add(first_delim,1),strlen(untoken))) |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
proc parse_relation(relation,keypath) { |
| 120 |
if (not(language)) { |
| 121 |
" " relation |
| 122 |
if (do_names) { |
| 123 |
set(untoken,keypath) |
| 124 |
call get_token(untoken) |
| 125 |
while(strlen(untoken)) { |
| 126 |
call get_token(untoken) |
| 127 |
" " token " " name(indi(token)) |
| 128 |
} |
| 129 |
} |
| 130 |
" " |
| 131 |
} |
| 132 |
else { |
| 133 |
set(charcounter,1) |
| 134 |
set(untoken,keypath) |
| 135 |
call get_token(untoken) |
| 136 |
while (le(charcounter,strlen(relation))) { |
| 137 |
lookup(language_table,substring(relation,charcounter,charcounter)) |
| 138 |
if (do_names) { |
| 139 |
call get_token(untoken) |
| 140 |
" " token " " name(indi(token)) |
| 141 |
} |
| 142 |
set(charcounter,add(charcounter,1)) |
| 143 |
} |
| 144 |
" is " |
| 145 |
} |
| 146 |
} |
| 147 |
|
| 148 |
proc main () |
| 149 |
{ |
| 150 |
table(mark) |
| 151 |
table(keys) |
| 152 |
list(plist) |
| 153 |
list(hlist) |
| 154 |
|
| 155 |
table(language_table) |
| 156 |
insert(language_table,"f","'s father") |
| 157 |
insert(language_table,"m","'s mother") |
| 158 |
insert(language_table,"P","'s parent") |
| 159 |
insert(language_table,"b","'s brother") |
| 160 |
insert(language_table,"s","'s sister") |
| 161 |
insert(language_table,"S","'s sibling") |
| 162 |
insert(language_table,"z","'s son") |
| 163 |
insert(language_table,"d","'s daughter") |
| 164 |
insert(language_table,"C","'s child") |
| 165 |
insert(language_table,"h","'s husband") |
| 166 |
insert(language_table,"w","'s wife") |
| 167 |
insert(language_table,"O","'s spouse") |
| 168 |
|
| 169 |
getindimsg(from_person, |
| 170 |
"Enter person to compute relation from:") |
| 171 |
set(from_key,key(from_person)) |
| 172 |
set(hopcount,0) |
| 173 |
set(prev_hopcount,neg(1)) |
| 174 |
set(found,0) |
| 175 |
call include(from_person,hopcount,"","","") |
| 176 |
getintmsg(mode,"Enter 1 for a single relation, 2 for several, 3 for all:") |
| 177 |
getintmsg(language, |
| 178 |
"Enter 0 for brief, 1 for English-language relationships:") |
| 179 |
getintmsg(do_names, |
| 180 |
"Enter 0 to omit, 1 to output names of all intervening relatives:") |
| 181 |
if (eq(mode,1)) { |
| 182 |
getindimsg(to_person, |
| 183 |
"Enter one person to compute relation to:") |
| 184 |
set(to_key,key(to_person)) |
| 185 |
if (strcmp(from_key,to_key)) { |
| 186 |
insert(mark,to_key,"is not related to") |
| 187 |
} |
| 188 |
else { |
| 189 |
list(plist) |
| 190 |
list(hlist) |
| 191 |
} |
| 192 |
} |
| 193 |
while (pkey,dequeue(plist)) { |
| 194 |
set(person,indi(pkey)) |
| 195 |
set(hopcount,dequeue(hlist)) |
| 196 |
set(path,lookup(mark,pkey)) |
| 197 |
set(keypath,lookup(keys,pkey)) |
| 198 |
if (ne(hopcount,prev_hopcount)) { |
| 199 |
print(".") |
| 200 |
set(prev_hopcount,hopcount) |
| 201 |
} |
| 202 |
set(hopcount,add(hopcount,1)) |
| 203 |
call include(father(person),hopcount,keypath,path,"f") |
| 204 |
call include(mother(person),hopcount,keypath,path,"m") |
| 205 |
children(parents(person),child,cnum) { |
| 206 |
if (male(child)) { set(pathend,"b") } |
| 207 |
elsif (female(child)) { set(pathend,"s") } |
| 208 |
else { set(pathend,"S") } |
| 209 |
call include(child,hopcount,keypath,path,pathend) |
| 210 |
} |
| 211 |
families(person,fam,spouse,pnum) { |
| 212 |
if (male(spouse)) { set(pathend,"h") } |
| 213 |
elsif (female(spouse)) { set(pathend,"w") } |
| 214 |
else { set(pathend,"O") } |
| 215 |
call include(spouse,hopcount,keypath,path,pathend) |
| 216 |
children(fam,child,cnum) { |
| 217 |
if (male(child)) { set(pathend,"z") } |
| 218 |
elsif (female(child)) { set(pathend,"d") } |
| 219 |
else { set(pathend,"C") } |
| 220 |
call include(child,hopcount,keypath,path,pathend) |
| 221 |
} |
| 222 |
} |
| 223 |
} |
| 224 |
if (eq(mode,1)) { |
| 225 |
from_key " " name(indi(from_key)) |
| 226 |
call parse_relation(lookup(mark,to_key),lookup(keys,to_key)) |
| 227 |
to_key " " name(indi(to_key)) "\n" |
| 228 |
} |
| 229 |
if (eq(mode,2)) { |
| 230 |
set(want_another,1) |
| 231 |
while (want_another) { |
| 232 |
getindimsg(to_person,"Enter person to compute relation to:") |
| 233 |
set(to_key,key(to_person)) |
| 234 |
from_key " " name(indi(from_key)) |
| 235 |
if (path,lookup(mark,to_key)) { |
| 236 |
call parse_relation(path,lookup(keys,to_key)) |
| 237 |
} |
| 238 |
else { " is not related to " } |
| 239 |
to_key " " name(to_person) "\n" |
| 240 |
getintmsg(want_another, |
| 241 |
"Enter 0 if done, 1 if you want another to person:") |
| 242 |
} |
| 243 |
} |
| 244 |
if (eq(mode,3)) { |
| 245 |
from_key " " name(indi(from_key)) " --->\n" |
| 246 |
forindi(to_person,num) { |
| 247 |
set(to_key,key(to_person)) |
| 248 |
if (path,lookup(mark,to_key)) { |
| 249 |
call parse_relation(path,lookup(keys,to_key)) |
| 250 |
to_key " " name(to_person) "\n" |
| 251 |
} |
| 252 |
} |
| 253 |
} |
| 254 |
} |
| 255 |
|