recordconf.py 4.99 KB
Newer Older
1
""" store_tools.recordconf
2 3

"""
4
from .base import REG_CONF, REG_YEAR
5
from plugin_dbui import CLEAN_SPACES
6
from .recordpubli import RecordPubli
7 8 9


class RecordConf(RecordPubli):
LE GAC Renaud's avatar
LE GAC Renaud committed
10
    """The record describing a conference talk or a proceeding.
LE GAC Renaud's avatar
LE GAC Renaud committed
11
    Additional field describing the conference data are:
LE GAC Renaud's avatar
LE GAC Renaud committed
12

13 14
        +----------------+-----------------------------------------------+
        | field          | subfield                                      |
LE GAC Renaud's avatar
LE GAC Renaud committed
15
        +================+===============================================+
16 17 18 19 20
        | meeting_name   | closing_date, coference_code, country, date,  |
        |                | location, opening_date, year                  |
        +----------------+-----------------------------------------------+

    One field is added by limbra:
LE GAC Renaud's avatar
LE GAC Renaud committed
21

22 23
        +----------------+-----------------------------------------------+
        | field (limbra) | subfield                                      |
LE GAC Renaud's avatar
LE GAC Renaud committed
24
        +================+===============================================+
25 26
        | meeting_note   | recid, url                                    |
        +----------------+-----------------------------------------------+
27 28

    """
29

LE GAC Renaud's avatar
LE GAC Renaud committed
30 31
    def conference_country(self):
        """The country where the conference took place.
32

33
        Returns:
34
            str:
LE GAC Renaud's avatar
LE GAC Renaud committed
35 36
                the filter *CLEAN_SPACES* is applied.
                The string is empty when the country is not defined.
37 38

        """
LE GAC Renaud's avatar
LE GAC Renaud committed
39 40 41 42 43 44 45 46
        # NOTE:
        #  * country is extract from the location since it is defined
        #    for both cds and inspire store
        #
        #  * The subfield country contains the country code (IT? FR, ..).
        #    It is only defined for cds
        #
        location = self.conference_location()
47

LE GAC Renaud's avatar
LE GAC Renaud committed
48
        if len(location) == 0:
49
            return ""
50

LE GAC Renaud's avatar
LE GAC Renaud committed
51
        return CLEAN_SPACES(location.split(",")[-1])
52

LE GAC Renaud's avatar
LE GAC Renaud committed
53 54
    def conference_dates(self):
        """The dates of the conference.
55

LE GAC Renaud's avatar
LE GAC Renaud committed
56
        Returns:
57
            str:
LE GAC Renaud's avatar
LE GAC Renaud committed
58 59 60
                the usual pattern is ``6-5 March 2012`` but it can varies
                between records and between stores since it is not
                standardise.
61

LE GAC Renaud's avatar
LE GAC Renaud committed
62 63
        """
        # for list assume that the first item is the correct one
64
        val = self._get("meeting_name", "date")
LE GAC Renaud's avatar
LE GAC Renaud committed
65 66
        val = (val[0] if isinstance(val, list) and len(val) > 0 else val)
        return val
67

LE GAC Renaud's avatar
LE GAC Renaud committed
68 69
    def conference_id(self):
        """The conference identifier used in the store.
70

71
        Returns:
72
            int or None
73 74

        """
75 76 77 78
        if "meeting_note" not in self:
            return None

        return self["meeting_note"].get("recid")
79 80 81 82

    def conference_key(self):
        """The conference key used in the store.

83
        Returns:
84
            str:
LE GAC Renaud's avatar
LE GAC Renaud committed
85
                empty string when not defined
86 87

        """
LE GAC Renaud's avatar
LE GAC Renaud committed
88 89
        # algorithm depends on the store
        # CDS
90 91
        if "aleph_linking_page" in self:
            value = self["aleph_linking_page"]["up_link"]
LE GAC Renaud's avatar
LE GAC Renaud committed
92 93

        # INSPIRE
94 95
        elif "publication_info" in self:
            df = self["publication_info"]
LE GAC Renaud's avatar
LE GAC Renaud committed
96 97 98 99 100 101
            cnums = df[df.cnum.str.match(REG_CONF.pattern) == True].cnum

            if len(cnums) == 1:
                value = cnums.iloc[0]

        else:
102
            value = ""
LE GAC Renaud's avatar
LE GAC Renaud committed
103 104

        return value
105 106 107 108

    def conference_location(self):
        """The conference location.

109
        Returns:
110
            str:
LE GAC Renaud's avatar
LE GAC Renaud committed
111 112 113
                - the pattern is ``town, country``
                - empty string when more than one location found
                - empty string when not defined
114 115

        """
116 117
        location = self._get("meeting_name", "location", force_list=True)
        location = (location[0] if len(location) == 1 else "")
118 119 120 121 122 123

        return CLEAN_SPACES(location)

    def conference_title(self):
        """The title of the conference.

124
        Returns:
125
            str:
126 127

        """
LE GAC Renaud's avatar
LE GAC Renaud committed
128
        # for list assume that the first item is the correct one
129
        value = self._get("meeting_name", "meeting")
LE GAC Renaud's avatar
LE GAC Renaud committed
130 131
        value = (value[0] if isinstance(value, list) else value)
        return CLEAN_SPACES(value)
132 133 134 135

    def conference_town(self):
        """The town where the conference took place.

136
        Returns:
137
            str:
LE GAC Renaud's avatar
LE GAC Renaud committed
138
                empty string when it is not defined.
139 140

        """
LE GAC Renaud's avatar
LE GAC Renaud committed
141 142 143
        location = self.conference_location()

        if len(location) == 0:
144
            return ""
LE GAC Renaud's avatar
LE GAC Renaud committed
145 146

        return CLEAN_SPACES(location.split(",")[0])
147 148 149 150

    def conference_url(self):
        """The URL of the conference home page.

151
        Returns:
152
            str:
LE GAC Renaud's avatar
LE GAC Renaud committed
153
                select arbitrarily the first URL when severals
LE GAC Renaud's avatar
LE GAC Renaud committed
154 155
                are founded. The string is empty string when the URL
                is not defined.
156 157

        """
158 159 160 161
        if "meeting_note" not in self:
            return ""

        return self["meeting_note"].get("url", "")
162 163 164 165

    def conference_year(self):
        """The year of the conference.

166
        Returns:
167
            str:
LE GAC Renaud's avatar
LE GAC Renaud committed
168
                empty string when it is not defined.
169 170

        """
LE GAC Renaud's avatar
LE GAC Renaud committed
171
        # from the conference dates
172 173 174 175
        match = REG_YEAR.search(self.conference_dates())
        if match:
            return match.group(1)

176
        return ""