def dump(self, data): AuthorsXMLConverter = Converters.get('authorsxml') AuthorsXML = dumps(data, AuthorsXMLConverter) organizations_list = [] authors_list = [] root = ET.fromstring(AuthorsXML) # save affiliations for organization in root.findall('{%s}organizations/{%s}Organization' % (NAMESPACES['cal'], NAMESPACES['foaf'])): org_id = organization.attrib['id'] org_name = '' if organization.find('{%s}name' % NAMESPACES['foaf']) is not None: org_name = organization.find('{%s}name' % NAMESPACES['foaf']).text or '' organizations_list.append([org_id, org_name.encode('utf-8')]) # save authors for author in root.findall('{%s}authors/{%s}Person' % (NAMESPACES['cal'], NAMESPACES['foaf'])): author_name = '' author_affiliations = [] if author.find('{%s}authorNamePaper' % NAMESPACES['cal']) is not None: author_name = author.find('{%s}authorNamePaper' % NAMESPACES['cal']).text or '' for affil in author.findall('{%(cal)s}authorAffiliations/{%(cal)s}authorAffiliation' % {'cal': NAMESPACES['cal']}): author_affiliations.append(affil.attrib['organizationid']) authors_list.append([author_name.encode('utf-8'), author_affiliations]) myout = '' for author in authors_list: myout += '\\author{' + str(escape_latex(author[0])) + '$^{' + ','.join(author[1]) + '}$}\r\n' for org in organizations_list: myout += '\\affiliation{$^{' + str(org[0]) + '}$ ' + str(escape_latex(org[1])) + '}\r\n' return myout
def dump(self, data): AuthorsXMLConverter = Converters.get('authorsxml') AuthorsXML = dumps(data, AuthorsXMLConverter) organizations_list = [] authors_list = [] root = ET.fromstring(AuthorsXML) # save affiliations for organization in root.findall( '{%s}organizations/{%s}Organization' % (NAMESPACES['cal'], NAMESPACES['foaf'])): org_id = organization.attrib['id'] org_name = '' if organization.find('{%s}name' % NAMESPACES['foaf']) is not None: org_name = organization.find( '{%s}name' % NAMESPACES['foaf']).text or '' organizations_list.append([org_id, org_name.encode('utf-8')]) # save authors for author in root.findall('{%s}authors/{%s}Person' % (NAMESPACES['cal'], NAMESPACES['foaf'])): author_name = '' author_affiliations = [] if author.find('{%s}authorNamePaper' % NAMESPACES['cal']) is not None: author_name = author.find( '{%s}authorNamePaper' % NAMESPACES['cal']).text or '' for affil in author.findall( '{%(cal)s}authorAffiliations/{%(cal)s}authorAffiliation' % {'cal': NAMESPACES['cal']}): author_affiliations.append(affil.attrib['organizationid']) authors_list.append( [author_name.encode('utf-8'), author_affiliations]) myout = '' for author in authors_list: myout += '\\author{' + str(escape_latex( author[0])) + '$^{' + ','.join(author[1]) + '}$}\r\n' for org in organizations_list: myout += '\\affiliation{$^{' + str(org[0]) + '}$ ' + str( escape_latex(org[1])) + '}\r\n' return myout
def dump(self, data): AuthorsXMLConverter = Converters.get('authorsxml') AuthorsXML = dumps(data, AuthorsXMLConverter) root = ET.fromstring(AuthorsXML) tree = ET.ElementTree(root) res = self.dictionary_to_list(tree.getroot()) collaboration_author_list_values = res['collaborationauthorlist']['value'] organization_dict = dict() author_list = [] for element in collaboration_author_list_values: key = element.keys()[0] # if the value of the key is empty, start next loop cycle if element[key]['value'] is None: continue if key == self.cal + 'organizations': organization_dict = self.get_organizations(element[key]['value']) elif key == self.cal + 'authors': author_list = self.get_authors(element[key]['value']) clusters = [] organization_codes = [] for element in author_list: if len(element[1]) >= 1: organization_code = element[1][0] other_affiliations = element[1][1:] author = [element[0]] if other_affiliations: author.extend(other_affiliations) # if this organization already exists in the cluster if organization_code in organization_codes: for cluster in clusters: if cluster[0] == organization_code: cluster.append(author) break else: organization_codes.append(organization_code) clusters.append([organization_code, author]) myout = "" myout += "\\documentclass[a4paper,12pt]{article}\r\n" myout += "\\usepackage[utf8]{inputenc}\r\n" myout += "\\begin{document}\r\n" myout += "\\begin{center}\r\n" myout += "{\\Large Collaboration}\\\\\r\n" myout += "\\vspace{2mm}\r\n%\r\n" primary_output_string = "" secondary_affiliation_count = 1 secondary_affiliations = "" secondary_affiliations_pos = {} for data in clusters: primary_output = [] organization_code = data[0] for author in data[1:]: name = " " + str(escape_latex(author[0][0])) + '~' + str(escape_latex(author[0][1])) if len(author) > 1: for sec_affiliation in author[1:]: if sec_affiliation in organization_dict.keys(): if organization_dict[sec_affiliation] in secondary_affiliations_pos.keys(): name += "$\\,$\\footnotemark[" + str(secondary_affiliations_pos[organization_dict[sec_affiliation]]) + "]" else: name += "$\\,$\\footnotemark[" + str(secondary_affiliation_count) + "]" secondary_affiliations += "%\r\n\\footnotetext[" + str(secondary_affiliation_count) + "]{" + str(escape_latex(organization_dict[sec_affiliation])) + "}\r\n" secondary_affiliations_pos[organization_dict[sec_affiliation]] = secondary_affiliation_count secondary_affiliation_count += 1 primary_output.append(name) if organization_dict.get(data[0]): organization = organization_dict.get(data[0]) else: organization = UNKNOWN_AFFILIATION primary_output_string += ',\r\n'.join(primary_output) + " \\\\\r\n{\\em \\small " + str(escape_latex(organization)) + "} \\\\[0.2cm]\r\n%\r\n" myout += primary_output_string myout += "\\end{center}\r\n" myout += "\\setcounter{footnote}{0}\r\n" myout += secondary_affiliations myout += "\\end{document}\r\n" return myout
def dump(self, data): AuthorsXMLConverter = Converters.get('authorsxml') AuthorsXML = dumps(data, AuthorsXMLConverter) root = ET.fromstring(AuthorsXML) tree = ET.ElementTree(root) res = self.dictionary_to_list(tree.getroot()) collaboration_author_list_values = res['collaborationauthorlist'][ 'value'] organization_dict = dict() author_list = [] for element in collaboration_author_list_values: key = element.keys()[0] # if the value of the key is empty, start next loop cycle if element[key]['value'] is None: continue if key == self.cal + 'organizations': organization_dict = self.get_organizations( element[key]['value']) elif key == self.cal + 'authors': author_list = self.get_authors(element[key]['value']) clusters = [] organization_codes = [] for element in author_list: if len(element[1]) >= 1: organization_code = element[1][0] other_affiliations = element[1][1:] author = [element[0]] if other_affiliations: author.extend(other_affiliations) # if this organization already exists in the cluster if organization_code in organization_codes: for cluster in clusters: if cluster[0] == organization_code: cluster.append(author) break else: organization_codes.append(organization_code) clusters.append([organization_code, author]) myout = "" myout += "\\documentclass[a4paper,12pt]{article}\r\n" myout += "\\usepackage[utf8]{inputenc}\r\n" myout += "\\begin{document}\r\n" myout += "\\begin{center}\r\n" myout += "{\\Large Collaboration}\\\\\r\n" myout += "\\vspace{2mm}\r\n%\r\n" primary_output_string = "" secondary_affiliation_count = 1 secondary_affiliations = "" secondary_affiliations_pos = {} for data in clusters: primary_output = [] organization_code = data[0] for author in data[1:]: name = " " + str(escape_latex(author[0][0])) + '~' + str( escape_latex(author[0][1])) if len(author) > 1: for sec_affiliation in author[1:]: if sec_affiliation in organization_dict.keys(): if organization_dict[ sec_affiliation] in secondary_affiliations_pos.keys( ): name += "$\\,$\\footnotemark[" + str( secondary_affiliations_pos[ organization_dict[sec_affiliation]] ) + "]" else: name += "$\\,$\\footnotemark[" + str( secondary_affiliation_count) + "]" secondary_affiliations += "%\r\n\\footnotetext[" + str( secondary_affiliation_count) + "]{" + str( escape_latex( organization_dict[sec_affiliation]) ) + "}\r\n" secondary_affiliations_pos[organization_dict[ sec_affiliation]] = secondary_affiliation_count secondary_affiliation_count += 1 primary_output.append(name) if organization_dict.get(data[0]): organization = organization_dict.get(data[0]) else: organization = UNKNOWN_AFFILIATION primary_output_string += ',\r\n'.join( primary_output) + " \\\\\r\n{\\em \\small " + str( escape_latex(organization)) + "} \\\\[0.2cm]\r\n%\r\n" myout += primary_output_string myout += "\\end{center}\r\n" myout += "\\setcounter{footnote}{0}\r\n" myout += secondary_affiliations myout += "\\end{document}\r\n" return myout