Пример #1
0
def test_build_dict(list_for_dict):
    """Test the list to dict function, based on a specific key."""
    dict_from_list = build_dict(list_for_dict, 'id')
    assert dict_from_list[0]['value'] == 'John'
    assert dict_from_list[1]['value'] == 'Mark'
    assert dict_from_list[2]['value'] == 'Bruce'

    dict_from_list = build_dict(list_for_dict, 'value')
    assert dict_from_list['John']['age'] == 20
    assert dict_from_list['Mark']['age'] == 27
    assert dict_from_list['Bruce']['age'] == 9
Пример #2
0
def test_build_dict(list_for_dict):
    """Test the list to dict function, based on a specific key."""
    dict_from_list = build_dict(list_for_dict, 'id')
    assert dict_from_list[0]['value'] == 'John'
    assert dict_from_list[1]['value'] == 'Mark'
    assert dict_from_list[2]['value'] == 'Bruce'

    dict_from_list = build_dict(list_for_dict, 'value')
    assert dict_from_list['John']['age'] == 20
    assert dict_from_list['Mark']['age'] == 27
    assert dict_from_list['Bruce']['age'] == 9
Пример #3
0
    def _get_authors_and_collab(self, article, dois):
        authors = []
        collaboration = []

        for author in article['authors']:
            if author['type'] == 'Person':
                author_affiliations = []
                if 'affiliations' in article and 'affiliationIds' in author:
                    affiliations = build_dict(article['affiliations'], 'id')
                    for aff_id in author['affiliationIds']:
                        author_affiliations.append(
                            {'value': affiliations[aff_id]['name']})

                surname = ''
                given_name = ''
                raw_name = ''
                if author.get('surname'):
                    surname = author.get('surname').replace('\u2009', ' ')
                if author.get('firstname'):
                    given_name = author.get('firstname').replace('\u2009', ' ')
                if author.get('name'):
                    raw_name = author.get('name').replace('\u2009', ' ')

                authors.append({
                    'surname': surname,
                    'given_names': given_name,
                    "raw_name": raw_name,
                    'affiliations': author_affiliations
                })

            elif author['type'] == 'Collaboration':
                collaboration.append(author['name'])

        if not authors:
            logger.error('No authors found for article %s.' % dois)

        return authors, collaboration