Coverage for apps/ptf/model_data.py: 90%
205 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-05-19 19:20 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-05-19 19:20 +0000
1##################################################################################################
2#
3# README
4#
5# pivot classes for PTF objects (articles, issues,...).
6# They only have data members and are independent of XML, relational database and search engine.
7# They can be used directly by cmds
8# Parsers (JATS), Comparators,... inherit from these classes and add functions (parse_tree, compare)
9#
10##################################################################################################
13# Simple object for compatibility reason:
14# - in xml_cmds/add_relations
15# - in xml_cmds/find_collection (needs an incollection.collection.pid)
16class Foo:
17 pass
20class ResourceData:
21 def __init__(self, *args, **kwargs):
22 super().__init__()
24 self.lang = "und"
26 self.pid = None
27 self.doi = None
29 self.title_xml = ""
30 self.title_tex = ""
31 self.title_html = ""
32 self.trans_lang = "und"
33 self.trans_title_html = ""
34 self.trans_title_tex = ""
35 self.trans_title_xml = ""
37 # Common to articles, books, book-parts
38 self.abstracts = []
39 self.bibitems = []
40 # TODO: Remove bibitem. This is used for solrCmds. solrCmds should use bibitems instead.
41 self.bibitem = []
42 self.awards = []
43 self.relations = []
45 self.ids = [] # Other id of the resource. Create ResourceId in the DB
46 self.extids = [] # id given by an external source (MR, ZBL...). Create an ExtId in the DB
48 self.ext_links = (
49 []
50 ) # <ext-link> can contain MR/ZBL... In this case, ExtLink are not created, only ExtId
51 self.streams = []
52 self.related_objects = []
54 self.counts = []
56 self.contributors = []
57 self.kwds = []
58 self.kwd_groups = []
59 self.subjs = []
60 self.subj_groups = []
62 self.figures = []
63 self.supplementary_materials = []
65 self.funding_statement_html = ""
66 self.funding_statement_xml = ""
67 self.footnotes_html = ""
68 self.footnotes_xml = ""
70 self.body_html = ""
71 self.body_tex = ""
72 self.body_xml = ""
73 self.body = ""
76# Found in col.xml
77# It is the main way to create a collection in PTF
78# The upload urls will end up create MathdocPublicationData
79class MathdocPublicationData(ResourceData):
80 def __init__(self, *args, **kwargs):
81 super().__init__(*args, **kwargs)
83 self.coltype = None
84 self.issn = None
85 self.e_issn = None
86 self.wall = 0
87 self.provider = None
88 self.abbrev = ""
91class PublisherData:
92 def __init__(self, *args, **kwargs):
93 super().__init__()
94 self.name = None
95 self.loc = ""
96 # Note: add_publisher in xml_cmds tries to create ExtLinks for Publishers
97 # But this is not possible in JATS:
98 # <publisher> only has <publisher-name> and <publisher-location>
99 # TODO: remove ext_links ?
100 self.ext_links = []
103# JournalData typically comes from a <journal-meta> inside a <journal-issue>
104# It is not the main way to create a Journal, but can be used to create a collection on the fly.
105# In this case, it will get some attributes from its parent collection (ex: coltype)
106class JournalData(ResourceData):
107 def __init__(self, *args, **kwargs):
108 super().__init__(*args, **kwargs)
110 self.coltype = None
111 self.publisher = None
112 self.provider = None
113 self.issn = None
114 self.e_issn = None
115 self.wall = 0
116 self.abbrev = ""
119class IssueData(ResourceData):
120 def __init__(self, *args, **kwargs):
121 super().__init__(*args, **kwargs)
123 self.journal = None
124 self.publisher = None
125 self.provider = None
126 self.ctype = "issue"
127 self.year = ""
128 self.vseries = ""
129 self.volume = ""
130 self.number = ""
131 self.last_modified_iso_8601_date_str = None
132 self.prod_deployed_date_iso_8601_date_str = None
133 self.articles = []
134 self.with_online_first = False
135 self.seq = 0
137 def __iter__(self):
138 yield from self.articles
141class ArticleData(ResourceData):
142 def __init__(self, *args, **kwargs):
143 super().__init__(*args, **kwargs)
145 self.atype = ""
147 self.seq = 0
148 self.fpage = self.lpage = self.page_range = self.size = ""
149 self.page_type = ""
151 self.article_number = ""
152 self.talk_number = ""
154 self.elocation = ""
155 self.history_dates = []
156 self.prod_deployed_date_iso_8601_date_str = None
157 self.date_published_iso_8601_date_str = None
159 self.pid = None
161 self.coi_statement = "" # Conflict of interest
163 self.translations = [] # list of ArticleData, translation of the article by others
166class RefData(ResourceData):
167 # TODO: remove lang ? It is not used by Bibitem.
169 def __init__(self, *args, **kwargs): # , lang):
170 super().__init__(*args, **kwargs)
172 self.lang = kwargs["lang"]
173 self.user_id = ""
174 self.label = ""
175 self.label_prefix = self.label_suffix = ""
176 self.citation_xml = ""
177 self.citation_html = None
178 self.citation_tex = None
179 self.type = "misc"
180 self.publisher_name = ""
181 self.publisher_loc = ""
182 self.institution = ""
183 self.series = ""
184 self.volume = ""
185 self.issue = ""
186 self.month = ""
187 self.year = ""
188 self.comment = ""
189 self.annotation = ""
190 self.fpage = ""
191 self.lpage = ""
192 self.page_range = ""
193 self.size = ""
194 self.source_tex = ""
195 self.article_title_tex = ""
196 self.chapter_title_tex = ""
199# Incollection found in books
200# Mainly used to find the book number in its collection
201class CollectionData(ResourceData):
202 def __init__(self, *args, **kwargs):
203 super().__init__(*args, **kwargs)
205 self.coltype = None
206 self.issn = None
207 self.e_issn = None
208 self.volume = ""
209 self.vseries = ""
210 self.seq = 0
213class BookData(ResourceData):
214 def __init__(self, *args, **kwargs):
215 super().__init__(*args, **kwargs)
217 book_type = "Book"
218 self.ctype = "book-" + book_type
219 self.frontmatter_xml = None
220 self.frontmatter_toc_html = None
221 self.frontmatter_foreword_html = None
222 self.incollection = []
223 self.publisher = None
224 self.provider = None
225 self.parts = []
226 self.body = ""
227 self.seq = 0
229 self.last_modified_iso_8601_date_str = None
230 self.prod_deployed_date_iso_8601_date_str = None
233class BookPartData(ArticleData):
234 def __init__(self, *args, **kwargs):
235 super().__init__(*args, **kwargs)
237 self.atype = ""
238 self.fpage = self.lpage = self.page_range = self.page_type = ""
239 self.frontmatter_xml = None
240 self.frontmatter_toc_html = None
241 self.frontmatter_foreword_html = None
242 self.parts = []
243 self.body = None
246def create_refdata(lang="und", doi=None):
247 data = RefData(lang=lang)
248 data.type = "unknown"
249 data.citation_html = ""
250 data.citation_tex = ""
251 data.citation_xml = '<label></label><mixed-citation xml:space="preserve"></mixed_citation>'
253 if doi is not None:
254 data.doi = doi
255 data.extids.append(("doi", doi))
257 return data
260def create_articledata(doi=None):
261 data = ArticleData(doi=doi)
262 return data
265def create_issuedata():
266 data = IssueData()
267 return data
270def create_bookdata():
271 data = BookData()
272 return data
275def create_publicationdata():
276 data = MathdocPublicationData()
277 return data
280def create_collectiondata():
281 data = CollectionData()
282 return data
285def create_publisherdata():
286 data = PublisherData()
287 return data
290def create_contributor():
291 return {
292 "orcid": "",
293 "idref": "",
294 "mid": "",
295 "first_name": "",
296 "last_name": "",
297 "prefix": "",
298 "suffix": "",
299 "email": "",
300 "string_name": "",
301 "addresses": [],
302 "address_text": "",
303 "role": "",
304 "deceased_before_publication": False,
305 "equal_contrib": False,
306 "contrib_xml": '<contrib content-type="author"><name><surname></surname><given-names></given-names></name></contrib>',
307 "corresponding": False,
308 "seq": 0,
309 }
312def create_subj():
313 return {
314 "lang": "",
315 "type": "",
316 "value": "",
317 }
320def create_extlink():
321 return {"rel": "", "mimetype": "", "location": "", "base": "", "metadata": ""}
324def create_datastream():
325 return {"rel": "", "mimetype": "", "location": "", "base": "", "text": ""}
328def get_extlink(resource, rel):
329 if resource is None:
330 return None
332 results = [extlink for extlink in resource.ext_links if extlink["rel"] == rel]
333 result = results[0] if len(results) > 0 else None
335 return result