recordthesis.py 3.23 KB
Newer Older
1 2 3 4
# -*- coding: utf-8 -*-
""" invenio_tools.recordthesis

"""
LE GAC Renaud's avatar
LE GAC Renaud committed
5
from base import THESIS_DIR
6
from filters import CLEAN_THESIS_DEFENSE
7 8
from iterauthors import author_name, iter_author_fields
from itertools import ifilter, ifilterfalse, imap
9 10 11
from recordpubli import RecordPubli


LE GAC Renaud's avatar
LE GAC Renaud committed
12 13 14 15 16 17 18
def is_thesis_dir(x):
    """
    Args:
        x (dict): correspond to the field 100 or 700 for one author

    """
    return "e" in x and x["e"] == THESIS_DIR
19 20


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

25 26 27 28 29 30 31 32
        +-----------------------+---------+----------+
        |                       |  CDS    | INSPIREP |
        +-----------------------+---------+----------+
        | these defence         | 500 a   |          |
        | these level           | 502 a   |          |
        | these director        | 700 a   |          |
        | these universities    | 502 b   |          |
        +-----------------------+---------+----------+
33 34

    """
35 36 37
    def authors_as_list(self):
        """The list of author(s) signing the publication.

38 39
        Returns:
            list: the list is empty when authors are not defined.
40 41

        """
42 43 44
        # for a thesis, the author field 700 contains names of author
        # as well as directors. The latter have to be removed.
        df = self[u"700"]
45

46 47 48 49 50 51 52 53 54
        query = df.e != THESIS_DIR
        df = df.loc[query]

        li = df.a.tolist()

        if len(li) == 1 and li[0] == "":
            li = []

        return li
55

56
    def these_defense(self):
57
        """The defence date for a master/phd thesis.
58

59 60 61 62 63 64
        Returns:
            unicode:
                * The pattern is ``5 March 2012``.
                * The pattern it is not standardise
                  and can varies between records and between stores.
                * The filter CLEAN_THESIS_DEFENSE is applied.
65 66 67 68 69 70 71 72

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

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

73 74 75 76 77 78
        Returns:
            unicode:
                * The value is "master" or "PhD".
                * The value is not standardise and can varies
                  between records and between stores.
                * Empty string when not defined
79 80 81 82 83 84 85

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

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

86 87
        Returns:
            unicode:
88
                * Names are separated by ``|``.
89
                * Empty string when it is not defined.
90 91

        """
92 93
        # for a thesis, the author field 700 field contains
        # names of the director as well as the name of authors
94 95 96 97
        df = self[u"700"]

        query = df.e == THESIS_DIR
        df = df.loc[query]
98

99
        return (u"|".join(df.a) if len(df) > 0 else u"")
100 101 102 103

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

104 105
        Returns:
            unicode: empty string when the town is not defined.
106 107 108 109 110 111 112

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

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

113 114
        Returns:
            list: empty list when university is not defined
115 116 117

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