Coverage for apps/ptf/model_data.py: 89%

203 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2024-02-28 09:09 +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################################################################################################## 

11 

12 

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 

18 

19 

20class ResourceData: 

21 def __init__(self, *args, **kwargs): 

22 super().__init__() 

23 

24 self.lang = "und" 

25 

26 self.pid = None 

27 self.doi = None 

28 

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 = "" 

36 

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 = [] 

44 

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 

47 

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 = [] 

53 

54 self.counts = [] 

55 

56 self.contributors = [] 

57 self.kwds = [] 

58 self.kwd_groups = [] 

59 self.subjs = [] 

60 self.subj_groups = [] 

61 

62 self.figures = [] 

63 self.supplementary_materials = [] 

64 

65 self.funding_statement_html = "" 

66 self.funding_statement_xml = "" 

67 self.footnotes_html = "" 

68 self.footnotes_xml = "" 

69 

70 self.body_html = "" 

71 self.body_tex = "" 

72 self.body_xml = "" 

73 self.body = "" 

74 

75 

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) 

82 

83 self.coltype = None 

84 self.issn = None 

85 self.e_issn = None 

86 self.wall = 0 

87 self.provider = None 

88 self.abbrev = "" 

89 

90 

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 = [] 

101 

102 

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) 

109 

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 = "" 

117 

118 

119class IssueData(ResourceData): 

120 def __init__(self, *args, **kwargs): 

121 super().__init__(*args, **kwargs) 

122 

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 

136 

137 def __iter__(self): 

138 yield from self.articles 

139 

140 

141class ArticleData(ResourceData): 

142 def __init__(self, *args, **kwargs): 

143 super().__init__(*args, **kwargs) 

144 

145 self.atype = "" 

146 

147 self.seq = 0 

148 self.fpage = self.lpage = self.page_range = self.size = "" 

149 self.page_type = "" 

150 

151 self.article_number = "" 

152 self.talk_number = "" 

153 

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 

158 

159 self.pid = None 

160 

161 self.coi_statement = "" # Conflict of interest 

162 

163 self.translations = [] # list of ArticleData, translation of the article by others 

164 

165 

166class RefData(ResourceData): 

167 # TODO: remove lang ? It is not used by Bibitem. 

168 

169 def __init__(self, *args, **kwargs): # , lang): 

170 super().__init__(*args, **kwargs) 

171 

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 = "" 

197 

198 

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) 

204 

205 self.coltype = None 

206 self.issn = None 

207 self.e_issn = None 

208 self.volume = "" 

209 self.vseries = "" 

210 self.seq = 0 

211 

212 

213class BookData(ResourceData): 

214 def __init__(self, *args, **kwargs): 

215 super().__init__(*args, **kwargs) 

216 

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 

228 

229 self.last_modified_iso_8601_date_str = None 

230 self.prod_deployed_date_iso_8601_date_str = None 

231 

232 

233class BookPartData(ArticleData): 

234 def __init__(self, *args, **kwargs): 

235 super().__init__(*args, **kwargs) 

236 

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 

244 

245 

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>' 

252 

253 if doi is not None: 

254 data.doi = doi 

255 data.extids.append(("doi", doi)) 

256 

257 return data 

258 

259 

260def create_articledata(doi=None): 

261 data = ArticleData(doi=doi) 

262 return data 

263 

264 

265def create_issuedata(): 

266 data = IssueData() 

267 return data 

268 

269 

270def create_bookdata(): 

271 data = BookData() 

272 return data 

273 

274 

275def create_publicationdata(): 

276 data = MathdocPublicationData() 

277 return data 

278 

279 

280def create_collectiondata(): 

281 data = CollectionData() 

282 return data 

283 

284 

285def create_publisherdata(): 

286 data = PublisherData() 

287 return data 

288 

289 

290def create_contributor(): 

291 return { 

292 "orcid": "", 

293 "mid": "", 

294 "first_name": "", 

295 "last_name": "", 

296 "prefix": "", 

297 "suffix": "", 

298 "email": "", 

299 "string_name": "", 

300 "addresses": [], 

301 "address_text": "", 

302 "role": "", 

303 "deceased_before_publication": False, 

304 "equal_contrib": False, 

305 "contrib_xml": '<contrib content-type="author"><name><surname></surname><given-names></given-names></name></contrib>', 

306 "corresponding": False, 

307 "seq": 0, 

308 } 

309 

310 

311def create_extlink(): 

312 return {"rel": "", "mimetype": "", "location": "", "base": "", "metadata": ""} 

313 

314 

315def create_datastream(): 

316 return {"rel": "", "mimetype": "", "location": "", "base": "", "text": ""} 

317 

318 

319def get_extlink(resource, rel): 

320 if resource is None: 

321 return None 

322 

323 results = [extlink for extlink in resource.ext_links if extlink["rel"] == rel] 

324 result = results[0] if len(results) > 0 else None 

325 

326 return result