Esempio n. 1
0
    def populate_destruction_events(self,
                                    data: dict,
                                    note,
                                    *,
                                    type_map,
                                    location=None):
        destruction_types_map = type_map
        hmo = get_crom_object(data)
        title = data.get('title')
        short_title = truncate_with_ellipsis(title, 100) or title

        r = re.compile(
            r'[Dd]estroyed(?: (?:by|during) (\w+))?(?: in (\d{4})[.]?)?')
        m = r.search(note)
        if m:
            method = m.group(1)
            year = m.group(2)
            # The destruction URI is just the object URI with a suffix. When URIs are
            # reconciled during prev/post sale rewriting, this will allow us to also reconcile
            # the URIs for the destructions (of which there should only be one per object)
            dest_uri = hmo.id + '-Destruction'

            d = model.Destruction(ident=dest_uri,
                                  label=f'Destruction of “{short_title}”')
            d.referred_to_by = vocab.Note(ident='', content=note)
            if year is not None:
                begin, end = date_cleaner(year)
                ts = timespan_from_outer_bounds(begin, end)
                ts.identified_by = model.Name(ident='', content=year)
                d.timespan = ts

            if method:
                with suppress(KeyError, AttributeError):
                    type_name = destruction_types_map[method.lower()]
                    otype = vocab.instances[type_name]
                    event = model.Event(
                        label=
                        f'{method.capitalize()} event causing the destruction of “{short_title}”'
                    )
                    event.classified_as = otype
                    d.caused_by = event
                    data['_events'].append(add_crom_data(data={}, what=event))

            if location:
                current = parse_location_name(
                    location, uri_base=self.helper.uid_tag_prefix)
                # The place URI used for destruction events is based on the object URI with
                # a suffix. When URIs are reconciled during prev/post sale rewriting, this
                # will allow us to also reconcile the URIs for the places of destruction
                # (of which there should only be one hierarchy per object)
                base_uri = hmo.id + '-Destruction-Place,'
                place_data = self.helper.make_place(current, base_uri=base_uri)
                place = get_crom_object(place_data)
                if place:
                    data['_locations'].append(place_data)
                    d.took_place_at = place

            hmo.destroyed_by = d
Esempio n. 2
0
    def clean_dates(self, data):
        cb = data.get('corporate_body', False)
        birth_key = 'formation' if cb else 'birth'
        death_key = 'dissolution' if cb else 'death'

        if cb:
            data[birth_key] = data.get('birth')
            data[death_key] = data.get('death')

        if 'birth' in data:
            data[f'{birth_key}_clean'] = date_cleaner(data[birth_key])

        if 'death' in data:
            data[f'{death_key}_clean'] = date_cleaner(data[death_key])

        birth = data.get('birth')
        death = data.get('death')
        period = data.get('period_active')
        century = data.get('century_active')
        active_city = data.get('active_city_date')

        if century:
            if '-' in century:
                begin, end = century.split('-')
            else:
                begin, end = century, century
            begin_ts = date_cleaner(begin)
            end_ts = date_cleaner(end)
            range_ts = [None, None]
            with suppress(TypeError):
                range_ts[0] = begin_ts[0]
            with suppress(TypeError):
                range_ts[1] = end_ts[1]
            data['century_active_clean'] = range_ts

        if period:
            clean_ts = []
            components = [p.strip() for p in period.split(';')]
            ts = None
            for p in components:
                if '-' in p:
                    begin, end = p.split('-')
                    begin_ts = date_cleaner(begin)
                    end_ts = date_cleaner(end)
                    ts = [None, None]
                    with suppress(TypeError):
                        ts[0] = begin_ts[0]
                    with suppress(TypeError):
                        ts[1] = end_ts[1]
                else:
                    ts = date_cleaner(p)
                if ts:
                    clean_ts.append(ts)
            if ts:
                # TODO: should handle multiple timespans in clean_ts
                data['period_active_clean'] = ts
Esempio n. 3
0
	def string_to_span(value):
		'''Parse a string value and attempt to create a corresponding `model.TimeSpan` object.'''
		try:
			date_from, date_to = date_cleaner(value)
			ts = model.TimeSpan()
			if date_from is not None:
				ts.begin_of_the_begin = date_from.strftime("%Y-%m-%dT%H:%M:%SZ")
			if date_to is not None:
				ts.end_of_the_end = date_to.strftime("%Y-%m-%dT%H:%M:%SZ")
			return ts
		except Exception as e:
			print('*** Unknown date format %r: %s' % (value, e))
			return None
Esempio n. 4
0
    def populate_destruction_events(self,
                                    data: dict,
                                    note,
                                    *,
                                    type_map,
                                    location=None):
        destruction_types_map = type_map
        hmo = get_crom_object(data)
        title = data.get('title')
        short_title = truncate_with_ellipsis(title, 100) or title

        r = re.compile(
            r'[Dd]estroyed(?: (?:by|during) (\w+))?(?: in (\d{4})[.]?)?')
        m = r.search(note)
        if m:
            method = m.group(1)
            year = m.group(2)
            dest_id = hmo.id + '-Destr'
            d = model.Destruction(ident=dest_id,
                                  label=f'Destruction of “{short_title}”')
            d.referred_to_by = vocab.Note(ident='', content=note)
            if year is not None:
                begin, end = date_cleaner(year)
                ts = timespan_from_outer_bounds(begin, end)
                ts.identified_by = model.Name(ident='', content=year)
                d.timespan = ts

            if method:
                with suppress(KeyError, AttributeError):
                    type_name = destruction_types_map[method.lower()]
                    otype = vocab.instances[type_name]
                    event = model.Event(
                        label=
                        f'{method.capitalize()} event causing the destruction of “{short_title}”'
                    )
                    event.classified_as = otype
                    d.caused_by = event
                    data['_events'].append(add_crom_data(data={}, what=event))

            if location:
                current = parse_location_name(
                    location, uri_base=self.helper.uid_tag_prefix)
                base_uri = hmo.id + '-Place,'
                place_data = self.helper.make_place(current, base_uri=base_uri)
                place = get_crom_object(place_data)
                if place:
                    data['_locations'].append(place_data)
                    d.took_place_at = place

            hmo.destroyed_by = d
Esempio n. 5
0
    def model_sojourn(self, data, loc):
        base_uri = self.helper.make_proj_uri('PLACE', '')
        cb = data.get('corporate_body', False)
        sojourn_type = vocab.Establishment if cb else vocab.Residing
        sdata = {
            'type': sojourn_type,
            'referred_to_by': [],
        }

        verbatim_date = loc.get('address_date')
        if verbatim_date:
            date_range = date_cleaner(verbatim_date)
            if date_range:
                begin, end = date_range
                ts = timespan_from_outer_bounds(*date_range)
                ts.identified_by = model.Name(ident='', content=verbatim_date)
                sdata['timespan'] = add_crom_data(
                    {
                        'address_date': verbatim_date,
                        'begin': begin,
                        'end': end
                    }, ts)

        current = None
        l = loc.get('location')
        if l:
            current = parse_location_name(l, uri_base=self.helper.proj_prefix)
        address = loc.get('address')
        if address:
            current = {
                'name': address,
                'part_of': current,
                'type': 'address',
            }

        for k in ('address_note', 'location_note'):
            note = loc.get(k)
            if note:
                sdata['referred_to_by'].append(
                    vocab.Note(ident='', content=note))

        if current:
            place_data = self.helper.make_place(current, base_uri=base_uri)
            data['_places'].append(place_data)
            sdata['place'] = place_data
        return sdata
Esempio n. 6
0
 def model_active_city(self, data, loc):
     m = self.active_date.search(loc)
     date = None
     if m:
         date = m.group(2)
         date_range = date_cleaner(date)
         if date_range:
             loc = m.group(1)
         else:
             # this apparently wasn't a date, but just a parenthetical
             date = None
     sdata = {
         'location': loc,
     }
     if date:
         sdata['address_date'] = date
     return self.model_sojourn(data, sdata)
Esempio n. 7
0
    def active_args(self, data: dict, name: str):
        '''
		Return a dict suitable for passing as keyword arguments to
		`professional_activity` to indicate the time period during
		which a person was active in their professional activities.
		'''
        period_active = data.get('period_active')
        century_active = data.get('century_active')
        if period_active:
            date_range = date_cleaner(period_active)
            if date_range:
                return {'date_range': date_range}
        elif century_active:
            if len(century_active) == 4 and century_active.endswith('th'):
                century = int(century_active[0:2])
                return {'century': century}
            else:
                warnings.warn(
                    f'TODO: better handling for century ranges: {century_active}'
                )
        return {}
Esempio n. 8
0
	def handle_dates(self, data):
		if 'birth' in data:
			data['birth_clean'] = date_cleaner(data['birth'])

		if 'death' in data:
			data['death_clean'] = date_cleaner(data['death'])