format an author affiliation from details
322687
def text_from_affiliation_elements(department, institution, city, country):
    ""
    return ', '.join(element for element in [department, institution, city, country] if element)
1315593
def authors2marc(self, key, value):
    
    value = force_list(value)

    def _get_ids(value):
        ids = {
            'i': [],
            'j': [],
        }
        if value.get('ids'):
            for _id in value.get('ids'):
                if _id.get('schema') == 'INSPIRE ID':
                    ids['i'].append(_id.get('value'))
                elif _id.get('schema') == 'ORCID':
                    ids['j'].append('ORCID:' + _id.get('value'))
                elif _id.get('schema') == 'JACOW':
                    ids['j'].append(_id.get('value'))
                elif _id.get('schema') == 'CERN':
                    ids['j'].append('CCID-' + _id.get('value')[5:])
        return ids

    def _get_affiliations(value):
        return [
            aff.get('value') for aff in value.get('affiliations', [])
        ]

    def _get_affiliations_identifiers(value):
        return [
            u'{}:{}'.format(aff.get('schema'), aff.get('value')) for aff in value.get('affiliations_identifiers', [])
        ]

    def _get_inspire_roles(value):
        values = force_list(value.get('inspire_roles'))
        return ['ed.' for role in values if role == 'editor']

    def _get_raw_affiliations(value):
        return [
            aff.get('value') for aff in value.get('raw_affiliations', [])
        ]

    def get_value_100_700(value):
        ids = _get_ids(value)
        return {
            'a': value.get('full_name'),
            'e': _get_inspire_roles(value),
            'q': value.get('alternative_names'),
            'i': ids.get('i'),
            'j': ids.get('j'),
            'm': value.get('emails'),
            't': _get_affiliations_identifiers(value),
            'u': _get_affiliations(value),
            'v': _get_raw_affiliations(value),
        }

    def get_value_701(value):
        ids = _get_ids(value)
        return {
            'a': value.get('full_name'),
            'q': value.get('alternative_names'),
            'i': ids.get('i'),
            'j': ids.get('j'),
            'u': _get_affiliations(value),
            'v': _get_raw_affiliations(value),
        }

    if len(value) > 1:
        self["700"] = []
        self["701"] = []

    for author in value[1:]:
        is_supervisor = 'supervisor' in author.get('inspire_roles', [])
        if is_supervisor:
            self["701"].append(get_value_701(author))
        else:
            self["700"].append(get_value_100_700(author))
    return get_value_100_700(value[0])
1109312
def _format_pr(pr_):
    '''
    
    '''
    ret = {'id': pr_.get('id'),
           'pr_number': pr_.get('number'),
           'state': pr_.get('state'),
           'title': pr_.get('title'),
           'user': pr_.get('user').get('login'),
           'html_url': pr_.get('html_url'),
           'base_branch': pr_.get('base').get('ref')}

    return ret
589786
def set_author(self):
        """"""
        try:
            self.author = self.soup.find('author').string
        except AttributeError:
            self.author = None
577600
def generate_additional_context(self, matching_datasets):
        """"""
        top_tags = Tag.objects.filter(
            dataset__in=matching_datasets
        ).annotate(
            tag_count=Count('word')
        ).order_by('-tag_count')[:3]

        top_authors = Dataset.objects.filter(
            id__in=matching_datasets
        ).values('uploaded_by').annotate(
            author_count=Count('uploaded_by')
        ).order_by('-author_count')[:3]

        for author in top_authors:
            author['fullName'] = grab_names_from_emails([
                author['uploaded_by']
            ])[author['uploaded_by']]

        return {
            'top_tags': top_tags,
            'top_authors': top_authors
        }
657700
def __reorganize_authors(authors):
        
        # String SHOULD be semi-colon separated names.
        l = []
        s = authors.split(";")
        for author in s:
            try:
                l.append({"name": author.strip()})
            except AttributeError:
                logger_noaa_lpd.warning("reorganize_authors: AttributeError: authors incorrectly formatted")
        return l
1304589
def make_article_info_citation(self):
        
        citation_div = etree.Element('div', {'id': 'article-citation'})
        b = etree.SubElement(citation_div, 'b')
        b.text = 'Citation: '

        #Add author stuff to the citation
        authors = self.article.root.xpath("./front/article-meta/contrib-group/contrib[@contrib-type='author']")
        for author in authors:
            author_index = authors.index(author)
            #At the 6th author, simply append an et al., then stop iterating
            if author_index == 5:
                append_new_text(citation_div, 'et al.', join_str='')
                break
            else:
                #Check if the author contrib has a collab
                collab = author.find('collab')
                if collab is not None:
                    collab_copy = deepcopy(collab)
                    for contrib_group in collab_copy.findall('contrib_group'):
                        remove(contrib_group)
                    append_all_below(citation_div, collab, join_str='')
                else:  # Author element is not a collab
                    name = author.find('name')
                    #Note that this does not support eastern names
                    #Grab the surname information
                    surname = name.find('surname')
                    given_names = name.find('given-names')
                    suffix = name.find('suffix')
                    append_new_text(citation_div, surname.text, join_str='')
                    #Make initials from the given-name information
                    if given_names is not None:
                        #Add a space
                        append_new_text(citation_div, ' ', join_str='')
                        #Split by whitespace and take first character
                        given_initials = [i[0] for i in given_names.text.split() if i]
                        for initial in given_initials:
                            append_new_text(citation_div, initial, join_str='')
                    #If there is a suffix, add its text, but don't include the
                    #trailing period if there is one
                    if suffix is not None:
                        #Add a space
                        append_new_text(citation_div, ' ', join_str='')
                        suffix_text = suffix.text
                        #Check for the trailing period
                        if suffix_text[-1] == '.':
                            suffix_text = suffix_text[:-1]
                        append_new_text(citation_div, suffix_text, join_str='')
                #If this is not the last author to be added, add a ", "
                #This is satisfied by being less than the 6th author, or less
                #than the length of the author_list - 1
                if author_index < 5 or author_index < len(author_list) -1:
                    append_new_text(citation_div, ', ', join_str='')
        #Add Publication Year to the citation
        #Find pub-date elements, use pub-type=collection, or else pub-type=ppub
        d = './front/article-meta/pub-date'
        coll = self.article.root.xpath(d + "[@pub-type='collection']")
        ppub = self.article.root.xpath(d + "[@pub-type='ppub']")
        if coll:
            pub_year = coll[0].find('year').text
        elif ppub:
            pub_year = ppub[0].find('year').text
        append_new_text(citation_div, ' ({0}) '.format(pub_year), join_str='')
        #Add the Article Title to the Citation
        #As best as I can tell from the reference implementation, they
        #serialize the article title to text-only, and expunge redundant spaces
        #This might need later review
        article_title = self.article.root.xpath('./front/article-meta/title-group/article-title')[0]
        article_title_text = serialize(article_title)
        normalized = ' '.join(article_title_text.split())  # Remove redundant whitespace
        #Add a period unless there is some other valid punctuation
        if normalized[-1] not in '.?!':
            normalized += '.'
        append_new_text(citation_div, normalized + ' ', join_str='')
        #Add the article's journal name using the journal-id of type "nlm-ta"
        journal = self.article.root.xpath("./front/journal-meta/journal-id[@journal-id-type='nlm-ta']")
        append_new_text(citation_div, journal[0].text + ' ', join_str='')
        #Add the article's volume, issue, and elocation_id  values
        volume = self.article.root.xpath('./front/article-meta/volume')[0].text
        issue = self.article.root.xpath('./front/article-meta/issue')[0].text
        elocation_id = self.article.root.xpath('./front/article-meta/elocation-id')[0].text
        form = '{0}({1}): {2}. '.format(volume, issue, elocation_id)
        append_new_text(citation_div, form, join_str='')
        append_new_text(citation_div, 'doi:{0}'.format(self.article.doi), join_str='')

        return citation_div
254359
private static CSLName[] toAuthors(List<Map<String, Object>> authors) {
		CSLName[] result = new CSLName[authors.size()];
		int i = 0;
		for (Map<String, Object> a : authors) {
			CSLNameBuilder builder = new CSLNameBuilder();
			if (a.containsKey(FIELD_FIRSTNAME)) {
				builder.given(strOrNull(a.get(FIELD_FIRSTNAME)));
			}
			if (a.containsKey(FIELD_LASTNAME)) {
				builder.family(strOrNull(a.get(FIELD_LASTNAME)));
			}
			builder.parseNames(true);
			result[i] = builder.build();
			++i;
		}
		return result;
	}
420371
def set_itunes_author_name(self):
        """"""
        try:
            self.itunes_author_name = self.soup.find('itunes:author').string
        except AttributeError:
            self.itunes_author_name = None
6845
function splitAuthor(author) {
	return author
		.split(/\s*[,\.\s]\s*/)
		.filter(function(i) { return !!i }) // Strip out blanks
		.filter(function(i) { return !/^[0-9]+(st|nd|rd|th)$/.test(i) }); // Strip out decendent numerics (e.g. '1st', '23rd')
}
1271075
def author_tokenize(name):
    """"""
    phrases = scan_author_string_for_phrases(name)
    res = {'lastnames': [], 'nonlastnames': []}
    for key, tokens in phrases.items():
        lst = res.get(key)
        if lst is None:
            continue
        for token in tokens:
            if len(token) == 1:
                lst.append(NameInitial(token))
            else:
                lst.append(NameToken(token))
    return res
1338195
def authors(self, *usernames):
        
        if len(usernames) == 1:
            return self.filter(**{"author__{}".format(User.USERNAME_FIELD): usernames[0]})
        else:
            return self.filter(**{"author__{}__in".format(User.USERNAME_FIELD): usernames})
284153
def set_author(self, author, email=''):
        """"""
        self.author = author
        self.email = email
65809
def _Summarize(user_info):
  """"""
  return "Username: %s\nIs Admin: %s" % (
      user_info.username,
      user_info.user_type == api_user.ApiGrrUser.UserType.USER_TYPE_ADMIN)
221397
def build_contributors(authors, contrib_type, competing_interests=None):
    

    contributors = []

    for author in authors:
        contributor = None
        author_contrib_type = contrib_type

        surname = author.get("surname")
        given_name = author.get("given-names")
        collab = author.get("collab")

        # Small hack for on-behalf-of type when building authors
        #  use on-behalf-of as the contrib_type
        if author.get("type") and author.get("type") == "on-behalf-of":
            collab = author.get("on-behalf-of")
            author_contrib_type = "on-behalf-of"

        if surname or collab:
            contributor = ea.Contributor(author_contrib_type, surname, given_name, collab)

        utils.set_attr_if_value(contributor, 'suffix', author.get('suffix'))

        contributor.group_author_key = author.get("group-author-key")
        contributor.orcid = author.get("orcid")
        contributor.corresp = bool(author.get("corresp"))
        if author.get("equal-contrib") == "yes":
            contributor.equal_contrib = True

        # Add contributor affiliations
        for aff in author.get("affiliations", []):
            affiliation = ea.Affiliation()
            affiliation.text = utils.text_from_affiliation_elements(
                aff.get("dept"),
                aff.get("institution"),
                aff.get("city"),
                aff.get("country"))
            # fall back if no other fields are set take the text content
            if affiliation.text == '':
                affiliation.text = aff.get("text")
            contributor.set_affiliation(affiliation)

        # competing interests / conflicts
        if (competing_interests and author.get("references")
            and "competing-interest" in author.get("references")):
            for ref_id in author["references"]["competing-interest"]:
                for competing_interest in competing_interests:
                    if competing_interest.get("text") and competing_interest.get("id") == ref_id:
                        clean_text = utils.remove_tag('p', competing_interest.get("text"))
                        contributor.set_conflict(clean_text)

        # Finally add the contributor to the list
        if contributor:
            contributors.append(contributor)

    return contributors
204863
def tblRefAuthors 
      @headers = %w{RefID PersonID SeqNum AuthorCount LastUpdate ModifiedBy}
      sql = []
      @name_collection.ref_collection.collection.each do |r| 
        r.authors.each_with_index do |x, i|
          cols = {
            RefID: r.id,
            PersonID: x.id,
            SeqNum: i + 1,
            AuthorCount: r.authors.size + 1,
            LastUpdate: @time,
            ModifiedBy: @authorized_user_id
          }
          sql << sql_insert_statement('tblRefAuthors', cols) 
        end
      end
      sql.join("\n")
    end
1337762
private function loadAuthorDetails($author)
    {
        if (is_array($author) && is_array(array_values($author)[0])) {
            return $author;
        }

        if (!is_array($author)) {
            $tmp = $author;
            $author = [];
            $author[] = $tmp;
        }

        $authors = [];
        foreach ($author as $acronym) {
            if (isset($this->author[$acronym])) {
                $key = $this->author[$acronym];
                $authors[$acronym] = $this->meta[$key];
            } else {
                $authors[$acronym]["acronym"] = $acronym;
            }
        }

        return $authors;
    }