Beispiel #1
0
    def model_publishing(data):
        series_label = data['label']
        a_uri = data['uri'] + f'-pub'
        a = vocab.Publishing(ident=a_uri,
                             label=f'Publishing of {series_label}')
        start_year = data.get('_publishing_start_year')
        cease_year = data.get('_publishing_cease_year')
        if start_year or cease_year:
            ts = model.TimeSpan(ident='')
            if start_year:
                with suppress(ValueError):
                    year = int(start_year)
                    ts.begin_of_the_begin = '%04d-01-01:00:00:00Z' % (year, )
            if cease_year:
                with suppress(ValueError):
                    year = int(cease_year)
                    ts.end_of_the_end = '%04d-01-01:00:00:00Z' % (year + 1, )
            a.timespan = ts

        publishings = data.get('_publishings', [])
        if publishings:
            series_label = data['label']
            # 			if len(publishings) > 1:
            # 				print(f'{len(publishings)} publishings of {series_label}')
            for sub in publishings:
                a.part = sub

        data['used_for'].append(a)
Beispiel #2
0
def timespan_from_outer_bounds(begin=None, end=None, inclusive=False):
    '''
	Return a `TimeSpan` based on the (optional) `begin` and `end` date strings.

	If both `begin` and `end` are `None`, returns `None`.
	'''
    if begin or end:
        ts = model.TimeSpan(ident='')
        ts._label = label_for_timespan_range(begin, end, inclusive=inclusive)

        if begin is not None:
            try:
                if not isinstance(begin, datetime.datetime):
                    begin = dateutil.parser.parse(begin)
                begin = begin.strftime("%Y-%m-%dT%H:%M:%SZ")
                ts.begin_of_the_begin = begin
            except ValueError:
                warnings.warn(f'*** failed to parse begin date: {begin}')
                raise
        if end is not None:
            try:
                if not isinstance(end, datetime.datetime):
                    end = dateutil.parser.parse(end)
                if inclusive:
                    end += datetime.timedelta(days=1)
                end = end.strftime("%Y-%m-%dT%H:%M:%SZ")
                ts.end_of_the_end = end
            except ValueError:
                warnings.warn(f'*** failed to parse end date: {end}')
        return ts
    return None
Beispiel #3
0
 def test_int_per_segment(self):
     model.factory._auto_id_segments = {}
     model.factory.auto_id_type = "int-per-segment"
     model.Activity._uri_segment = model.Person._uri_segment
     p = model.Person()
     p2 = model.Activity()
     self.assertEqual(int(p.id[-1]), int(p2.id[-1]) - 1)
     p3 = model.TimeSpan()
     self.assertEqual(int(p.id[-1]), int(p3.id[-1]))
Beispiel #4
0
    def set_properties(self, data, thing):
        super().set_properties(data, thing)
        with suppress(KeyError):
            thing._label = str(data['label'])

        for event in data.get('events', []):
            thing.carried_out = event

        for n in data.get('nationality', []):
            thing.classified_as = n

        if data.get('formation'):
            b = model.Formation()
            ts = model.TimeSpan(ident='')
            if 'formation_clean' in data and data['formation_clean']:
                if data['formation_clean'][0]:
                    ts.begin_of_the_begin = data['formation_clean'][
                        0].strftime("%Y-%m-%dT%H:%M:%SZ")
                if data['formation_clean'][1]:
                    ts.end_of_the_end = data['formation_clean'][1].strftime(
                        "%Y-%m-%dT%H:%M:%SZ")
            verbatim = data['formation']
            ts._label = verbatim
            ts.identified_by = model.Name(ident='', content=verbatim)
            b.timespan = ts
            b._label = "Formation of %s" % thing._label
            thing.formed_by = b

        if data.get('dissolution'):
            d = model.Dissolution()
            ts = model.TimeSpan(ident='')
            if 'dissolution_clean' in data and data['dissolution_clean']:
                if data['dissolution_clean'][0]:
                    ts.begin_of_the_begin = data['dissolution_clean'][
                        0].strftime("%Y-%m-%dT%H:%M:%SZ")
                if data['dissolution_clean'][1]:
                    ts.end_of_the_end = data['dissolution_clean'][1].strftime(
                        "%Y-%m-%dT%H:%M:%SZ")
            verbatim = data['dissolution']
            ts._label = verbatim
            ts.identified_by = model.Name(ident='', content=verbatim)
            d.timespan = ts
            d._label = "Dissolution of %s" % thing._label
            thing.dissolved_by = d
Beispiel #5
0
def timespan_after(before):
    ts = model.TimeSpan(ident='')
    try:
        ts.begin_of_the_begin = before.end_of_the_end
        with suppress(AttributeError):
            l = f'After {before._label}'
            l.identified_by = model.Name(ident='', content=l)
            ts._label = l
        return ts
    except AttributeError:
        return None
Beispiel #6
0
def timespan_before(after):
    ts = model.TimeSpan(ident='')
    try:
        ts.end_of_the_end = after.begin_of_the_begin
        with suppress(AttributeError):
            l = f'Before {after._label}'
            l.identified_by = model.Name(ident='', content=l)
            ts._label = l
        return ts
    except AttributeError:
        return None
Beispiel #7
0
def dates_for_century(century):
    '''
	Given a integer representing a century (e.g. 17 for the 17th century), return a
	tuple of dates for the bounds of that century.
	'''
    ord = make_ordinal(century)
    ts = model.TimeSpan(ident='', label=f'{ord} century')
    from_year = 100 * (century - 1)
    to_year = from_year + 100
    begin = datetime.datetime(from_year, 1, 1)
    end = datetime.datetime(to_year, 1, 1)
    return (begin, end)
Beispiel #8
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
Beispiel #9
0
def timespan_for_century(century, narrow=False, inclusive=False, **kwargs):
    '''
	Given a integer representing a century (e.g. 17 for the 17th century), return a
	TimeSpan object for the bounds of that century.
	
	If `narrow` is True, the bounding properties will be `end_of_the_begin` and
	`begin_of_the_end`; otherwise they will be `begin_of_the_begin` and `end_of_the_end`.
	'''
    ord = make_ordinal(century)
    ts = model.TimeSpan(ident='', label=f'{ord} century')
    from_year = 100 * (century - 1)
    to_year = from_year + 100
    if narrow:
        ts.end_of_the_begin = "%04d-%02d-%02dT%02d:%02d:%02dZ" % (from_year, 1,
                                                                  1, 0, 0, 0)
        ts.begin_of_the_end = "%04d-%02d-%02dT%02d:%02d:%02dZ" % (to_year, 1,
                                                                  1, 0, 0, 0)
    else:
        ts.begin_of_the_begin = "%04d-%02d-%02dT%02d:%02d:%02dZ" % (
            from_year, 1, 1, 0, 0, 0)
        ts.end_of_the_end = "%04d-%02d-%02dT%02d:%02d:%02dZ" % (to_year, 1, 1,
                                                                0, 0, 0)
    return ts
Beispiel #10
0
def make_ymd_timespan(data: dict, start_prefix="", end_prefix="", label=""):
    y = f'{start_prefix}year'
    m = f'{start_prefix}month'
    d = f'{start_prefix}day'
    y2 = f'{end_prefix}year'
    m2 = f'{end_prefix}month'
    d2 = f'{end_prefix}day'

    t = model.TimeSpan(ident='')
    if not label:
        label = ymd_to_label(data[y], data[m], data[d])
        if y != y2:
            lbl2 = ymd_to_label(data[y2], data[m2], data[d2])
            label = f'{label} to {lbl2}'
    t._label = label
    if not label:
        warnings.warn(f'Setting empty name on {t.id}')
    t.identified_by = model.Name(ident='', content=label)
    t.begin_of_the_begin = ymd_to_datetime(data[y], data[m], data[d])
    t.end_of_the_end = ymd_to_datetime(data[y2],
                                       data[m2],
                                       data[d2],
                                       which="end")
    return t
Beispiel #11
0
    def set_properties(self, data, who):
        super().set_properties(data, who)
        with suppress(KeyError):
            who._label = str(data['label'])

        for ns in [
                'aat_nationality_1', 'aat_nationality_2', 'aat_nationality_3'
        ]:
            # add nationality
            n = data.get(ns)
            # XXX Strip out antique / modern anonymous as a nationality
            if n:
                if int(n) in [300310546, 300264736]:
                    break
                natl = vocab.Nationality(
                    ident="http://vocab.getty.edu/aat/%s" % n)
                who.classified_as = natl
                natl._label = str(data[ns + '_label'])
            else:
                break
        for n in data.get('nationality', []):
            if isinstance(n, model.BaseResource):
                who.classified_as = n

        # nationality field can contain other information, but not useful.
        # XXX Intentionally ignored but validate with GRI

        if data.get('active_early') or data.get('active_late'):
            act = vocab.Active()
            ts = model.TimeSpan(ident='')
            if data['active_early']:
                ts.begin_of_the_begin = "%s-01-01:00:00:00Z" % (
                    data['active_early'], )
                ts.end_of_the_begin = "%s-01-01:00:00:00Z" % (
                    data['active_early'] + 1, )
            if data['active_late']:
                ts.begin_of_the_end = "%s-01-01:00:00:00Z" % (
                    data['active_late'], )
                ts.end_of_the_end = "%s-01-01:00:00:00Z" % (
                    data['active_late'] + 1, )
            ts._label = "%s-%s" % (data['active_early'], data['active_late'])
            act.timespan = ts
            who.carried_out = act

        for event in data.get('events', []):
            who.carried_out = event

        if data.get('birth'):
            b = model.Birth()
            ts = model.TimeSpan(ident='')
            if 'birth_clean' in data and data['birth_clean']:
                if data['birth_clean'][0]:
                    ts.begin_of_the_begin = data['birth_clean'][0].strftime(
                        "%Y-%m-%dT%H:%M:%SZ")
                if data['birth_clean'][1]:
                    ts.end_of_the_end = data['birth_clean'][1].strftime(
                        "%Y-%m-%dT%H:%M:%SZ")
            ts._label = data['birth']
            b.timespan = ts
            b._label = "Birth of %s" % who._label
            who.born = b

        if data.get('death'):
            d = model.Death()
            ts = model.TimeSpan(ident='')
            if 'death_clean' in data and data['death_clean']:
                if data['death_clean'][0]:
                    ts.begin_of_the_begin = data['death_clean'][0].strftime(
                        "%Y-%m-%dT%H:%M:%SZ")
                if data['death_clean'][1]:
                    ts.end_of_the_end = data['death_clean'][1].strftime(
                        "%Y-%m-%dT%H:%M:%SZ")
            ts._label = data['death']
            d.timespan = ts
            d._label = "Death of %s" % who._label
            who.died = d

        if 'contact_point' in data:
            for p in data['contact_point']:
                if isinstance(p, model.Identifier):
                    pl = p
                elif isinstance(p, dict):
                    pl = get_crom_object(p)
                else:
                    pl = model.Identifier(ident='', content=p)
                who.contact_point = pl
Beispiel #12
0
    def model_issue_group(self, record, data, seq):
        record.setdefault('^part', [])

        issue_id = data['issue_id']
        title = data.get('title')
        title_translated = data.get('title_translated')
        date = data.get('date')
        # issue_group/date/display_date
        # issue_group/date/sort_year
        volume = data.get('volume')
        number = data.get('number')
        note = data.get('note')

        journal_label = record['label']
        issue_label = f'Issue of {journal_label}'
        if title:
            issue_label = f'{journal_label}: “{title}”'
            if volume and number:
                issue_label = f'{issue_label} (v. {volume}, n. {number})'
        elif volume and number:
            issue_label = f'{journal_label} (v. {volume}, n. {number})'

        jid = record['record_desc_group']['record_id']
        issue = {
            'uri': self.helper.issue_uri(jid, issue_id),
            'label': issue_label,
            'object_type': vocab.IssueText,
            'identifiers': [self.helper.gci_number_id(issue_id)],
            'referred_to_by': [],
            'used_for': [],
        }
        if title:
            issue['identifiers'].append(
                vocab.PrimaryName(ident='', content=title))
        if title_translated:
            issue['identifiers'].append(
                vocab.TranslatedTitle(ident='', content=title_translated))

        if date:
            display_date = date.get('display_date')
            sort_year = date.get('sort_year')
            if display_date or sort_year:
                a_uri = issue['uri'] + f'-pub'
                a = vocab.Publishing(ident=a_uri,
                                     label=f'Publishing of {issue_label}')
                ts = model.TimeSpan(ident='')
                if display_date:
                    ts._label = display_date
                    ts.identified_by = vocab.DisplayName(ident='',
                                                         content=display_date)
                if sort_year:
                    try:
                        year = int(sort_year)
                        ts.begin_of_the_begin = '%04d-01-01:00:00:00Z' % (
                            year, )
                        ts.end_of_the_end = '%04d-01-01:00:00:00Z' % (year +
                                                                      1, )
                    except:
                        pass
                a.timespan = ts
                issue['used_for'].append(a)

        # TODO:
        # volume
        # number

        if note:
            issue['referred_to_by'].append(vocab.Note(ident='', content=note))

        mlalo = MakeLinkedArtLinguisticObject()
        mlalo(issue)

        i = get_crom_object(issue)
        for a in issue.get('used_for', []):
            i.used_for = a

        record['^part'].append(issue)
Beispiel #13
0
    fetchDelay = 0

for oid in objects:
    url = "%s%s" % (baseUrl, oid)
    js = fetch(url, "json", fetchDelay)

    cls = objectTypeMap.get(js['classification'], model.HumanMadeObject)
    artwork = cls(ident=url)
    artwork.identified_by = vocab.LocalNumber(value=js['objectID'])
    artwork.identified_by = vocab.AccessionNumber(value=js['accessionNumber'])
    artwork.identified_by = vocab.Title(value=js['title'])

    prod = model.Production()
    artwork.produced_by = prod
    if js['objectBeginDate'] or js['objectEndDate'] or js['objectDate']:
        ts = model.TimeSpan()
        ts.begin_of_the_begin = js.get('objectBeginDate',
                                       js.get('objectDate', None))
        ts.end_of_the_end = js.get('objectEndDate', js.get('objectDate', None))
        ts.identified_by = model.Name(value=js['objectDate'])
        prod.timespan = ts

    artist = model.Person()
    if js['artistDisplayName']:
        artist.identified_by = model.Name(value=js['artistDisplayName'])
        prod.carried_out_by = artist
    if js['artistDisplayBio']:
        artist.referred_to_by = vocab.BiographyStatement(
            value=js['artistDisplayBio'])
    if js['artistNationality']:
        artist.classified_as = nationalityMap[js['artistNationality']]