def _parse_individual(self, element: IndividualElement): ptr = element.get_pointer() name = Name(*element.get_name()) birth = None death = None sex = Sex.Unknown child_of_family = [] spouse_of_family = [] assert ptr not in self.individuals, (ptr, name) for sub_element in element.get_child_elements(): if self._has_tag(sub_element, Tag.Children): child_of_family.append(sub_element.get_value()) elif self._has_tag(sub_element, Tag.Spouses): spouse_of_family.append(sub_element.get_value()) elif self._has_tag(sub_element, Tag.BirthDate): birth = self._get_date_value(sub_element) elif self._has_tag(sub_element, Tag.DeathDate): death = self._get_date_value(sub_element) elif self._has_tag(sub_element, Tag.Sex): sex = Sex(sub_element.get_value()) self.individuals[ptr] = Individual(ptr, name, birth, death, sex) self.graph.add_node(ptr) for family in child_of_family: self.graph.add_edge(ptr, family, rel=Rel.Children.value) for family in spouse_of_family: self.graph.add_edge(ptr, family, rel=Rel.Spouses.value)
def new_child_element(self, tag, pointer="", value=""): """Creates and returns a new child element of this element :type tag: str :type pointer: str :type value: str :rtype: Element """ from gedcom.element.family import FamilyElement from gedcom.element.file import FileElement from gedcom.element.individual import IndividualElement from gedcom.element.object import ObjectElement # Differentiate between the type of the new child element if tag == gedcom.tags.GEDCOM_TAG_FAMILY: child_element = FamilyElement(self.get_level() + 1, pointer, tag, value, self.__crlf) elif tag == gedcom.tags.GEDCOM_TAG_FILE: child_element = FileElement(self.get_level() + 1, pointer, tag, value, self.__crlf) elif tag == gedcom.tags.GEDCOM_TAG_INDIVIDUAL: child_element = IndividualElement(self.get_level() + 1, pointer, tag, value, self.__crlf) elif tag == gedcom.tags.GEDCOM_TAG_OBJECT: child_element = ObjectElement(self.get_level() + 1, pointer, tag, value, self.__crlf) else: child_element = Element(self.get_level() + 1, pointer, tag, value, self.__crlf) self.add_child_element(child_element) return child_element
def parse_individual(element: IndividualElement, tree): child = Person() # get names from element names = list(get_names(element)) # save legal name # assumes first name in list is primary name legal_name = LegalName() parse_name_dict(names[0], legal_name) legal_name.tree = tree legal_name.save() child.legal_name = legal_name # save alternate names for name_dict in names[1:]: alternate_name = AlternateName() parse_name_dict(name_dict, alternate_name) alternate_name.person = child alternate_name.tree = tree alternate_name.save() child.gender = parse_gender(get_value(element, tags.GEDCOM_TAG_SEX)) # Is saving related models necessary, or will it cascade? birth_event_element = get_next_child_element(element, tags.GEDCOM_TAG_BIRTH) if birth_event_element: child.birth_date = parse_event_date(birth_event_element) child.birth_location = parse_event_location(birth_event_element) death_event_element = get_next_child_element(element, tags.GEDCOM_TAG_DEATH) if death_event_element: child.death_date = parse_event_date(death_event_element) child.death_location = parse_event_location(death_event_element) child.living = 'Dead' # living defaults to Unknown; change to living = has birth year and not has death year? child.tree = tree child.save() return element.get_pointer(), child