# -*- coding: utf-8 -*- """ invenio_tools.recordthesis """ from base import THESIS_DIR from filters import CLEAN_THESIS_DEFENSE from iterauthors import author_name, iter_author_fields from itertools import ifilter, ifilterfalse, imap from recordpubli import RecordPubli 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 class RecordThesis(RecordPubli): """The MARC record describing a thesis. The relation between methods and MARC fields are the following:: +-----------------------+---------+----------+ | | CDS | INSPIREP | +-----------------------+---------+----------+ | these defence | 500 a | | | these level | 502 a | | | these director | 700 a | | | these universities | 502 b | | +-----------------------+---------+----------+ """ def authors_as_list(self): """The list of author(s) signing the publication. Returns: list: the list is empty when authors are not defined. """ # 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"] query = df.e != THESIS_DIR df = df.loc[query] li = df.a.tolist() if len(li) == 1 and li[0] == "": li = [] return li def these_defense(self): """The defence date for a master/phd thesis. 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. """ val = self._get(u"500", "a") return CLEAN_THESIS_DEFENSE(val) def these_level(self): """The level of the thesis. 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 """ return self._get(u"502", "a") def these_directors(self): """The list of director(s) Returns: unicode: * Names are separated by ``|``. * Empty string when it is not defined. """ # for a thesis, the author field 700 field contains # names of the director as well as the name of authors df = self[u"700"] query = df.e == THESIS_DIR df = df.loc[query] return (u"|".join(df.a) if len(df) > 0 else u"") def these_town(self): """The town where the thesis took place. Returns: unicode: empty string when the town is not defined. """ return self._get(u"260", "a") def these_universities(self): """The university(ies) delivering the thesis diploma. Returns: list: empty list when university is not defined """ return self._get(u"502", "b", force_list=True)