コード例 #1
0
ファイル: crossref.py プロジェクト: qa4osf/osf.io
    def _process_crossref_name(self, contributor):
        # Adapted from logic used in `api/citations/utils.py`
        # If the user has a family and given name, use those
        if contributor.family_name and contributor.given_name:
            given = contributor.given_name
            middle = contributor.middle_names
            family = contributor.family_name
            suffix = contributor.suffix
        else:
            names = impute_names(contributor.fullname)
            given = names.get('given')
            middle = names.get('middle')
            family = names.get('family')
            suffix = names.get('suffix')

        given_name = ' '.join([given, middle]).strip()
        given_stripped = remove_control_characters(given_name)
        # For crossref, given_name is not allowed to have numbers or question marks
        given_processed = ''.join([
            char for char in given_stripped
            if (not char.isdigit() and char != '?')
        ])
        surname_processed = remove_control_characters(family)

        surname = surname_processed or given_processed or contributor.fullname
        processed_names = {'surname': surname[:CROSSREF_SURNAME_LIMIT].strip()}
        if given_processed and surname_processed:
            processed_names[
                'given_name'] = given_processed[:
                                                CROSSREF_GIVEN_NAME_LIMIT].strip(
                                                )
        if suffix and (surname_processed or given_processed):
            processed_names['suffix'] = suffix[:CROSSREF_SUFFIX_LIMIT].strip()

        return processed_names
コード例 #2
0
ファイル: crossref.py プロジェクト: erinspace/osf.io
    def _process_crossref_name(self, contributor):
        # Adapted from logic used in `api/citations/utils.py`
        # If the user has a family and given name, use those
        if contributor.family_name and contributor.given_name:
            given = contributor.given_name
            middle = contributor.middle_names
            family = contributor.family_name
            suffix = contributor.suffix
        else:
            names = impute_names(contributor.fullname)
            given = names.get('given')
            middle = names.get('middle')
            family = names.get('family')
            suffix = names.get('suffix')

        given_name = ' '.join([given, middle]).strip()
        given_stripped = remove_control_characters(given_name)
        # For crossref, given_name is not allowed to have numbers or question marks
        given_processed = ''.join(
            [char for char in given_stripped if (not char.isdigit() and char != '?')]
        )
        surname_processed = remove_control_characters(family)

        surname = surname_processed or given_processed or contributor.fullname
        processed_names = {'surname': surname[:CROSSREF_SURNAME_LIMIT].strip()}
        if given_processed and surname_processed:
            processed_names['given_name'] = given_processed[:CROSSREF_GIVEN_NAME_LIMIT].strip()
        if suffix and (surname_processed or given_processed):
            processed_names['suffix'] = suffix[:CROSSREF_SUFFIX_LIMIT].strip()

        return processed_names
コード例 #3
0
ファイル: crossref.py プロジェクト: erinspace/osf.io
    def build_posted_content(self, preprint, element, status, include_relation):
        """Build the <posted_content> element for a single preprint
        preprint - preprint to build posted_content for
        element - namespace element to use when building parts of the XML structure
        """
        status = status or self.get_status(preprint)
        posted_content = element.posted_content(
            element.group_title(preprint.provider.name),
            type='preprint'
        )
        if status == 'public':
            posted_content.append(element.contributors(*self._crossref_format_contributors(element, preprint)))

        title = element.title(remove_control_characters(preprint.node.title)) if status == 'public' else element.title('')
        posted_content.append(element.titles(title))

        posted_content.append(element.posted_date(*self._crossref_format_date(element, preprint.date_published)))

        if status == 'public':
            posted_content.append(element.item_number('osf.io/{}'.format(preprint._id)))

            if preprint.node.description:
                posted_content.append(
                    element.abstract(element.p(remove_control_characters(preprint.node.description)), xmlns=JATS_NAMESPACE))

            if preprint.license and preprint.license.node_license.url:
                posted_content.append(
                    element.program(
                        element.license_ref(preprint.license.node_license.url,
                                            start_date=preprint.date_published.strftime('%Y-%m-%d')),
                        xmlns=CROSSREF_ACCESS_INDICATORS
                    )
                )
            else:
                posted_content.append(
                    element.program(xmlns=CROSSREF_ACCESS_INDICATORS)
                )

            if preprint.node.preprint_article_doi and include_relation:
                posted_content.append(
                    element.program(
                        element.related_item(
                            element.intra_work_relation(
                                preprint.node.preprint_article_doi,
                                **{'relationship-type': 'isPreprintOf', 'identifier-type': 'doi'}
                            )
                        ), xmlns=CROSSREF_RELATIONS
                    )
                )

        doi = self.build_doi(preprint)
        doi_data = [
            element.doi(doi),
            element.resource(settings.DOMAIN + preprint._id)
        ]
        posted_content.append(element.doi_data(*doi_data))

        return posted_content
コード例 #4
0
ファイル: crossref.py プロジェクト: mdicgovbr/osf.io
    def build_posted_content(self, preprint, element, status, include_relation):
        """Build the <posted_content> element for a single preprint
        preprint - preprint to build posted_content for
        element - namespace element to use when building parts of the XML structure
        """
        status = status or self.get_status(preprint)
        posted_content = element.posted_content(
            element.group_title(preprint.provider.name),
            type='preprint'
        )
        if status == 'public':
            posted_content.append(element.contributors(*self._crossref_format_contributors(element, preprint)))

        title = element.title(remove_control_characters(preprint.title)) if status == 'public' else element.title('')
        posted_content.append(element.titles(title))

        posted_content.append(element.posted_date(*self._crossref_format_date(element, preprint.date_published)))

        if status == 'public':
            posted_content.append(element.item_number('osf.io/{}'.format(preprint._id)))

            if preprint.description:
                posted_content.append(
                    element.abstract(element.p(remove_control_characters(preprint.description)), xmlns=JATS_NAMESPACE))

            if preprint.license and preprint.license.node_license.url:
                posted_content.append(
                    element.program(
                        element.license_ref(preprint.license.node_license.url,
                                            start_date=preprint.date_published.strftime('%Y-%m-%d')),
                        xmlns=CROSSREF_ACCESS_INDICATORS
                    )
                )
            else:
                posted_content.append(
                    element.program(xmlns=CROSSREF_ACCESS_INDICATORS)
                )

            if preprint.article_doi and include_relation:
                posted_content.append(
                    element.program(
                        element.related_item(
                            element.intra_work_relation(
                                preprint.article_doi,
                                **{'relationship-type': 'isPreprintOf', 'identifier-type': 'doi'}
                            )
                        ), xmlns=CROSSREF_RELATIONS
                    )
                )

        doi = self.build_doi(preprint)
        doi_data = [
            element.doi(doi),
            element.resource(settings.DOMAIN + preprint._id)
        ]
        posted_content.append(element.doi_data(*doi_data))

        return posted_content
コード例 #5
0
ファイル: crossref.py プロジェクト: qa4osf/osf.io
    def _crossref_format_contributors(self, element, preprint):
        contributors = []
        for index, contributor in enumerate(
                preprint.node.visible_contributors):
            if index == 0:
                sequence = 'first'
            else:
                sequence = 'additional'
            name_parts = self._process_crossref_name(contributor)
            person = element.person_name(sequence=sequence,
                                         contributor_role='author')
            if name_parts.get('given_name'):
                person.append(element.given_name(name_parts['given_name']))
            person.append(element.surname(name_parts['surname']))
            if name_parts.get('suffix'):
                person.append(
                    element.suffix(
                        remove_control_characters(name_parts['suffix'])))
            if contributor.external_identity.get('ORCID'):
                orcid = contributor.external_identity['ORCID'].keys()[0]
                verified = contributor.external_identity['ORCID'].values(
                )[0] == 'VERIFIED'
                if orcid and verified:
                    person.append(
                        element.ORCID('https://orcid.org/{}'.format(orcid),
                                      authenticated='true'))
            contributors.append(person)

        return contributors
コード例 #6
0
ファイル: crossref.py プロジェクト: erinspace/osf.io
    def _crossref_format_contributors(self, element, preprint):
        contributors = []
        for index, contributor in enumerate(preprint.node.visible_contributors):
            if index == 0:
                sequence = 'first'
            else:
                sequence = 'additional'
            name_parts = self._process_crossref_name(contributor)
            person = element.person_name(sequence=sequence, contributor_role='author')
            if name_parts.get('given_name'):
                person.append(element.given_name(name_parts['given_name']))
            person.append(element.surname(name_parts['surname']))
            if name_parts.get('suffix'):
                person.append(element.suffix(remove_control_characters(name_parts['suffix'])))
            if contributor.external_identity.get('ORCID'):
                orcid = contributor.external_identity['ORCID'].keys()[0]
                verified = contributor.external_identity['ORCID'].values()[0] == 'VERIFIED'
                if orcid and verified:
                    person.append(
                        element.ORCID('https://orcid.org/{}'.format(orcid), authenticated='true')
                    )
            contributors.append(person)

        return contributors