Megarus & KinshipCode
KinshipCode KinshipCode
Hey Megarus, have you ever noticed how a kinship chart can be turned into a graph—nodes for people, edges for relationships? I love spotting those hidden patterns in matrilineal lines, and I suspect there’s a neat algorithm to flag forbidden cousin marriages. Want to dig into that together?
Megarus Megarus
Yeah, that’s basically a graph problem. Map each person to a node, each parent-child link to an edge, then run a search to see if two nodes share a close ancestor. I can script that in a few lines; just let me know the data format.
KinshipCode KinshipCode
Sounds great, thank you! I’m planning to store the family data in a CSV where each line is “PersonID,ParentID,Relation”. For example, “123,45,parent” or “123,67,mother”. Then I’ll load that into a small graph structure in Python. If you have any tips on how to keep the IDs consistent or how to annotate cousin levels, let me know—happy to hear your thoughts!
Megarus Megarus
IDs should be plain ints or UUIDs; just keep a single source of truth so you don’t end up with duplicate IDs for the same person. For cousin levels, build a helper that walks up the ancestor tree and records depth; two people are n‑th cousins if their lowest common ancestor is n+1 generations back for each of them. Then flag any that fall below your forbidden threshold. Python’s dicts and recursion will do the trick—no need for a full library.
KinshipCode KinshipCode
Nice! I’ll start pulling the CSV into a dictionary mapping each ID to its parents, then recursively climb up the tree to find the lowest common ancestor. I’ll keep an eye on the depth counter so I can calculate cousin levels right away. Let me know if you’d like me to sketch the pseudocode—happy to share the field notes!
Megarus Megarus
Sure, a quick sketch: load CSV into dict `parents[child]=[parent1,parent2]`. Write a recursive `ancestors(id, depth=0)` that yields tuples `(node, depth)` up to the root. Then for two IDs, build ancestor sets, find intersection, pick the one with max depth as LCA. Cousin level = max(depth1,depth2) - LCA_depth. That’s all you need to flag anything below your limit. Let me know if you hit a snag.
KinshipCode KinshipCode
That’s exactly the kind of neat, tidy algorithm I love—thanks for the quick sketch! I’ll start writing the `ancestors` helper and test it on a small sample. If anything weird pops up, I’ll ping you. Oh, and I’ll jot down a little note in both English and Spanish so my field notebook stays bilingual—always good to keep those language layers intact!
Megarus Megarus
Sounds solid—go test the helper, then ping if any edge cases trip you up. Keep the bilingual notes; just remember to tag which language you’re using so you don’t mix up the variable names. Happy coding!
KinshipCode KinshipCode
Got it, I’ll start with a small test set right away. I’ll keep the English and Spanish comments in separate blocks and label each one, so nothing gets mixed up. If I run into any quirks—like a looping ancestor or a missing parent—I’ll ping you with a quick note. Thanks for the guidance!
Megarus Megarus
Good plan—just add a guard against loops, like a visited set in `ancestors`. And if a parent ID isn’t in the dict, treat that node as a root. Those two checks should cover most quirks. Let me know how the test set behaves.