private void AddSpouseRelationship(Relationship edge)
        {
            PersonRelationships sourcePersonRelationships, targetPeopleRelationships;

            if (!Families.TryGetValue(edge.Source, out sourcePersonRelationships))
            {
                sourcePersonRelationships = new PersonRelationships();
                Families.Add(edge.Source, sourcePersonRelationships);
            }
            if (!Families.TryGetValue(edge.Target, out targetPeopleRelationships))
            {
                targetPeopleRelationships = new PersonRelationships();
                Families.Add(edge.Target, targetPeopleRelationships);
            }

            if (targetPeopleRelationships.Spouse == null && sourcePersonRelationships.Spouse == null)
            {
                targetPeopleRelationships.AddSpouse(edge.Source);
                sourcePersonRelationships.AddSpouse(edge.Target);
            }
            else
            {
                throw new InvalidOperationException($"Cannot add spouse");
            }
        }
        private void AddParentRelationship(Relationship edge)
        {
            PersonRelationships sourcePersonRelationships, targetPeopleRelationships;

            if (!Families.TryGetValue(edge.Source, out sourcePersonRelationships))
            {
                sourcePersonRelationships = new PersonRelationships();
                Families.Add(edge.Source, sourcePersonRelationships);
            }
            if (!Families.TryGetValue(edge.Target, out targetPeopleRelationships))
            {
                targetPeopleRelationships = new PersonRelationships();
                Families.Add(edge.Target, targetPeopleRelationships);
            }

            if (targetPeopleRelationships.CanAddParent(edge.Source))
            {
                targetPeopleRelationships.AddParent(edge.Source);
                sourcePersonRelationships.AddEdge(edge);
            }
            else
            {
                throw new InvalidOperationException($"Cannot add parents to {edge.Target.Name}");
            }
        }
        public IEnumerable <Person> Spouse(Person person)
        {
            List <Person>       result = new List <Person>();
            PersonRelationships personRelationships = GetRelationship(person);

            if (personRelationships.Spouse != null)
            {
                result.Add(personRelationships.Spouse);
            }
            return(result);
        }
        public IEnumerable <Person> Children(Person person, Gender?gender = null)
        {
            List <Person>       result = new List <Person>();
            PersonRelationships personRelationships = GetRelationship(person);
            List <Person>       children            = personRelationships.Edges
                                                      .Where(m => m.RelationshipType == RelationshipType.Parent)
                                                      .Where(m => gender == null || m.Target.Gender == gender)
                                                      .Select(m => m.Target)
                                                      .ToList();

            result.AddRange(children);
            return(result);
        }
        public IEnumerable <Person> Parents(Person person, Gender?gender = null)
        {
            List <Person>       result = new List <Person>();
            PersonRelationships personRelationships = GetRelationship(person);

            if (personRelationships == null)
            {
                return(result);
            }
            IEnumerable <Person> parents = personRelationships.Parents
                                           .Where(m => gender == null || m.Gender == gender);

            result.AddRange(parents);
            return(result);
        }