The Categories variables return all categories to which an image is assigned. If an image is assigned to multiple WHO categories, each category will become part of your output. There is no folding on levels or anything.
What you are trying to do is in fact really complex.
Alternatively, if I were to create WHAT categories for Family Line, is there a way to have the correct one automatically selected depending upon which WHO category was selected?
I don't even understand what yo mean by that.
Would a specialized genealogy software not be better suited for what you are trying to achieve?
They use graphs to represent families, not hierarchical categories. Different thing. Different technology.
IMatch is a DAM and it can do a lot.
But you seem to have a really unique use case (creating keywords from multiple spots of hierarchical keywords, on different levels, with folding, dupe removal, whatnot).
That's nothing a general DAM can do.
I most workflows you would just copy the fully-qualified keywords into your file and the
receiving application decides what to display and how.
Did you ask Flickr how they handle standard XMP hierarchical keywords and how you can filter the output they present?
I'm sure they have many options implemented for this in their software/site. Large company, big audience, lots of resources etc.
A custom IMatch app would be able to do what you want, because it would know how to use your category hierarchy to produce the keywords you want.
If you can program or you know somebody who can, this would probably take a day or two.