recordthesis.py 4.49 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# -*- coding: utf-8 -*-
""" invenio_tools.recordthesis

"""
from base import THESIS_DIR
from filters import CLEAN_THESIS_DEFENSE
from recordpubli import RecordPubli


class RecordThesis(RecordPubli):
    """MARC record describing a thesis.
    The relation between methods and MARC fields are the following::

                              |  CDS    | INSPIREP
        ----------------------+---------+----------
        these defense         | 500 a   |
        these level           | 502 a   |
        these director        | 700 a   |
        these universities    | 502 b   |
        ----------------------+---------+----------

    """
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    def authors_as_list(self):
        """The list of author(s) signing the publication.

        @rtype: list
        @return:
            - The list is empty when authors are not defined.

        """
        authors = []
        first_author = self.first_author()

        # NOTE
        # the content of the 700 field depend on the record type.
        # For thesis it also contains the name of the director
        if u"700" in self and isinstance(self[u"700"], dict):
            if not ("e" in self[u"700"] and self[u"700"]["e"] == THESIS_DIR):
                if "a" in self[u"700"]:
                    authors.append(self[u"700"]["a"])

        elif u"700" in self and isinstance(self[u"700"], list):
            for di in self[u"700"]:
                if "e" in di and di["e"] == THESIS_DIR:
                    continue

                if "a" in di:
                    author = di["a"]

                    # PROTECTION
                    # in most of the case the author is a string
                    # but it can be a list, e.g inspirehep.net/138663:
                    # [u'Zuniga, J.', u'(the A.N.T.ARES. Collaboration)']
                    if isinstance(author, unicode):
                        authors.append(di["a"])

                    elif isinstance(author, list):
                        for elt in author:
                            if REG_AUTHOR.match(elt):
                                authors.append(elt)
                                break

        # the first author is defined not the other one
        elif u"100" in self:
            authors.append(first_author)

        # sometime the first author is missing
        if len(authors) == 0:
            authors = [first_author]

        elif first_author != authors[0]:
            authors.insert(0, first_author)

        return authors

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
    def these_defense(self):
        """The defense date for a master/phd thesis.

        @rtype: unicode
        @return:
            - The format is '5 March 2012'.
            - The format is not standardize and can varies
              between records and between stores.
            - The value is not a standardize C{date}.
            - The filter L{CLEAN_THESIS_DEFENSE} is applied.

        """
        val = self._get(u"500", "a")
        return CLEAN_THESIS_DEFENSE(val)

    def these_level(self):
        """The level of the thesis.

        @rtype: unicode
        @return:
            - The format is "master" or "PhD".
            - The format is not standardize and can varies
              between records and between stores.
            - Empty string when not defined

        """
        return self._get(u"502", "a")

    def these_directors(self):
        """The list of director(s)

        @rtype: unicode
        @return:
            - Names are separated by ", ".
            - Empty string when not defined.

        """
        # NOTE director are stored in the author field
        # the first author is not a director !
        li = []
        if u"700" in self and isinstance(self[u"700"], dict):
            if "e" in self[u"700"] and self[u"700"]["e"] == THESIS_DIR:
118 119
                if "a" in self[u"700"]:
                    li.append(self[u"700"]["a"])
120 121 122 123

        elif u"700" in self and isinstance(self[u"700"], list):
            for di in self[u"700"]:
                if "e" in di and di["e"] == THESIS_DIR:
124 125
                    if "a" in di:
                        li.append(di["a"])
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147

        return ', '.join(li)

    def these_town(self):
        """The town where the thesis took place.

        @rtype: unicode
        @return:
            - Empty string when not defined.

        """
        return self._get(u"260", "a")

    def these_universities(self):
        """The university(ies) delivering the thesis diploma.

        @rtype: list
        @return:
            - Empty list when not defined

        """
        return self._get(u"502", "b", force_list=True)