Пример #1
0
 def test_place_should_sync_references(self):
     place = Place('1', [LocalizedName('one')])
     sut = IdentifiableEvent('1', Event.Type.BIRTH)
     sut.place = place
     self.assertEquals(place, sut.place)
     self.assertIn(sut, place.events)
     sut.place = None
     self.assertEquals(None, sut.place)
     self.assertNotIn(sut, place.events)
Пример #2
0
 def test_place_should_sync_references(self):
     place = Place('1', [PlaceName('one')])
     sut = IdentifiableEvent('1', Birth())
     sut.place = place
     self.assertEquals(place, sut.place)
     self.assertIn(sut, place.events)
     sut.place = None
     self.assertEquals(None, sut.place)
     self.assertNotIn(sut, place.events)
Пример #3
0
    def test_clean_should_not_clean_event_with_presences_with_people(
            self) -> None:
        ancestry = Ancestry()

        source = IdentifiableSource('S1', 'The Source')
        ancestry.sources[source.id] = source

        citation = IdentifiableCitation('C1', source)
        ancestry.citations[citation.id] = citation

        file = File('F1', __file__)
        ancestry.files[file.id] = file

        place = Place('P0', [PlaceName('The Place')])
        ancestry.places[place.id] = place

        person = Person('P0')

        event = IdentifiableEvent('E0', Birth())
        event.citations.append(citation)
        event.files.append(file)
        event.place = place
        ancestry.events[event.id] = event

        Presence(person, Subject(), event)

        clean(ancestry)

        self.assertEqual(event, ancestry.events[event.id])
        self.assertIn(event, place.events)
        self.assertEqual(place, ancestry.places[place.id])
        self.assertIn(event, citation.facts)
        self.assertEqual(citation, ancestry.citations[citation.id])
        self.assertIn(event, file.resources)
        self.assertEqual(file, ancestry.files[file.id])
Пример #4
0
def _load_event(loader: _Loader, element: ElementTree.Element):
    handle = element.get('handle')
    event_id = element.get('id')
    gramps_type = _xpath1(element, './ns:type')

    try:
        event_type = _EVENT_TYPE_MAP[gramps_type.text]
    except KeyError:
        event_type = UnknownEventType()
        logging.getLogger().warning(
            'Betty is unfamiliar with Gramps event "%s"\'s type of "%s". The event was imported, but its type was set to "%s".' % (event_id, gramps_type.text, event_type.label))

    event = IdentifiableEvent(event_id, event_type)

    event.date = _load_date(element)

    # Load the event place.
    place_handle_element = _xpath1(element, './ns:place')
    if place_handle_element is not None:
        event.place = loader._places[place_handle_element.get('hlink')]

    # Load the description.
    description_element = _xpath1(element, './ns:description')
    if description_element is not None:
        event.description = description_element.text

    _load_objref(loader, event, element)
    _load_citationref(loader, event, element)
    _load_attribute_privacy(event, element, 'attribute')
    loader._events[handle] = event
Пример #5
0
    def test_clean_should_clean_event(self) -> None:
        ancestry = Ancestry()

        source = IdentifiableSource('S1', 'The Source')
        ancestry.sources[source.id] = source

        citation = IdentifiableCitation('C1', source)
        ancestry.citations[citation.id] = citation

        file = File('F1', __file__)
        ancestry.files[file.id] = file

        place = Place('P0', [PlaceName('The Place')])
        ancestry.places[place.id] = place

        event = IdentifiableEvent('E0', Birth())
        event.citations.append(citation)
        event.files.append(file)
        event.place = place
        ancestry.events[event.id] = event

        clean(ancestry)

        self.assertNotIn(event.id, ancestry.events)
        self.assertIsNone(event.place)
        self.assertNotIn(event, place.events)
        self.assertNotIn(place.id, ancestry.places)
        self.assertNotIn(event, citation.facts)
        self.assertNotIn(citation.id, ancestry.citations)
        self.assertNotIn(event, file.resources)
        self.assertNotIn(file.id, ancestry.files)
Пример #6
0
def _parse_event(ancestry: _IntermediateAncestry, element: Element):
    handle = str(_xpath1(element, './@handle'))
    event_id = _xpath1(element, './@id')
    gramps_type = _xpath1(element, './ns:type')

    try:
        event_type = _EVENT_TYPE_MAP[gramps_type.text]
    except KeyError:
        event_type = UnknownEventType()
        logging.getLogger().warning(
            'Betty is unfamiliar with Gramps event "%s"\'s type of "%s". The event was imported, but its type was set to "%s".'
            % (event_id, gramps_type.text, event_type.label))

    event = IdentifiableEvent(event_id, event_type)

    event.date = _parse_date(element)

    # Parse the event place.
    place_handle = _xpath1(element, './ns:place/@hlink')
    if place_handle:
        event.place = ancestry.places[place_handle]

    # Parse the description.
    description_element = _xpath1(element, './ns:description')
    if description_element is not None:
        event.description = description_element.text

    _parse_objref(ancestry, event, element)
    _parse_citationref(ancestry, event, element)
    _parse_attribute_privacy(event, element, 'attribute')
    ancestry.events[handle] = event
Пример #7
0
 def test_event_should_encode_full(self):
     event = IdentifiableEvent('the_event', Birth())
     event.date = DateRange(Date(2000, 1, 1), Date(2019, 12, 31))
     event.place = Place('the_place', [PlaceName('The Place')])
     Presence(Person('the_person'), Subject(), event)
     event.citations.append(
         IdentifiableCitation('the_citation', Source('The Source')))
     expected = {
         '$schema': '/schema.json#/definitions/event',
         '@context': {
             'place': 'https://schema.org/location',
         },
         '@type': 'https://schema.org/Event',
         'id': 'the_event',
         'type': 'birth',
         'presences': [
             {
                 '@context': {
                     'person': 'https://schema.org/actor',
                 },
                 'role': 'subject',
                 'person': '/en/person/the_person/index.json',
             },
         ],
         'citations': [
             '/en/citation/the_citation/index.json',
         ],
         'date': {
             'start': {
                 'year': 2000,
                 'month': 1,
                 'day': 1,
             },
             'end': {
                 'year': 2019,
                 'month': 12,
                 'day': 31,
             },
         },
         'place': '/en/place/the_place/index.json',
         'links': [
             {
                 'url': '/en/event/the_event/index.json',
                 'relationship': 'canonical',
                 'mediaType': 'application/json',
             },
             {
                 'url': '/nl/event/the_event/index.json',
                 'relationship': 'alternate',
                 'locale': 'nl-NL',
             },
             {
                 'url': '/en/event/the_event/index.html',
                 'relationship': 'alternate',
                 'mediaType': 'text/html',
             },
         ],
     }
     self.assert_encodes(expected, event, 'event')
Пример #8
0
 def test_event_should_encode_full(self):
     event = IdentifiableEvent('the_event', Event.Type.BIRTH)
     event.date = DateRange(Date(2000, 1, 1), Date(2019, 12, 31))
     event.place = Place('the_place', [LocalizedName('The Place')])
     Presence(Person('the_person'), Presence.Role.SUBJECT, event)
     event.citations.append(
         Citation('the_citation', Source('the_source', 'The Source')))
     expected = {
         '$schema':
         '/schema.json#/definitions/event',
         '@context': {
             'place': 'https://schema.org/location',
         },
         '@type':
         'https://schema.org/Event',
         'id':
         'the_event',
         'type':
         Event.Type.BIRTH.value,
         'presences': [
             {
                 '@context': {
                     'person': 'https://schema.org/actor',
                 },
                 'role': Presence.Role.SUBJECT.value,
                 'person': '/person/the_person/index.json',
             },
         ],
         'citations': [
             '/citation/the_citation/index.json',
         ],
         'date': {
             'start': {
                 'year': 2000,
                 'month': 1,
                 'day': 1,
             },
             'end': {
                 'year': 2019,
                 'month': 12,
                 'day': 31,
             },
         },
         'place':
         '/place/the_place/index.json',
     }
     self.assert_encodes(expected, event, 'event')
Пример #9
0
def _parse_event(ancestry: _IntermediateAncestry, element: Element):
    handle = str(_xpath1(element, './@handle'))
    gramps_type = _xpath1(element, './ns:type')

    event = IdentifiableEvent(_xpath1(element, './@id'), _EVENT_TYPE_MAP[gramps_type.text])

    event.date = _parse_date(element)

    # Parse the event place.
    place_handle = _xpath1(element, './ns:place/@hlink')
    if place_handle:
        event.place = ancestry.places[place_handle]

    # Parse the description.
    description_element = _xpath1(element, './ns:description')
    if description_element is not None:
        event.description = description_element.text

    _parse_objref(ancestry, event, element)
    _parse_citationref(ancestry, event, element)
    _parse_attribute_privacy(event, element)
    ancestry.events[handle] = event
Пример #10
0
    async def load(self) -> None:
        amsterdam = Place('betty-demo-amsterdam', [PlaceName('Amsterdam')])
        amsterdam.coordinates = Point(52.366667, 4.9)
        amsterdam.links.add(Link('https://nl.wikipedia.org/wiki/Amsterdam'))
        self._ancestry.places[amsterdam.id] = amsterdam

        ilpendam = Place('betty-demo-ilpendam', [PlaceName('Ilpendam')])
        ilpendam.coordinates = Point(52.465556, 4.951111)
        ilpendam.links.add(Link('https://nl.wikipedia.org/wiki/Ilpendam'))
        self._ancestry.places[ilpendam.id] = ilpendam

        personal_accounts = IdentifiableSource('betty-demo-personal-accounts',
                                               'Personal accounts')
        self._ancestry.sources[personal_accounts.id] = personal_accounts

        cite_first_person_account = IdentifiableCitation(
            'betty-demo-first-person-account', personal_accounts)
        self._ancestry.citations[
            cite_first_person_account.id] = cite_first_person_account

        bevolkingsregister_amsterdam = IdentifiableSource(
            'betty-demo-bevolkingsregister-amsterdam',
            'Bevolkingsregister Amsterdam')
        bevolkingsregister_amsterdam.author = 'Gemeente Amsterdam'
        bevolkingsregister_amsterdam.publisher = 'Gemeente Amsterdam'
        self._ancestry.sources[
            bevolkingsregister_amsterdam.id] = bevolkingsregister_amsterdam

        david_marinus_lankester = Person('betty-demo-david-marinus-lankester')
        david_marinus_lankester.names.append(
            PersonName('David Marinus', 'Lankester'))
        self._ancestry.people[
            david_marinus_lankester.id] = david_marinus_lankester

        geertruida_van_ling = Person('betty-demo-geertruida-van-ling')
        geertruida_van_ling.names.append(PersonName('Geertruida', 'Van Ling'))
        self._ancestry.people[geertruida_van_ling.id] = geertruida_van_ling

        marriage_of_dirk_jacobus_lankester_and_jannigje_palsen = IdentifiableEvent(
            'betty-demo-marriage-of-dirk-jacobus-lankester-and-jannigje-palsen',
            Marriage(), Date(1922, 7, 4))
        marriage_of_dirk_jacobus_lankester_and_jannigje_palsen.place = ilpendam
        self._ancestry.events[
            marriage_of_dirk_jacobus_lankester_and_jannigje_palsen.
            id] = marriage_of_dirk_jacobus_lankester_and_jannigje_palsen

        birth_of_dirk_jacobus_lankester = IdentifiableEvent(
            'betty-demo-birth-of-dirk-jacobus-lankester', Birth(),
            Date(1897, 8, 25))
        birth_of_dirk_jacobus_lankester.place = amsterdam
        self._ancestry.events[birth_of_dirk_jacobus_lankester.
                              id] = birth_of_dirk_jacobus_lankester

        death_of_dirk_jacobus_lankester = IdentifiableEvent(
            'betty-demo-death-of-dirk-jacobus-lankester', Death(),
            Date(1986, 8, 18))
        death_of_dirk_jacobus_lankester.place = amsterdam
        self._ancestry.events[death_of_dirk_jacobus_lankester.
                              id] = death_of_dirk_jacobus_lankester

        dirk_jacobus_lankester = Person('betty-demo-dirk-jacobus-lankester')
        dirk_jacobus_lankester.names.append(
            PersonName('Dirk Jacobus', 'Lankester'))
        Presence(dirk_jacobus_lankester, Subject(),
                 birth_of_dirk_jacobus_lankester)
        Presence(dirk_jacobus_lankester, Subject(),
                 death_of_dirk_jacobus_lankester)
        Presence(dirk_jacobus_lankester, Subject(),
                 marriage_of_dirk_jacobus_lankester_and_jannigje_palsen)
        dirk_jacobus_lankester.parents.append(david_marinus_lankester,
                                              geertruida_van_ling)
        self._ancestry.people[
            dirk_jacobus_lankester.id] = dirk_jacobus_lankester

        birth_of_marinus_david_lankester = IdentifiableEvent(
            'betty-demo-birth-of-marinus-david', Birth(),
            DateRange(Date(1874, 1, 15),
                      Date(1874, 3, 21),
                      start_is_boundary=True,
                      end_is_boundary=True))
        birth_of_marinus_david_lankester.place = amsterdam
        self._ancestry.events[birth_of_marinus_david_lankester.
                              id] = birth_of_marinus_david_lankester

        death_of_marinus_david_lankester = IdentifiableEvent(
            'betty-demo-death-of-marinus-david', Death(), Date(1971))
        death_of_marinus_david_lankester.place = amsterdam
        self._ancestry.events[death_of_marinus_david_lankester.
                              id] = death_of_marinus_david_lankester

        marinus_david_lankester = Person('betty-demo-marinus-david-lankester')
        marinus_david_lankester.names.append(
            PersonName('Marinus David', 'Lankester'))
        Presence(marinus_david_lankester, Subject(),
                 birth_of_marinus_david_lankester)
        Presence(marinus_david_lankester, Subject(),
                 death_of_marinus_david_lankester)
        marinus_david_lankester.parents.append(david_marinus_lankester,
                                               geertruida_van_ling)
        self._ancestry.people[
            marinus_david_lankester.id] = marinus_david_lankester

        birth_of_jacoba_gesina_lankester = IdentifiableEvent(
            'betty-demo-birth-of-jacoba-gesina', Birth(), Date(1900, 3, 14))
        birth_of_jacoba_gesina_lankester.place = amsterdam
        self._ancestry.events[birth_of_jacoba_gesina_lankester.
                              id] = birth_of_jacoba_gesina_lankester

        jacoba_gesina_lankester = Person('betty-demo-jacoba-gesina-lankester')
        jacoba_gesina_lankester.names.append(
            PersonName('Jacoba Gesina', 'Lankester'))
        Presence(jacoba_gesina_lankester, Subject(),
                 birth_of_jacoba_gesina_lankester)
        jacoba_gesina_lankester.parents.append(david_marinus_lankester,
                                               geertruida_van_ling)
        self._ancestry.people[
            jacoba_gesina_lankester.id] = jacoba_gesina_lankester

        jannigje_palsen = Person('betty-demo-jannigje-palsen')
        jannigje_palsen.names.append(PersonName('Jannigje', 'Palsen'))
        Presence(jannigje_palsen, Subject(),
                 marriage_of_dirk_jacobus_lankester_and_jannigje_palsen)
        self._ancestry.people[jannigje_palsen.id] = jannigje_palsen

        marriage_of_johan_de_boer_and_liberta_lankester = IdentifiableEvent(
            'betty-demo-marriage-of-johan-de-boer-and-liberta-lankester',
            Marriage(), Date(1953, 6, 19))
        marriage_of_johan_de_boer_and_liberta_lankester.place = amsterdam
        self._ancestry.events[
            marriage_of_johan_de_boer_and_liberta_lankester.
            id] = marriage_of_johan_de_boer_and_liberta_lankester

        cite_birth_of_liberta_lankester_from_bevolkingsregister_amsterdam = IdentifiableCitation(
            'betty-demo-birth-of-liberta-lankester-from-bevolkingsregister-amsterdam',
            bevolkingsregister_amsterdam)
        cite_birth_of_liberta_lankester_from_bevolkingsregister_amsterdam.location = 'Amsterdam'
        self._ancestry.citations[
            cite_birth_of_liberta_lankester_from_bevolkingsregister_amsterdam.
            id] = cite_birth_of_liberta_lankester_from_bevolkingsregister_amsterdam

        birth_of_liberta_lankester = IdentifiableEvent(
            'betty-demo-birth-of-liberta-lankester', Birth(),
            Date(1929, 12, 22))
        birth_of_liberta_lankester.place = amsterdam
        birth_of_liberta_lankester.citations.append(
            cite_birth_of_liberta_lankester_from_bevolkingsregister_amsterdam)
        self._ancestry.events[
            birth_of_liberta_lankester.id] = birth_of_liberta_lankester

        death_of_liberta_lankester = IdentifiableEvent(
            'betty-demo-death-of-liberta-lankester', Death(),
            Date(2015, 1, 17))
        death_of_liberta_lankester.place = amsterdam
        death_of_liberta_lankester.citations.append(cite_first_person_account)
        self._ancestry.events[
            death_of_liberta_lankester.id] = death_of_liberta_lankester

        liberta_lankester = Person('betty-demo-liberta-lankester')
        liberta_lankester.names.append(PersonName('Liberta', 'Lankester'))
        liberta_lankester.names.append(PersonName('Betty'))
        Presence(liberta_lankester, Subject(), birth_of_liberta_lankester)
        Presence(liberta_lankester, Subject(), death_of_liberta_lankester)
        Presence(liberta_lankester, Subject(),
                 marriage_of_johan_de_boer_and_liberta_lankester)
        liberta_lankester.parents.append(dirk_jacobus_lankester,
                                         jannigje_palsen)
        self._ancestry.people[liberta_lankester.id] = liberta_lankester

        birth_of_johan_de_boer = IdentifiableEvent(
            'betty-demo-birth-of-johan-de-boer', Birth(), Date(1930, 6, 20))
        birth_of_johan_de_boer.place = amsterdam
        self._ancestry.events[
            birth_of_johan_de_boer.id] = birth_of_johan_de_boer

        death_of_johan_de_boer = IdentifiableEvent(
            'betty-demo-death-of-johan-de-boer', Death(), Date(1999, 3, 10))
        death_of_johan_de_boer.place = amsterdam
        death_of_johan_de_boer.citations.append(cite_first_person_account)
        self._ancestry.events[
            death_of_johan_de_boer.id] = death_of_johan_de_boer

        johan_de_boer = Person('betty-demo-johan-de-boer')
        johan_de_boer.names.append(PersonName('Johan', 'De Boer'))
        johan_de_boer.names.append(PersonName('Hans'))
        Presence(johan_de_boer, Subject(), birth_of_johan_de_boer)
        Presence(johan_de_boer, Subject(), death_of_johan_de_boer)
        Presence(johan_de_boer, Subject(),
                 marriage_of_johan_de_boer_and_liberta_lankester)
        self._ancestry.people[johan_de_boer.id] = johan_de_boer

        parent_of_bart_feenstra_child_of_liberta_lankester = Person(
            'betty-demo-parent-of-bart-feenstra-child-of-liberta-lankester')
        parent_of_bart_feenstra_child_of_liberta_lankester.names.append(
            PersonName('Bart\'s parent'))
        parent_of_bart_feenstra_child_of_liberta_lankester.parents.append(
            johan_de_boer, liberta_lankester)
        self._ancestry.people[
            parent_of_bart_feenstra_child_of_liberta_lankester.
            id] = parent_of_bart_feenstra_child_of_liberta_lankester

        bart_feenstra = Person('betty-demo-bart-feenstra')
        bart_feenstra.names.append(PersonName('Bart', 'Feenstra'))
        bart_feenstra.parents.append(
            parent_of_bart_feenstra_child_of_liberta_lankester)
        self._ancestry.people[bart_feenstra.id] = bart_feenstra