Exemple #1
0
    def __update_data(self):
        """
        Update the container-title if needed for the specific style
        also apply latex encoding if needed for both title and container-title
        also for icarus if there is page range, assign it to PMCID

        :return:
        """
        # for mnras we need abbreviation of the journal names
        # available from adsutils
        if (self.csl_style == 'mnras'):
            for data in self.for_cls:
                data['container-title-short'] = Format(None).get_pub_abbrev(
                    data['bibstem'])
        elif (self.csl_style == 'aastex') or (self.csl_style
                                              == 'aasj') or (self.csl_style
                                                             == 'aspc'):
            # use macro (default)
            if self.journal_format == adsJournalFormat.macro or self.journal_format == adsJournalFormat.default:
                journal_macros = dict([
                    (k, v) for k, v in
                    current_app.config['EXPORT_SERVICE_AASTEX_JOURNAL_MACRO']
                ])
                for data in self.for_cls:
                    data['container-title'] = journal_macros.get(
                        Format(None).get_bibstem(data['bibstem']),
                        encode_laTex(data['container-title']))
                    data['title'] = encode_laTex(data['title'])
            elif self.journal_format == adsJournalFormat.abbreviated:
                for data in self.for_cls:
                    data['container-title'] = Format(None).get_pub_abbrev(
                        data['bibstem'])
                    data['title'] = encode_laTex(data['title'])
            elif self.journal_format == adsJournalFormat.full:
                for data in self.for_cls:
                    data['container-title'] = encode_laTex(
                        data['container-title'])
                    data['title'] = encode_laTex(data['title'])
        # for SoPh we use journal abbreviation for some special journals only
        elif (self.csl_style == 'soph'):
            journal_abbrevation = current_app.config[
                'EXPORT_SERVICE_SOPH_JOURNAL_ABBREVIATION']
            for data in self.for_cls:
                data['container-title'] = journal_abbrevation.get(
                    Format(None).get_bibstem(data['bibstem']),
                    encode_laTex(data['container-title']))
        # for the rest just run title and container-title through latex encoding
        elif (self.csl_style == 'icarus') or (self.csl_style == 'apsj'):
            for data in self.for_cls:
                data['container-title'] = encode_laTex(data['container-title'])
                data['title'] = encode_laTex(data['title'])
        if (self.csl_style == 'icarus'):
            for data in self.for_cls:
                if len(data['page']) > 0:
                    data['PMCID'] = data['page']
Exemple #2
0
    def __init__(self, custom_format):
        """

        :param custom_format:
        """
        Format.__init__(self, None)
        self.custom_format = custom_format
        self.export_format = adsFormatter.unicode
        self.line_length = 80
        self.header = ''
        self.footer = ''
        self.enumeration = False
        self.__parse()
    def __get_journal(self, a_doc, journalformat):
        """
        let client decide on the format of journal, macro if one is available, abbreviated journal name, or full journal name
        note that for doctype = software this field is ignored

        :param a_doc:
        :param journalformat
        :return:
        """
        if a_doc.get('doctype', '') == 'software':
            return None

        # use macro (default)
        if journalformat == adsJournalFormat.macro or journalformat == adsJournalFormat.default:
            journal_macros = dict([
                (k, v) for k, v in
                current_app.config['EXPORT_SERVICE_AASTEX_JOURNAL_MACRO']
            ])
            return journal_macros.get(
                self.get_bibstem(a_doc.get('bibstem', '')),
                encode_laTex(''.join(a_doc.get('pub', ''))))
        elif journalformat == adsJournalFormat.abbreviated:
            return Format(None).get_pub_abbrev(a_doc.get('bibstem', ''))
        elif journalformat == adsJournalFormat.full:
            return encode_laTex(''.join(a_doc.get('pub', '')))
    def __init__(self, from_solr, keyformat):
        """

        :param keyformat:
        """
        Format.__init__(self, from_solr)
        self.keyformat = keyformat
        self.parsed_spec = []
        for m in self.REGEX_KEY.finditer(self.keyformat):
            self.parsed_spec.append(
                tuple((m.start(1), m.group(1),
                       self.__get_solr_field(m.group(1)))))
        self.enumeration = False
        matches = self.REGEX_ENUMERATION.findall(self.keyformat)
        if (len(matches) >= 1):
            self.enumeration = True
            self.keyformat = self.keyformat.replace(self.ENUMERATION_KEY, '')
        self.enumerated_keys = []
Exemple #5
0
 def test_format_no_num_docs(self):
     solr_data = \
         {
            "responseHeader":{
               "status":1,
               "QTime":1,
               "params":{
                  "sort":"date desc",
                  "fq":"{!bitset}",
                  "rows":"19",
                  "q":"*:*",
                  "start":"0",
                  "wt":"json",
                  "fl":"author,title,year,date,pub,pub_raw,issue,volume,page,page_range,aff,doi,abstract,citation_count,read_count,bibcode,identification,copyright,keyword,doctype,reference,comment,property,esources,data"
               }
            }
         }
     format_export = Format(solr_data)
     assert(format_export.get_num_docs() == 0)
    def __init__(self, custom_format):
        """

        :param custom_format:
        """
        Format.__init__(self, None)
        self.parsed_spec = []
        self.from_cls = {}
        self.author_count = {}
        self.custom_format = custom_format
        self.export_format = adsFormatter.unicode
        self.line_length = 0
        self.header = ''
        self.footer = ''
        self.author_sep = ''
        self.markup_strip = False
        self.enumeration = False
        self.line_feed = self.__get_linefeed()
        self.__parse()
    def __get_journal(self, a_doc, journalformat):
        """
        let client decide on the format of journal, macro if one is available, abbreviated journal name, or full journal name
        note that for doctype = software this field is ignored

        :param a_doc:
        :param journalformat
        :return:
        """
        doctype = a_doc.get('doctype', '')

        if doctype == 'software':
            return None

        # apply user preference only if pub is assigned to journal field
        # pub is displayed for booktitle and how_published, in which case it should appears in full
        need_full_pub = [
            'inbook', 'proceedings', 'inproceedings', 'abstract', 'misc',
            'proposal', 'pressrelease', 'talk'
        ]
        if doctype in need_full_pub:
            return encode_laTex(''.join(a_doc.get('pub', '')))

        # use macro (default)
        if journalformat == adsJournalFormat.macro or journalformat == adsJournalFormat.default:
            journal_macros = dict([
                (k, v) for k, v in
                current_app.config['EXPORT_SERVICE_AASTEX_JOURNAL_MACRO']
            ])
            return journal_macros.get(
                self.get_bibstem(a_doc.get('bibstem', '')),
                encode_laTex(''.join(a_doc.get('pub', ''))))
        elif journalformat == adsJournalFormat.abbreviated:
            return Format(None).get_pub_abbrev(a_doc.get('bibstem', ''))
        elif journalformat == adsJournalFormat.full:
            return encode_laTex(''.join(a_doc.get('pub', '')))
Exemple #8
0
 def test_format_status(self):
     format_export = Format(solrdata.data)
     assert(format_export.get_status() == 0)