Subversion Repositories pyptex

Rev

Rev 25 | Blame | Compare with Previous | Last modification | View Log | RSS feed

# -*- coding: utf-8 -*-

# Slovak ISO 690 formating template for PyPTeX system
# Copyright (C) 2008  Michal Abaffy <michal_abaffy@transcat-plm.com>
# Copyright (C) 2010  Jan Janech <jan.janech@kst.uniza.sk>
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from lib import Template, param, noparam, authortype, encodetoascii, insteadOf, useAgain
from lib.iso_690_2 import ISOFormat, isoentry

################################################################################
# SlovakBase
# ==========
#
# Sablona pre standardny sposob citovania podla upravenej normy STN ISO 690
# Pre citacie podla normy STN ISO 690 systemom "prvy udaj, rok" je nutne pouzit
# inu sablonu.
#   Pomocou konfiguracnych parametrov je mozne vytvarat pripustne normovane
# variacie tejto sablony.
#
# Poznamka: Podla normy ISO 690 sa tvoria bibliograficke odkazy, t.j. zaznamy
#           o tych dokumentoch, ktore sa skutocne pouzili pri pisani prace.
#           Skutocne pouzite zaznamy s bibliografickymi odkazmi sa umiestnuju
#           na konci hlavnej casti prace s nazvom "Zoznam bibliografickych odkazov".
#               Pod nazvom "Bibliografia" sa moze k praci pridat usporiadany zoznam
#           zaznamov o literature, ktora sa sice tyka predmetu prace, ale ktora
#           sa bezprostredne nepouzila na jej napisanie. V tomto pripade sa odporuca
#           pouzit usmernenia ISBD(G) -- General international standard
#           bibliographic description.
class SlovakBase(Template):
    _Params = {
        'autoothers': (bool, True),
        'sameauthoremdash': (bool, True),
    }
    
    _Format = ISOFormat

    class Config:
        __noentry__ = True

        ########################################################################
        # AuthorSeparator = {' -- ' | ', '}
        #   Ked sa pouzivaju cele krstne mena, ako separator sa ma pouit pomlcka
        #   V pripade ze sa pouzivaju inicialky, ako separator sa ma pouit ciarka
        AuthorSeparator     = ' -- '

        ########################################################################
        # SurnameStyle        = {'{\\scshape ' | '\\uppercase{'}
        #   Norma preferuje styl '\\uppercase{'. Styl '{\\scshape ' je tiez
        #   mozne pouzit. No potom je potrebne pouzivat \scshape na pisanie
        #   priezvisk v celom dokumente
        SurnameStyle        = '\\uppercase{'

        ########################################################################
        # MaxAuthorsCount     = { 1 | 2 | 3 | 6 }
        #   Norma pripusta maximalne 3 autorov pre jeden zaznam, pricom sa mozeme
        #   rozhodnut ci budeme uvadzat 1 alebo 2 alebo 3. Avsak v niektorych
        #   vedeckych komunitach sa uvadza az 6 autorov. Tento pristup nema vsak
        #   nijake opodstatnenie v ziadnej norme. No ak by sme sa dostali nahodou
        #   do takejto komunity, radsej tu neham takuto moznost ;)
        MaxAuthorsCount     = 3

        ########################################################################
        # etal              = { 'a i.' | 'a in\'{y}' | 'et al.' | 'et alli' }
        #   co sa ma napisat ked je v zazname uvedeny vacsi pocet autorov ako
        #   je hodnota MaxAuthorsCount
        etal                = 'a i.'

        ########################################################################
        # others              = 'a kol.'
        #   co sa ma napisat ked je v zazname uvedene 'and others'
        others              = 'a kol.'

        ########################################################################
        # ed                  = 'vyd.'
        #   preklad slova edition resp. skratky ed.
        ed                  = 'vyd.'

        ########################################################################
        # sineloco            = {None, 's.l.' | 'b.m.'}
        #   preklad slova sine loco (bez miesta), v pripade ze sa nastavi na None
        #   nepouzije sa tento sposob uvedenia neuvedeneho mesta tzn. chybajuce
        #   mesto sa jednoducho neuvedie
        sineloco            = 's.l.'

        ########################################################################
        # sinenomine          = {None, 's.n.' | 'b.v.'}
        #   preklad slova sine nomine (bez mena vydavatela), v pripade ze sa nastavi na None
        #   nepouzije sa tento sposob uvedenia neuvedeneho vydavatela tzn. chybajuci
        #   vydavatel sa jednoducho neuvedie
        sinenomine          = 's.n.'

        ########################################################################
        # sineanum            = {None, 's.a.' | 'b.r.'}
        #   preklad slova sine anum (bez roku), v pripade ze sa nastavi na None
        #   nepouzije sa tento sposob uvedenia neuvedeneho roku tzn. chybajuci
        #   rok sa jednoducho neuvedie
        sineanum            = 's.a.'

        ########################################################################
        # p                   = { 's.' | 'p.' }
        #   skratka pre stranu. pouzije sa pre pocet stran monografie resp.
        #   pre uvedenie strany na ktorej sa nachadza citacia vramci publikacie
        p                   = 's.'

        ########################################################################
        # p                   = { 's.' | 'p.' }
        #   skratka pre stranu. pouzije sa pre pocet stran monografie resp.
        #   pre uvedenie strany na ktorej sa nachadza citacia vramci publikacie
        p                   = 's.'

        ########################################################################
        # no                  = { '\\v{c}.~' | 'n$\\degree$' }
        #   skratka pre cislo. pouzije sa pre zapisanie cisla casopisu a.p. ak je
        #   v zazname uvedene len cislo, bez udania typu
        no                  = '\\v{c}.~'

        ########################################################################
        # vol                 = { 'zv.~' | 'vol.~' }
        #   skratka pre cislo. pouzije sa pre zapisanie cisla zvazku a.p. ak je
        #   v zazname uvedene len cislo, bez udania typu
        vol                  = 'zv.~'

        ########################################################################
        # chap               = { 'kap.' | 'chap.' }
        # sec                = { 'odd.' | 'sec.' }
        #   skratka pre cislo kapitoly. pouzije sa na specifikaciu umiestnenia
        #   prispevku v monografii
        chap                = 'kap.'
        sec                 = 'odd.'
        
        ########################################################################
        # techrepname       = { 'Technick\\\'a spr\\\'ava' }
        #   oznacenie pre technicku spravu.
        techrepname         = 'Technick\\\'a spr\\\'ava'
        
        ########################################################################
        # phdname           = { 'Dizerta\\v{c}n\\\'a pr\\\'aca' }
        #   oznacenie pre dizertacnu pracu.
        phdname             = 'Dizerta\\v{c}n\\\'a pr\\\'aca'

    class Labeling:
        __noentry__ = True

        def itemLabel(self):
            if 'author' in self:
                author = self['author']
                a = author
                if (None, 'others') in a:
                    a.remove((None, 'others'))
                if len(author) == 1:
                    lbl = encodetoascii(author[0][1])[:3].upper()
                else:
                    lbl = encodetoascii(''.join(
                        auth[1][0]
                            for auth in author[:4]
                                if auth[0] is not None
                    ))[:3].upper()
            else:
                title = self['title']
                lbl = encodetoascii(''.join(
                    t[0]
                        for t in title.split()
                            if t[0].isalpha()
                ))[:3].upper()
            lbl += "%s"%(self['year', ''][-2:])
            
            return lbl
            
    class Misc(Labeling, Config):
        __falldown__ = True

        @param(authortype)
        @isoentry('author')
        def author(self, out, value):
            thisauthor = ()
            akol = False
            for id, (name, surname) in enumerate(value):
                if (name, surname) == (None, 'others'):
                    akol = True
                elif name is None:
                    thisauthor += (surname, )
                else:
                    a  = self.SurnameStyle
                    a += surname
                    a += '}, '
                    a += name

                    thisauthor += (a, )
            if akol:
                thisauthor += (self.others, )

            if not hasattr(out, 'prevauthor'):
                out.prevauthor = ()

            if thisauthor == out.prevauthor and self._Params.sameauthoremdash:
                out.write('---')
            else:
                out.prevauthor = thisauthor
                count = len(thisauthor)
                if self._Params.autoothers:
                    if (akol and count-1 > self.MaxAuthorsCount) or (not akol and count > self.MaxAuthorsCount):
                        thisauthor = thisauthor[:self.MaxAuthorsCount] + (self.etal,)
                last = len(thisauthor)-1
                for id, a in enumerate(thisauthor):
                    if id < last and thisauthor[id+1] in (self.others, self.etal):
                        out.beginEntry('author', ' ')
                    else:
                        out.beginEntry('author', self.AuthorSeparator)

                    out.write(a)
            out.setBlockSeparator(':\n')

        @param(str)
        @isoentry('title')
        def title(self, out, value):
            if 'booktitle' not in self and 'journal' not in self:
                out.write('\\emph{')
            out.write(value)

            if 'subtitle' in self:
                out.setSeparator('~:~')
            else:
                if 'booktitle' not in self and 'journal' not in self:
                    out.write('}')

        @param(str)
        @isoentry('title')
        def subtitle(self, out, value):
            if 'title' not in self:
                if 'booktitle' not in self:
                    out.write('\\emph{')
            out.write(value)
            if not self.isin:
                out.write('}')

        @param(str)
        @isoentry('booktitle')
        def booktitle(self, out, value):
            out.write('In:~\\emph{')
            out.write(value)

            if 'booksubtitle' in self:
                out.setSeparator('~:~')
            else:
                out.write('}')

        @param(str)
        @isoentry('booktitle')
        def booksubtitle(self, out, value):
            if 'booktitle' not in self:
                out.write('In:~\\emph{')
            out.write(value)
            out.write('}')
        
        @param(str)
        @isoentry('media')
        def media(self, out, value):
            out.write('['+value+']')
        
        @param(str)
        @isoentry('editor')
        def editor(self, out, value):
            out.write(value)

        @param(str)
        @isoentry('edition')
        def edition(self, out, value):
            if value == '1':
                txtvalue = "Prv\\'{e}"
            elif value == '2':
                txtvalue = "Druh\\'{e}"
            elif value == '3':
                txtvalue = "Tretie"
            elif value == '4':
                txtvalue = "\\v{S}tvr\\'{e}"
            elif value == '5':
                txtvalue = "Piate"
            elif value == '6':
                txtvalue = "\\v{S}ieste"
            elif value == '7':
                txtvalue = "Siedme"
            elif value == '8':
                txtvalue = "\\^{O}sme"
            else:
                if value.isdigit():
                    txtvalue = "%s."%value
                else:
                    txtvalue = value

            out.write(txtvalue)
            out.write(' ')
            out.write(self.ed)

        @param(str)
        @isoentry('publisher')
        def address(self, out, value):
            if 'publisher' in self:
                out.write(value)
                out.setSeparator('~:~')
            else:
                if self.sinenomine is None:
                    out.write(value)
                    out.setSeparator('~:~')
                    out.beginEntry('published')
                    out.write(self.sinenomine)
                else:
                    out.write(value)

        @param(str)
        @isoentry('publisher')
        def location(self, out, value):
            if 'publisher' in self:
                out.write(value)
                out.setSeparator('~:~')
            else:
                if self.sinenomine is None:
                    out.write(value)
                    out.setSeparator('~:~')
                    out.beginEntry('published')
                    out.write(self.sinenomine)
                else:
                    out.write(value)

        @param(str)
        @isoentry('publisher')
        def publisher(self, out, value):
            if 'address' not in self and 'location' not in self and self.sineloco is not None:
                out.write('[')
                out.write(self.sineloco)
                out.write(']')
                out.setSeparator('~:~')
                out.beginEntry('published')
            out.write(value)

        @param(str)
        @isoentry('publisher')
        def month(self, out, value):
            out.write(value)
            if 'year' in self:
                out.setSeparator('~')

        @param(str)
        @isoentry('publisher')
        def year(self, out, value):
            if value == 's.a.':
                if self.sineanum is not None:
                    out.write(self.sineanum)
            else:
                out.write('\\oldstylenums{')
                out.write(value)
                out.write('}')

        @param(int)
        @isoentry('size')
        def pagescount(self, out, value):
            out.write(value)
            out.write('~')
            out.write(self.p)

        @param(str)
        @isoentry('edition', separator='; ')
        def series(self, out, value):
            out.write(value)

        @param(str)
        @isoentry('edition')
        def volume(self, out, value):
            if value.isdigit():
                out.write(self.vol)
            out.write(value)

        @param(str)
        @isoentry('edition')
        def number(self, out, value):
            if value.isdigit():
                out.write(self.no)
            out.write(value)

        @param(str)
        @isoentry('note')
        def note(self, out, value):
            out.write(value)

        @param(str)
        @isoentry('standardnumber')
        def isbn(self, out, value):
            out.write('ISBN~')
            out.write(value)
        
        @param(str)
        @isoentry('url')
        def url(self, out, value):
            out.write(u'\\\\Dostupné online: $<$')
            out.write(u'\\url{')
            out.write(value)
            out.write(u'}')
            out.write('$>$')
        
        ##########################

        def compareBy(self):
            if 'author' in self:
                return ''.join(i[1] for i in self['author']) + "%s"%self['year', '0000'] + self['title']
            else:
                return ''.join(i[0] for i in self['title'].split() if i[0].isalpha()) + "%s"%self['year', '0000'] + self['title']

    class Book(Misc):
        pass

    class InBook(Misc):
        @param(str)
        @isoentry('part')
        def chapter(self, out, value):
            out.write(self.chap)
            out.write('~')
            out.write(value)

        @isoentry('part')
        def section(self, out, value):
            out.write(self.sec)
            out.write('~')
            out.write(value)

        @param(str)
        @isoentry('part')
        def pages(self, out, value):
            out.write(self.p)
            out.write('~')
            out.write(value)

    class InProceedings(Misc):
        pass

    class Article(Misc):
        @param(str, insteadOf('booktitle'))
        @isoentry('booktitle')
        def journal(self, out, value):
            out.write('In:~\\emph{')
            out.write(value)

            if 'booksubtitle' in self:
                out.setSeparator('~:~')
            else:
                out.write('}')

        @param(str, insteadOf('isbn'))
        @isoentry('standardnumber')
        def issn(self, out, value):
            out.write('ISSN~')
            out.write(value)

    class PhdThesis(Misc):
        @param(str, insteadOf('publisher'))
        @isoentry('publisher')
        def school(self, out, value):
            out.write(value)
        
        @noparam(insteadOf('note'))
        @isoentry('note')
        def typenote(self, out):
            out.write(self.phdname)

    class TechReport(Misc):
        @param(str, insteadOf('publisher'))
        @isoentry('publisher')
        def institution(self, out, value):
            out.write(value)
        
        @noparam(insteadOf('note'))
        @isoentry('note')
        def typenote(self, out):
            out.write(self.techrepname)

class SlovakBaseNum(SlovakBase):
    class Labeling:
        __noentry__ = True

        def itemLabel(self):
            pass

        def compareBy(self):
            if 'author' in self:
                return ''.join(i[1] for i in self['author']) + "%s"%self['year', '0000'] + self['title']
            else:
                return '\xFF' + "%s"%self['year', '0000'] + self['title']

class Slovak(SlovakBase):
    class Config:
        __noentry__ = True

        AuthorSeparator     = ' -- '
        SurnameStyle        = '{\\scshape '
        MaxAuthorsCount     = 3
        etal                = 'a i.'
        others              = 'a kol.'
        ed                  = 'vyd.'
        sineloco            = 's.l.'
        sinenomine          = 's.n.'
        sineanum            = 's.a.'
        p                   = 's.'
        no                  = 'n$^\\circ$'
        vol                 = 'vol.'
        chap                = 'kap.'
        sec                 = 'odd.'
        techrepname         = 'Technick\\\'a spr\\\'ava'

class SlovakNum(SlovakBase):
    Labeling = useAgain(SlovakBaseNum.Labeling)
    Config = useAgain(Slovak.Config)