Ejemplo n.º 1
0
def marc21_to_language(self, key, value):
    """Get languages.

    languages: 008 and 041 [$a, repetitive]
    """
    lang_codes = []
    language = self.get('language', [])
    if marc21.lang_from_008:
        language.append({'value': marc21.lang_from_008, 'type': 'bf:Language'})
        lang_codes.append(marc21.lang_from_008)
    for lang_value in marc21.langs_from_041_a:
        if lang_value not in lang_codes:
            language.append({
                'value': lang_value.strip(),
                'type': 'bf:Language'
            })
            lang_codes.append(lang_value)
    # default provisionActivity if we have no 264
    fields_264 = marc21.get_fields(tag='264')
    valid_264 = False
    for field_264 in fields_264:
        valid_264 = valid_264 or field_264['ind2'] in ['0', '1', '2', '3']
    if not valid_264:
        if fields_264:
            error_print('WARNING INVALID 264', marc21.bib_id, marc21.rero_id,
                        fields_264)
        self['provisionActivity'] = [{'type': 'bf:Publication'}]
        if (marc21.date_type_from_008 == 'q'
                or marc21.date_type_from_008 == 'n'):
            self['provisionActivity'][0][
                'note'] = 'Date(s) uncertain or unknown'
        start_date = make_year(marc21.date1_from_008)
        if not start_date or start_date > 2050:
            error_print('WARNING START DATE 008:', marc21.bib_id,
                        marc21.rero_id, marc21.date1_from_008)
            start_date = 2050
            self['provisionActivity'][0][
                'note'] = 'Date not available and automatically set to 2050'
        self['provisionActivity'][0]['startDate'] = start_date
        end_date = make_year(marc21.date2_from_008)
        if end_date:
            if end_date > 2050:
                error_print('WARNING END DATE 008:', marc21.bib_id,
                            marc21.rero_id, marc21.date1_from_008)
            else:
                self['provisionActivity'][0]['endDate'] = end_date

    # if not language:
    #     error_print('ERROR LANGUAGE:', marc21.bib_id, 'set to "und"')
    #     language = [{'value': 'und', 'type': 'bf:Language'}]
    return language or None
Ejemplo n.º 2
0
def unimarc_publishers_provision_activity_publication(self, key, value):
    """Get provision activity dates."""
    def build_place_or_agent_data(code, label, index):
        type_per_code = {'a': 'bf:Place', 'c': 'bf:Agent'}
        place_or_agent_data = {
            'type': type_per_code[code],
            'label': [{
                'value': remove_trailing_punctuation(label)
            }]
        }
        return place_or_agent_data

    def build_place():
        # country from 102
        place = {}
        field_102 = unimarc.get_fields(tag='102')
        if field_102:
            field_102 = field_102[0]
            country_codes = unimarc.get_subfields(field_102, 'a')
            if country_codes:
                place['country'] = country_codes[0].lower()
                place['type'] = 'bf:Place'
        return place

    publication = {}
    ind2 = key[4]
    type_per_ind2 = {
        ' ': 'bf:Publication',
        '_': 'bf:Publication',
        '0': 'bf:Publication',
        '1': 'bf:Production',
        '2': 'bf:Distribution',
        '3': 'bf:Manufacture'
    }
    if ind2 == '4':
        field_d = value.get('d')
        if field_d:
            field_d = force_list(field_d)[0]
            copyright_date = self.get('copyrightDate', [])
            if field_d[0] == 'P':
                copyright_date.append('℗ ' + field_d[2:])
            else:
                copyright_date.append('© ' + field_d)
            self['copyrightDate'] = copyright_date
    else:
        publication = {
            'type': type_per_ind2[ind2],
            'statement': [],
        }
        statement = []
        items = get_field_items(value)
        index = 1
        for blob_key, blob_value in items:
            if blob_key in ('a', 'c'):
                place_or_agent_data = build_place_or_agent_data(
                    blob_key, blob_value, index)
                statement.append(place_or_agent_data)
            if blob_key != '__order__':
                index += 1
        if statement:
            publication['statement'] = statement
        if ind2 in (' ', '_', '0'):
            place = build_place()
            if place:
                publication['place'] = [place]

        subfields_d = utils.force_list(value.get('d'))
        if subfields_d:
            subfield_d = subfields_d[0]
            publication['statement'].append({
                'label': [{
                    'value': subfield_d
                }],
                'type': 'Date'
            })
            if ind2 in (' ', '_', '0'):
                dates = subfield_d.replace('[', '').replace(']', '').split('-')
                try:
                    start_date = make_year(dates[0])
                    if start_date:
                        publication['startDate'] = start_date
                except Exception:
                    pass
                try:
                    end_date = make_year(dates[1])
                    if end_date:
                        publication['endDate'] = end_date
                except Exception:
                    pass

    if not publication.get('statement'):
        publication = None
    return publication or None
Ejemplo n.º 3
0
def unimarc_publishers_provision_activity_publication(self, key, value):
    """Get provision activity dates."""
    def build_place_or_agent_data(code, label, index):
        type_per_code = {
            'a': 'bf:Place',
            'c': 'bf:Agent',
            'e': 'bf:Place',
            'g': 'bf:Agent'
        }
        place_or_agent_data = {
            'type': type_per_code[code],
            'label': [{'value': remove_trailing_punctuation(label)}]
        }
        return place_or_agent_data

    def build_place():
        # country from 102
        place = {}
        field_102 = unimarc.get_fields(tag='102')
        if field_102:
            field_102 = field_102[0]
            country_codes = unimarc.get_subfields(field_102, 'a')
            if country_codes:
                country = _COUNTRY_UNIMARC_MARC21.get(country_codes[0])
                if country:
                    place['country'] = country
                    place['type'] = 'bf:Place'
        return place

    # only take 214 if exists
    publication = {}
    ind2 = key[4]
    type_per_ind2 = {
        ' ': 'bf:Publication',
        '_': 'bf:Publication',
        '0': 'bf:Publication',
        '1': 'bf:Production',
        '2': 'bf:Distribution',
        '3': 'bf:Manufacture'
    }
    if ind2 == '4':
        field_d = value.get('d')
        if field_d:
            field_d = utils.force_list(field_d)[0]
            copyright_date = self.get('copyrightDate', [])
            if field_d[0] == 'P':
                copyright_date.append('℗ ' + field_d[2:])
            else:
                copyright_date.append('© ' + field_d)
            self['copyrightDate'] = copyright_date
    else:
        start_date = None
        end_date = None
        place = build_place()
        field_100 = unimarc.get_fields('100')
        if field_100:
            field_100 = field_100[0]
            subfield_a = unimarc.get_subfields(field_100, 'a')
            if subfield_a:
                subfield_a = subfield_a[0]
                start_date = make_year(subfield_a[9:13])
                end_date = make_year(subfield_a[14:17])

        if key[:3] == '210':
            if not unimarc.get_fields(tag='214'):
                publications = self.setdefault('provisionActivity', [])
                items = get_field_items(value)
                index = 1
                publication = {}
                statement = []
                for blob_key, blob_value in items:
                    if blob_key in ('a', 'c'):
                        type = 'bf:Publication'
                        if index == 1:
                            old_type = 'bf:Publication'
                            publication = {'type': type, 'statement': []}
                        if type != old_type:
                            subfields_h = utils.force_list(value.get('h'))
                            publication['statement'] = statement
                            if subfields_h:
                                subfields_h = subfields_h[0]
                                publication['statement'].append({
                                    'label': [{'value': subfields_h}],
                                    'type': 'Date'
                                })
                            statement = []
                            publications.append(publication)
                            publication = {
                                'type': type,
                                'statement': [],
                            }
                            old_type = type

                        place_or_agent_data = build_place_or_agent_data(
                            blob_key, blob_value, index)
                        statement.append(place_or_agent_data)
                    if blob_key in ('e', 'g'):
                        type = 'bf:Manufacture'
                        if index == 1:
                            old_type = 'bf:Manufacture'
                            publication = {'type': type, 'statement': []}
                        if type != old_type:
                            subfields_d = utils.force_list(value.get('d'))
                            publication['statement'] = statement
                            if subfields_d:
                                subfield_d = subfields_d[0]
                                publication['statement'].append({
                                    'label': [{'value': subfield_d}],
                                    'type': 'Date'
                                })
                            if start_date:
                                publication['startDate'] = start_date
                            if end_date:
                                publication['endDate'] = end_date
                            if place:
                                publication['place'] = [place]
                            statement = []
                            publications.append(publication)
                            publication = {
                                'type': type,
                                'statement': [],
                            }
                            old_type = type
                        place_or_agent_data = build_place_or_agent_data(
                            blob_key, blob_value, index)
                        statement.append(place_or_agent_data)
                    if blob_key != '__order__':
                        index += 1
                if statement:
                    publication = {
                        'type': type,
                        'statement': statement,
                    }
                    date_subfield = 'd'
                    if type == 'bf:Manufacture':
                        date_subfield = 'h'
                    subfields = utils.force_list(value.get(date_subfield))
                    if subfields:
                        subfield = subfields[0]
                        publication['statement'].append({
                            'label': [{'value': subfield}],
                            'type': 'Date'
                        })
                    if publication['type'] == 'bf:Publication':
                        if start_date:
                            publication['startDate'] = start_date
                        if end_date:
                            publication['endDate'] = end_date
                        if place:
                            publication['place'] = [place]

                    publications.append(publication)
                if publications:
                    self['provisionActivity'] = publications
                return None
        else:
            publication = {
                'type': type_per_ind2[ind2],
                'statement': [],
            }
            statement = []
            items = get_field_items(value)
            index = 1
            for blob_key, blob_value in items:
                if blob_key in ('a', 'c'):
                    place_or_agent_data = build_place_or_agent_data(
                        blob_key, blob_value, index)
                    statement.append(place_or_agent_data)
                if blob_key != '__order__':
                    index += 1
            if statement:
                publication['statement'] = statement
            if publication['type'] == 'bf:Publication':
                if place:
                    publication['place'] = [place]

            subfields_d = utils.force_list(value.get('d'))
            if subfields_d:
                subfield_d = subfields_d[0]
                publication['statement'].append({
                    'label': [{'value': subfield_d}],
                    'type': 'Date'
                })
            if publication['type'] == 'bf:Publication':
                if start_date:
                    publication['startDate'] = start_date
                if end_date:
                    publication['endDate'] = end_date

    if not publication.get('statement'):
        publication = None
    return publication or None
Ejemplo n.º 4
0
def marc21_to_provision_activity(self, key, value):
    """Get publisher data.

    publisher.name: 264 [$b repetitive]
    publisher.place: 264 [$a repetitive]
    publicationDate: 264 [$c repetitive] (but take only the first one)
    """
    def build_statement(field_value, ind2):
        def build_place_or_agent_data(code, label):
            place_or_agent_data = None
            type_per_code = {'a': 'bf:Place', 'b': 'bf:Agent'}
            value = remove_trailing_punctuation(label)
            if value:
                place_or_agent_data = {
                    'type': type_per_code[code],
                    'label': [{
                        'value': value
                    }]
                }
            return place_or_agent_data

        # function build_statement start here
        statement = []
        items = get_field_items(field_value)
        for blob_key, blob_value in items:
            if blob_key in ('a', 'b'):
                place_or_agent_data = build_place_or_agent_data(
                    blob_key, blob_value)
                if place_or_agent_data:
                    statement.append(place_or_agent_data)
        return statement or None

    def build_place():
        place = {}
        if marc21.country:
            place['country'] = marc21.country
        if place:
            place['type'] = 'bf:Place'
        return place

    # the function marc21_to_provisionActivity start here
    ind2 = key[4]
    type_per_ind2 = {
        ' ': 'bf:Publication',
        '0': 'bf:Production',
        '1': 'bf:Publication',
        '2': 'bf:Distribution',
        '3': 'bf:Manufacture'
    }
    if key[:3] == '260':
        ind2 = '1'  # to force type to bf:Publication for field 260
    publication = {
        'type': type_per_ind2[ind2],
        'statement': [],
    }

    publication['statement'] = build_statement(value, ind2)

    subfields_c = utils.force_list(value.get('c'))
    if subfields_c:
        subfield_c = subfields_c[0]
        publication['statement'].append({
            'label': [{
                'value': subfield_c
            }],
            'type': 'Date'
        })
        if ind2 in (' ', '1'):
            dates = subfield_c.replace('[', '').replace(']', '').split('-')
            try:
                start_date = make_year(dates[0])
                if start_date:
                    publication['startDate'] = start_date
            except Exception:
                pass
            try:
                end_date = make_year(dates[1])
                if end_date:
                    publication['endDate'] = end_date
            except Exception:
                pass
            place = build_place()
            if place:
                publication['place'] = [place]

    return publication or None
Ejemplo n.º 5
0
def marc21_to_provisionActivity(self, key, value):
    """Get publisher data.

    publisher.name: 264 [$b repetitive] (without the , but keep the ;)
    publisher.place: 264 [$a repetitive] (without the : but keep the ;)
    publicationDate: 264 [$c repetitive] (but take only the first one)
    """
    def build_statement(field_value, ind2):
        def build_agent_data(code, label, index, link):
            type_per_code = {'a': 'bf:Place', 'b': 'bf:Agent'}
            agent_data = {
                'type': type_per_code[code],
                'label': [{
                    'value': remove_trailing_punctuation(label)
                }]
            }
            try:
                alt_gr = marc21.alternate_graphic['264'][link]
                subfield = \
                    marc21.get_subfields(alt_gr['field'])[index]
                agent_data['label'].append({
                    'value':
                    remove_trailing_punctuation(subfield),
                    'language':
                    marc21.get_language_script(alt_gr['script'])
                })
            except Exception as err:
                pass
            return agent_data

        # function build_statement start here
        tag_link, link = get_field_link_data(field_value)
        items = get_field_items(field_value)
        statement = []
        index = 1
        for blob_key, blob_value in items:
            if blob_key in ('a', 'b'):
                agent_data = build_agent_data(blob_key, blob_value, index,
                                              link)
                statement.append(agent_data)
            if blob_key != '__order__':
                index += 1
        return statement

    def build_place():
        place = {}
        if marc21.cantons:
            place['canton'] = marc21.cantons[0]
        if marc21.country:
            place['country'] = marc21.country
        if place:
            place['type'] = 'bf:Place'
        return place

    # the function marc21_to_provisionActivity start here
    ind2 = key[4]
    type_per_ind2 = {
        ' ': 'bf:Publication',
        '0': 'bf:Production',
        '1': 'bf:Publication',
        '2': 'bf:Distribution',
        '3': 'bf:Manufacture'
    }
    publication = {
        'type': type_per_ind2[ind2],
        'statement': [],
    }

    subfields_c = utils.force_list(value.get('c'))
    if ind2 in (' ', '1'):
        start_date = make_year(marc21.date1_from_008)
        if start_date:
            publication['startDate'] = start_date
        end_date = make_year(marc21.date2_from_008)
        if end_date:
            publication['endDate'] = end_date
        if (marc21.date_type_from_008 == 'q'
                or marc21.date_type_from_008 == 'n'):
            publication['note'] = 'Date(s) incertaine(s) ou inconnue(s)'
        place = build_place()
        if place:
            publication['place'] = [place]
    publication['statement'] = build_statement(value, ind2)
    if subfields_c:
        subfield_c = subfields_c[0]
        date = {'label': [{'value': subfield_c}], 'type': 'Date'}

        tag_link, link = get_field_link_data(value)
        try:
            alt_gr = marc21.alternate_graphic['264'][link]
            subfield = \
                marc21.get_subfields(alt_gr['field'], code='c')
            date['label'].append({
                'value':
                subfield[0],
                'language':
                marc21.get_language_script(alt_gr['script'])
            })
        except Exception as err:
            pass

        publication['statement'].append(date)
    return publication or None