예제 #1
0
파일: doi.py 프로젝트: Kortemme-Lab/klab
    def convert_to_ris(self):
        d = self.to_dict()

        RIS = []

        doi_to_ris_record_type_mapping = {
            'Journal' : 'JOUR'
        }

        if doi_to_ris_record_type_mapping.get(d['RecordType']):
            RIS.append('TY  - %s' % doi_to_ris_record_type_mapping[d['RecordType']])
        else:
            raise Exception("The logic needed to parse records of type '%s' has not been implemented yet." % d['RecordType'])

        if d.get('Title'):
            RIS.append('T1  - %(Title)s' % d)

        for author in d['authors']:
            if author['MiddleNames']:
                first_names = ' '.join([author.get('FirstName')] + author['MiddleNames'].split())
            else:
                first_names = author.get('FirstName')
            if author['Surname']:
                RIS.append('A1  - %s, %s' % (author['Surname'], first_names))
            else:
                RIS.append('A1  - %s' % first_names)

        if d.get('PublicationName'):
            RIS.append('JF  - %(PublicationName)s' % d)
            if publication_abbreviations.get(d['PublicationName']):
                RIS.append('JA  - %s' % publication_abbreviations[d['PublicationName']])

        if d.get('Volume'):
            RIS.append('VL  - %(Volume)s' % d)

        if d.get('Issue'):
            RIS.append('IS  - %(Issue)s' % d)

        if d.get('StartPage'):
            RIS.append('SP  - %(StartPage)s' % d)

        if d.get('EndPage'):
            RIS.append('EP  - %(EndPage)s' % d)

        if d.get('DOI'):
            RIS.append('M3  - %(DOI)s' % d)
            RIS.append('UR  - http://dx.doi.org/%(DOI)s' % d)

        if d.get('PublicationDate'):
            RIS.append('Y1  - %(PublicationDate)s' % d)
        elif d.get('PublicationYear'):
            RIS.append('Y1  - %(PublicationYear)s' % d)

        RIS.append('ER  - ')
        return '\n'.join(RIS)
예제 #2
0
파일: ris.py 프로젝트: Kortemme-Lab/klab
    def format(self, abbreviate_journal = True, abbreviate_author_names = True, show_year = True, html = True, allow_errors = False):
        raise Exception('This function is deprecated in favor of PublicationInterface.to_string. Some functionality needs to be added to that function e.g. ReferralURL_link.')
        if self.errors and not allow_errors:
            if not self.quiet:
                colortext.error("There were parsing errors: %s" % self.errors)
            return None

        # Abbreviate the journal name
        journal = self.journal
        if abbreviate_journal and self.publication_type != "CHAP":
            journal = publication_abbreviations.get(self.journal, self.journal)

        # Abbreviate the authors' names
        authors_str = None
        if abbreviate_author_names:
            authors_str = ", ".join(self.get_author_names_in_short_format())
        else:
            raise Exception("This code needs to be written with whatever is needed.")

        # Create string for the publication year
        year_str = ""
        if show_year:
            year_str = ", %s" % self.year

        ReferralURL_link = ""
        if self.ReferralURL:
            ReferralURL_link = " <a class='publist' href='%s'>[free download]</a>" % self.ReferralURL

        titlesuffix = '.'
        if self.publication_type == "CHAP":
            titlesuffix = " in"

        # The entry format is fixed. This could be passed as a variable for different styles.
        entry = ""
        if self.volume:
            entry = self.volume
            if self.subtitle:
                entry += " (%s)" % self.subtitle
            if self.issue:
                entry += "(%s)" % self.issue

            pagerange = PublicationInterface.get_page_range_in_abbreviated_format(self.startpage, self.endpage)
            if pagerange:
                entry += ":%s" % pagerange
        else:
            if self.startpage and self.endpage and self.startpage.isdigit() and self.endpage.isdigit():
                if self.subtitle:
                    entry = " (%s)" % self.subtitle
                pagerange = PublicationInterface.get_page_range_in_abbreviated_format(self.startpage, self.endpage)
                if pagerange:
                    entry += ":%s" % pagerange

        s = ['%s. ' % authors_str]
        if html:
            if self.doi:
                s.append('%s%s %s %s%s.' % (self.title, titlesuffix, self.journal, entry, year_str))
                s.append('doi: <a class="publication_doi" href="http://dx.doi.org/%s">%s</a>''' % (self.doi, self.doi))
                s.append(ReferralURL_link)
            elif self.url:
                s.append('<a class="publication_link" href="%s">%s</a>%s' % (self.url, self.title, titlesuffix))
                s.append('%s %s%s.' % (self.journal, entry, year_str))
                s.append(ReferralURL_link)
            else:
                s.append('%s%s %s %s%s.' % (self.title, titlesuffix, self.journal, entry, year_str))
                s.append(ReferralURL_link)
        else:
            s.append('%s%s %s %s%s.' % (self.title, titlesuffix, self.journal, entry, year_str))
            if self.doi:
                s.append('doi: %s' % self.doi)
            elif self.url:
                s.append('url: %s' % self.url)
        return " ".join(s)