Example #1
0
    def __format_output(self, cita, biblio, bibcode, index):
        """

        :param cita:
        :param biblio:
        :param bibcode:
        :param index:
        :return:
        """
        # apsj is a special case, display biblio as csl has format, just adjust translate characters for LaTex
        if (self.csl_style == 'apsj') or (self.csl_style == 'ieee'):
            cita_author, cita_year = '', ''
            biblio_author = cita
            biblio_rest = biblio.replace(cita, '')
            # do not need this, but since we are sending the format all the fields, empty bibcode
            bibcode = ''
        else:
            cita_author, cita_year = self.__tokenize_cita(cita)
            biblio_author, biblio_rest = self.__tokenize_biblio(biblio)

        # encode author if latex format
        if (self.export_format == adsFormatter.latex):
            cita_author = encode_laTex_author(cita_author)
            biblio_author = encode_laTex_author(biblio_author)

            # some adjustments to the what is returned from CSL that we can not do with CSL
            cita_author = html_to_laTex(
                self.__update_author_etal_add_emph(cita_author))
            biblio_author, biblio_rest = self.__update_author_etal(
                biblio_author, biblio_rest, bibcode)
            biblio_author = html_to_laTex(biblio_author)
            biblio_rest = html_to_laTex(biblio_rest)
        else:
            biblio_author, biblio_rest = self.__update_author_etal(
                biblio_author, biblio_rest, bibcode)

        format_style = {
            'mnras':
            u'\\bibitem[\\protect\\citeauthoryear{{{}}}{{{}}}]{{{}}} {}{}',
            'icarus': u'\\bibitem[{}({})]{{{}}} {}{}',
            'soph': u'\\bibitem[{}({})]{{{}}}{}{}',
            'aastex': u'\\bibitem[{}({})]{{{}}} {}{}',
            'aspc': u'\\bibitem[{}({})]{{{}}} {}{}',
            'aasj': u'\\bibitem[{}({})]{{{}}} {}{}',
            'apsj': u'{}{}{}{}{}',
            'ieee': u'{}{}{}{}{}'
        }
        return format_style[self.csl_style].format(cita_author, cita_year,
                                                   bibcode, biblio_author,
                                                   biblio_rest)
Example #2
0
    def get(self, export_organizer=adsOrganizer.plain):
        """

        :param export_organizer: output format, default is plain
        :return: for adsOrganizer.plain returns the result of formatted records in a dict
        """
        results = []
        if (export_organizer == adsOrganizer.plain):
            num_docs = 0
            if (self.export_format
                    == adsFormatter.unicode) or (self.export_format
                                                 == adsFormatter.latex):
                num_docs = len(self.bibcode_list)
                for cita, item, bibcode, i in zip(
                        self.citation_item, self.bibliography.bibliography(),
                        self.bibcode_list, range(len(self.bibcode_list))):
                    results.append(
                        self.__format_output(
                            str(self.bibliography.cite(cita, '')), str(item),
                            bibcode, i + 1) + '\n')
            result_dict = {}
            result_dict[
                'msg'] = 'Retrieved {} abstracts, starting with number 1.'.format(
                    num_docs)
            result_dict['export'] = ''.join(result for result in results)
            return result_dict
        if (export_organizer == adsOrganizer.citation_bibliography):
            for cita, item, bibcode in zip(self.citation_item,
                                           self.bibliography.bibliography(),
                                           self.bibcode_list):
                results.append(bibcode + '\n' +
                               str(self.bibliography.cite(cita, '')) + '\n' +
                               str(item) + '\n')
            return ''.join(result for result in results)
        if (export_organizer == adsOrganizer.bibliography):
            for item in self.bibliography.bibliography():
                results.append(html_to_laTex(str(item)))
            return results
        return None