philoch-bib-sdk 0.1.1rc1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- philoch_bib_sdk-0.1.1rc1/LICENSE +21 -0
- philoch_bib_sdk-0.1.1rc1/PKG-INFO +21 -0
- philoch_bib_sdk-0.1.1rc1/README.md +3 -0
- philoch_bib_sdk-0.1.1rc1/philoch_bib_sdk/logic/formatters.py +89 -0
- philoch_bib_sdk-0.1.1rc1/philoch_bib_sdk/logic/literals.py +86 -0
- philoch_bib_sdk-0.1.1rc1/philoch_bib_sdk/logic/models.py +359 -0
- philoch_bib_sdk-0.1.1rc1/philoch_bib_sdk/logic/parsers.py +177 -0
- philoch_bib_sdk-0.1.1rc1/pyproject.toml +66 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Philosophie.ch
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: philoch-bib-sdk
|
|
3
|
+
Version: 0.1.1rc1
|
|
4
|
+
Summary: Standard development kit for the Philosophie Bibliography project
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Luis Alejandro Bordo García
|
|
7
|
+
Author-email: luis.bordo@philosophie.ch
|
|
8
|
+
Maintainer: Luis Alejandro Bordo García
|
|
9
|
+
Maintainer-email: tech@philosophie.ch
|
|
10
|
+
Requires-Python: >=3.13
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Requires-Dist: aletk (>=0.1.6,<0.2.0)
|
|
15
|
+
Requires-Dist: attrs (>=25.3.0,<26.0.0)
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# Philosophie.ch Bibliography SDK
|
|
19
|
+
|
|
20
|
+
This repository contains the standard development kit for the bibliography project of the [Philosophie.ch](https://philosophie.ch) association.
|
|
21
|
+
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
from aletk.utils import get_logger
|
|
3
|
+
from philoch_bib_sdk.logic.models import Author, BibKey, PagePair
|
|
4
|
+
|
|
5
|
+
lgr = get_logger(__name__)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _author_full_name_generic(given_name: str | None, family_name: str | None) -> str:
|
|
9
|
+
if given_name is None:
|
|
10
|
+
return ""
|
|
11
|
+
|
|
12
|
+
if family_name is None:
|
|
13
|
+
return given_name
|
|
14
|
+
|
|
15
|
+
return f"{family_name}, {given_name}"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _author_full_name(author: Author | None) -> str:
|
|
19
|
+
if author is None:
|
|
20
|
+
return ""
|
|
21
|
+
return _author_full_name_generic(author.given_name, author.family_name)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _author_full_name_latex(author: Author | None) -> str:
|
|
25
|
+
if author is None:
|
|
26
|
+
return ""
|
|
27
|
+
return _author_full_name_generic(author.given_name_latex, author.family_name_latex)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def author_full_name(authors: List[Author] | None) -> str:
|
|
31
|
+
if authors is None:
|
|
32
|
+
return ""
|
|
33
|
+
return " and ".join([_author_full_name(author) for author in authors])
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def author_full_name_latex(authors: List[Author] | None) -> str:
|
|
37
|
+
if authors is None:
|
|
38
|
+
return ""
|
|
39
|
+
return " and ".join([_author_full_name_latex(author) for author in authors])
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def bibkey_str(bibkey: BibKey | None) -> str:
|
|
43
|
+
if bibkey is None:
|
|
44
|
+
return ""
|
|
45
|
+
|
|
46
|
+
if bibkey.other_authors:
|
|
47
|
+
authors_l = [bibkey.first_author, bibkey.other_authors]
|
|
48
|
+
else:
|
|
49
|
+
authors_l = [bibkey.first_author]
|
|
50
|
+
|
|
51
|
+
authors = "-".join(authors_l)
|
|
52
|
+
|
|
53
|
+
year = (
|
|
54
|
+
f"{bibkey.year}{bibkey.year_suffix}"
|
|
55
|
+
if bibkey.pub_status in ["published", ""]
|
|
56
|
+
else f"{bibkey.pub_status}{bibkey.year_suffix}"
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
return f"{authors}:{year}"
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _pages_single_str(page_pair: PagePair) -> str:
|
|
63
|
+
return "--".join([page_pair.start, page_pair.end])
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def pages_str(pages: List[PagePair] | None) -> str:
|
|
67
|
+
if pages is None:
|
|
68
|
+
return ""
|
|
69
|
+
return ", ".join([_pages_single_str(page_pair) for page_pair in pages])
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def person_str(person: Author | None) -> str:
|
|
73
|
+
"""
|
|
74
|
+
Note: ignores LaTeX names
|
|
75
|
+
"""
|
|
76
|
+
if person is None:
|
|
77
|
+
return ""
|
|
78
|
+
|
|
79
|
+
if person.famous_name is not None:
|
|
80
|
+
return person.famous_name
|
|
81
|
+
|
|
82
|
+
if person.given_name is None and person.family_name is None:
|
|
83
|
+
return ""
|
|
84
|
+
|
|
85
|
+
if person.given_name is None:
|
|
86
|
+
return person.family_name
|
|
87
|
+
|
|
88
|
+
# Mononym
|
|
89
|
+
return person.given_name
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
from typing import Literal
|
|
2
|
+
|
|
3
|
+
type TBibTeXEntryType = Literal[
|
|
4
|
+
"",
|
|
5
|
+
"article",
|
|
6
|
+
"book",
|
|
7
|
+
"incollection",
|
|
8
|
+
"inproceedings",
|
|
9
|
+
"mastersthesis",
|
|
10
|
+
"misc",
|
|
11
|
+
"phdthesis",
|
|
12
|
+
"proceedings",
|
|
13
|
+
"techreport",
|
|
14
|
+
"unpublished",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
type TPubState = Literal[
|
|
18
|
+
"",
|
|
19
|
+
"unpub",
|
|
20
|
+
"inwork",
|
|
21
|
+
"submitted",
|
|
22
|
+
"published",
|
|
23
|
+
"forthcoming",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
type TLanguageID = Literal[
|
|
27
|
+
"",
|
|
28
|
+
"catalan",
|
|
29
|
+
"czech",
|
|
30
|
+
"danish",
|
|
31
|
+
"dutch",
|
|
32
|
+
"english",
|
|
33
|
+
"french",
|
|
34
|
+
"greek",
|
|
35
|
+
"italian",
|
|
36
|
+
"latin",
|
|
37
|
+
"lithuanian",
|
|
38
|
+
"ngerman",
|
|
39
|
+
"polish",
|
|
40
|
+
"portuguese",
|
|
41
|
+
"romanian",
|
|
42
|
+
"russian",
|
|
43
|
+
"slovak",
|
|
44
|
+
"spanish",
|
|
45
|
+
"swedish",
|
|
46
|
+
"unknown",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
type TEpoch = Literal[
|
|
50
|
+
"",
|
|
51
|
+
"ancient-philosophy",
|
|
52
|
+
"ancient-scientists",
|
|
53
|
+
"austrian-philosophy",
|
|
54
|
+
"british-idealism",
|
|
55
|
+
"classics",
|
|
56
|
+
"contemporaries",
|
|
57
|
+
"contemporary-scientists",
|
|
58
|
+
"continental-philosophy",
|
|
59
|
+
"critical-theory",
|
|
60
|
+
"cynics",
|
|
61
|
+
"enlightenment",
|
|
62
|
+
"existentialism",
|
|
63
|
+
"exotic-philosophy",
|
|
64
|
+
"german-idealism",
|
|
65
|
+
"german-rationalism",
|
|
66
|
+
"gestalt-psychology",
|
|
67
|
+
"hermeneutics",
|
|
68
|
+
"islamic-philosophy",
|
|
69
|
+
"mathematicians",
|
|
70
|
+
"medieval-philosophy",
|
|
71
|
+
"modern-philosophy",
|
|
72
|
+
"modern-scientists",
|
|
73
|
+
"neokantianism",
|
|
74
|
+
"neo-kantianism",
|
|
75
|
+
"neoplatonism",
|
|
76
|
+
"new-realism",
|
|
77
|
+
"ordinary-language-philosophy",
|
|
78
|
+
"phenomenology",
|
|
79
|
+
"polish-logic",
|
|
80
|
+
"pragmatism",
|
|
81
|
+
"presocratics",
|
|
82
|
+
"renaissance",
|
|
83
|
+
"stoics",
|
|
84
|
+
"theologians",
|
|
85
|
+
"vienna-circle",
|
|
86
|
+
]
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from typing import Tuple
|
|
3
|
+
import attrs
|
|
4
|
+
|
|
5
|
+
from philoch_bib_sdk.logic.literals import TBibTeXEntryType, TEpoch, TLanguageID, TPubState
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
############
|
|
9
|
+
# Base Renderables
|
|
10
|
+
############
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@attrs.define(frozen=True, slots=True)
|
|
14
|
+
class BaseRenderable:
|
|
15
|
+
"""
|
|
16
|
+
Base class for renderable objects, that contain LaTeX code, and possibly a unicode representation of it.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
text: str = ""
|
|
20
|
+
text_latex: str = ""
|
|
21
|
+
id: int = -1
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
text: str = ""
|
|
25
|
+
text_latex: str = ""
|
|
26
|
+
id: int = -1
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@attrs.define(frozen=True, slots=True)
|
|
30
|
+
class BaseNamedRenderable:
|
|
31
|
+
"""
|
|
32
|
+
Base class for renderable, named, objects, that contain LaTeX code, and possibly a unicode representation of it.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
name: str
|
|
36
|
+
name_latex: str | None = None
|
|
37
|
+
id: int | None = None
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
name: str = ""
|
|
41
|
+
name_latex: str = ""
|
|
42
|
+
id: int = -1
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
############
|
|
46
|
+
# Author
|
|
47
|
+
############
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@attrs.define(frozen=True, slots=True)
|
|
51
|
+
class Author:
|
|
52
|
+
"""
|
|
53
|
+
An author of a publication.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
given_name: str = ""
|
|
57
|
+
family_name: str = ""
|
|
58
|
+
given_name_latex: str = ""
|
|
59
|
+
family_name_latex: str = ""
|
|
60
|
+
publications: List[BibItem] = []
|
|
61
|
+
id: int = -1
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
given_name: str = ""
|
|
65
|
+
family_name: str = ""
|
|
66
|
+
given_name_latex: str = ""
|
|
67
|
+
family_name_latex: str = ""
|
|
68
|
+
famous_name: str = ""
|
|
69
|
+
publications: Tuple[BibItem, ...] = ()
|
|
70
|
+
id: int = -1
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
############
|
|
74
|
+
# Journal
|
|
75
|
+
############
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
@attrs.define(frozen=True, slots=True)
|
|
79
|
+
class Journal:
|
|
80
|
+
"""
|
|
81
|
+
A journal that publishes publications.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
name: str = ""
|
|
85
|
+
name_latex: str = ""
|
|
86
|
+
issn_print: str = ""
|
|
87
|
+
issn_electronic: str = ""
|
|
88
|
+
id: int = -1
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
name: str = ""
|
|
92
|
+
name_latex: str = ""
|
|
93
|
+
issn_print: str = ""
|
|
94
|
+
issn_electronic: str = ""
|
|
95
|
+
id: int = -1
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
############
|
|
99
|
+
# Note
|
|
100
|
+
############
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@attrs.define(frozen=True, slots=True)
|
|
104
|
+
class Note(BaseRenderable):
|
|
105
|
+
"""
|
|
106
|
+
Notes (metadata) about a publication.
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
text: str = ""
|
|
110
|
+
text_latex: str = ""
|
|
111
|
+
id: int = -1
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
pass
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
############
|
|
118
|
+
# Keywords
|
|
119
|
+
############
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
@attrs.define(frozen=True, slots=True)
|
|
123
|
+
class Keyword:
|
|
124
|
+
"""
|
|
125
|
+
Keyword of a publication.
|
|
126
|
+
|
|
127
|
+
Args:
|
|
128
|
+
name: str = ""
|
|
129
|
+
id: int = -1
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
name: str = ""
|
|
133
|
+
id: int = -1
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
@attrs.define(frozen=True, slots=True)
|
|
137
|
+
class Keywords:
|
|
138
|
+
level1: Keyword = Keyword()
|
|
139
|
+
level2: Keyword = Keyword()
|
|
140
|
+
level3: Keyword = Keyword()
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
############
|
|
144
|
+
# Series, Institution, School, Publisher, Type
|
|
145
|
+
############
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
@attrs.define(frozen=True, slots=True)
|
|
149
|
+
class Series(BaseNamedRenderable):
|
|
150
|
+
"""
|
|
151
|
+
A series of publications.
|
|
152
|
+
|
|
153
|
+
Args:
|
|
154
|
+
name: str = ""
|
|
155
|
+
name_latex: str = ""
|
|
156
|
+
id: int = -1
|
|
157
|
+
"""
|
|
158
|
+
|
|
159
|
+
pass
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
@attrs.define(frozen=True, slots=True)
|
|
163
|
+
class Institution(BaseNamedRenderable):
|
|
164
|
+
"""
|
|
165
|
+
An institution that publishes publications.
|
|
166
|
+
|
|
167
|
+
Args:
|
|
168
|
+
name: str = ""
|
|
169
|
+
name_latex: str = ""
|
|
170
|
+
id: int = -1
|
|
171
|
+
"""
|
|
172
|
+
|
|
173
|
+
pass
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
@attrs.define(frozen=True, slots=True)
|
|
177
|
+
class School(BaseNamedRenderable):
|
|
178
|
+
"""
|
|
179
|
+
A school that publishes publications.
|
|
180
|
+
|
|
181
|
+
Args:
|
|
182
|
+
name: str = ""
|
|
183
|
+
name_latex: str = ""
|
|
184
|
+
id: int = -1
|
|
185
|
+
"""
|
|
186
|
+
|
|
187
|
+
pass
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
@attrs.define(frozen=True, slots=True)
|
|
191
|
+
class Publisher(BaseNamedRenderable):
|
|
192
|
+
"""
|
|
193
|
+
A publisher of publications.
|
|
194
|
+
|
|
195
|
+
Args:
|
|
196
|
+
name: str = ""
|
|
197
|
+
name_latex: str = ""
|
|
198
|
+
id: int = -1
|
|
199
|
+
"""
|
|
200
|
+
|
|
201
|
+
pass
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
@attrs.define(frozen=True, slots=True)
|
|
205
|
+
class Type(BaseNamedRenderable):
|
|
206
|
+
"""
|
|
207
|
+
A type of publication.
|
|
208
|
+
|
|
209
|
+
Args:
|
|
210
|
+
name: str = ""
|
|
211
|
+
name_latex: str = ""
|
|
212
|
+
id: int = -1
|
|
213
|
+
"""
|
|
214
|
+
|
|
215
|
+
pass
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
############
|
|
219
|
+
# BibItem
|
|
220
|
+
############
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
@attrs.define(frozen=True, slots=True)
|
|
224
|
+
class BibKey:
|
|
225
|
+
"""
|
|
226
|
+
A unique identifier for a publication.
|
|
227
|
+
|
|
228
|
+
Args:
|
|
229
|
+
first_author: str = ""
|
|
230
|
+
year: int | None = None
|
|
231
|
+
pub_status: TPubState = "published"
|
|
232
|
+
other_authors: str = ""
|
|
233
|
+
et_al: bool = False
|
|
234
|
+
year_suffix
|
|
235
|
+
"""
|
|
236
|
+
|
|
237
|
+
first_author: str
|
|
238
|
+
other_authors: str = ""
|
|
239
|
+
year: int | None = None
|
|
240
|
+
pub_status: TPubState = ""
|
|
241
|
+
year_suffix: str = ""
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
@attrs.define(frozen=True, slots=True)
|
|
245
|
+
class BibItemDate:
|
|
246
|
+
"""
|
|
247
|
+
Year of a publication.
|
|
248
|
+
|
|
249
|
+
Example:
|
|
250
|
+
BibItemDate(year=2021, year_revised=2022) represents `2021/2022`.
|
|
251
|
+
BibItemDate(year=2021, month=1, day=1) represents `2021-01-01`.
|
|
252
|
+
BibItemDate(forthcoming=True) represents `forthcoming`.
|
|
253
|
+
|
|
254
|
+
Args:
|
|
255
|
+
year: int | None = None
|
|
256
|
+
year_revised: int | None = None
|
|
257
|
+
month: int | None = None
|
|
258
|
+
day: int | None = None
|
|
259
|
+
forthcoming: bool | None = None
|
|
260
|
+
"""
|
|
261
|
+
|
|
262
|
+
year: int | None = None
|
|
263
|
+
year_revised: int | None = None
|
|
264
|
+
month: int | None = None
|
|
265
|
+
day: int | None = None
|
|
266
|
+
forthcoming: bool = False
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
@attrs.define(frozen=True, slots=True)
|
|
270
|
+
class PagePair:
|
|
271
|
+
"""
|
|
272
|
+
Page numbers of a publication. Can be a range, roman numerals, or a single page.
|
|
273
|
+
|
|
274
|
+
Args:
|
|
275
|
+
start: str
|
|
276
|
+
end: str | None = None
|
|
277
|
+
"""
|
|
278
|
+
|
|
279
|
+
start: str
|
|
280
|
+
end: str = ""
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
@attrs.define(frozen=True, slots=True)
|
|
284
|
+
class IssueTitle(BaseRenderable):
|
|
285
|
+
"""
|
|
286
|
+
Title of an issue of a publication.
|
|
287
|
+
|
|
288
|
+
Args:
|
|
289
|
+
text: str
|
|
290
|
+
text_latex: str | None = None
|
|
291
|
+
id: int | None = None
|
|
292
|
+
"""
|
|
293
|
+
|
|
294
|
+
pass
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
@attrs.define(frozen=True, slots=True)
|
|
298
|
+
class BibItem:
|
|
299
|
+
"""
|
|
300
|
+
Bibliographic item type. All attributes are optional.
|
|
301
|
+
|
|
302
|
+
Args:
|
|
303
|
+
|
|
304
|
+
"""
|
|
305
|
+
|
|
306
|
+
_to_do: str = ""
|
|
307
|
+
_change_request: str = ""
|
|
308
|
+
entry_type: TBibTeXEntryType = ""
|
|
309
|
+
bibkey: BibKey | None = None
|
|
310
|
+
author: Tuple[Author, ...] = ()
|
|
311
|
+
editor: Tuple[Author, ...] = ()
|
|
312
|
+
options: Tuple[str, ...] = ()
|
|
313
|
+
shorthand: str = ""
|
|
314
|
+
date: BibItemDate | None = None
|
|
315
|
+
pubstate: TPubState | None = None
|
|
316
|
+
title: str = ""
|
|
317
|
+
_title_unicode: str = ""
|
|
318
|
+
booktitle: str = ""
|
|
319
|
+
crossref: str = ""
|
|
320
|
+
journal: Journal | None = None
|
|
321
|
+
volume: str = ""
|
|
322
|
+
number: str = ""
|
|
323
|
+
pages: Tuple[PagePair, ...] = ()
|
|
324
|
+
eid: str = ""
|
|
325
|
+
series: Series | None = None
|
|
326
|
+
address: str = ""
|
|
327
|
+
institution: str = ""
|
|
328
|
+
school: str = ""
|
|
329
|
+
publisher: Publisher | None = None
|
|
330
|
+
type: Type | None = None
|
|
331
|
+
edition: str = ""
|
|
332
|
+
note: Note | None = None
|
|
333
|
+
issuetitle: IssueTitle | None = None
|
|
334
|
+
guesteditor: Tuple[Author, ...] = ()
|
|
335
|
+
further_note: Note | None = None
|
|
336
|
+
urn: str = ""
|
|
337
|
+
eprint: str = ""
|
|
338
|
+
doi: str = ""
|
|
339
|
+
url: str = ""
|
|
340
|
+
_kws: Keywords = Keywords()
|
|
341
|
+
_epoch: TEpoch = ""
|
|
342
|
+
_person: Author | None = None
|
|
343
|
+
_comm_for_profile_bib: str = ""
|
|
344
|
+
langid: TLanguageID = ""
|
|
345
|
+
_lang_det: str = ""
|
|
346
|
+
_further_refs: Tuple[BibKey, ...] = ()
|
|
347
|
+
_depends_on: Tuple[BibKey, ...] = ()
|
|
348
|
+
dltc_num: int | None = None
|
|
349
|
+
_spec_interest: str = ""
|
|
350
|
+
_note_perso: Note | None = None
|
|
351
|
+
_note_stock: Note | None = None
|
|
352
|
+
_note_status: Note | None = None
|
|
353
|
+
_num_in_work: str = ""
|
|
354
|
+
_num_in_work_coll: int | None = None
|
|
355
|
+
_num_coll: int | None = None
|
|
356
|
+
_dltc_copyediting_note: str = ""
|
|
357
|
+
_note_missing: str = ""
|
|
358
|
+
_num_sort: int = 0
|
|
359
|
+
_bib_info_source: str = ""
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import traceback
|
|
2
|
+
from typing import Tuple
|
|
3
|
+
from aletk.ResultMonad import Ok, Err
|
|
4
|
+
from aletk.utils import get_logger, remove_extra_whitespace
|
|
5
|
+
from philoch_bib_sdk.logic.models import Author, BibKey
|
|
6
|
+
|
|
7
|
+
lgr = get_logger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _author_parse_normalize(text: str) -> Tuple[str, str]:
|
|
11
|
+
"""
|
|
12
|
+
Return a tuple of two strings, the first of which is the given name, and the second of which is the family name. If only one name is found, the second string will be empty.
|
|
13
|
+
|
|
14
|
+
Fails if more than two names are found.
|
|
15
|
+
"""
|
|
16
|
+
parts = text.split(",")
|
|
17
|
+
|
|
18
|
+
if len(parts) > 2:
|
|
19
|
+
raise ValueError(f"Unexpected number of author parts found in '{text}': '{parts}'. Expected 2 or less.")
|
|
20
|
+
|
|
21
|
+
elif len(parts) == 0:
|
|
22
|
+
return ("", "")
|
|
23
|
+
|
|
24
|
+
elif len(parts) == 1:
|
|
25
|
+
return (parts[0], "")
|
|
26
|
+
|
|
27
|
+
else:
|
|
28
|
+
return (parts[0], parts[1])
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def author_parse(text: str, latex: bool) -> Ok[Tuple[Author, ...]] | Err:
|
|
32
|
+
"""
|
|
33
|
+
Return either a string, or a parsing error.
|
|
34
|
+
"""
|
|
35
|
+
try:
|
|
36
|
+
if text == "":
|
|
37
|
+
return Ok(())
|
|
38
|
+
|
|
39
|
+
parts = remove_extra_whitespace(text).split(" and ")
|
|
40
|
+
parts_normalized = [_author_parse_normalize(part) for part in parts]
|
|
41
|
+
|
|
42
|
+
authors = tuple(
|
|
43
|
+
Author(
|
|
44
|
+
given_name=author[0] if not latex else "",
|
|
45
|
+
family_name=author[1] if not latex else "",
|
|
46
|
+
given_name_latex=author[0] if latex else "",
|
|
47
|
+
family_name_latex=author[1] if latex else "",
|
|
48
|
+
)
|
|
49
|
+
for author in parts_normalized
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
return Ok(authors)
|
|
53
|
+
|
|
54
|
+
except Exception as e:
|
|
55
|
+
return Err(
|
|
56
|
+
message=f"Could not parse 'author' field with value [[ {text} ]]. {e.__class__.__name__}: {e}",
|
|
57
|
+
code=-1,
|
|
58
|
+
error_type="ParsingError",
|
|
59
|
+
error_trace=f"{traceback.format_exc()}",
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def person_parse(text: str) -> Ok[Author | None] | Err:
|
|
64
|
+
"""
|
|
65
|
+
Return either an Author object, or a parsing error.
|
|
66
|
+
"""
|
|
67
|
+
try:
|
|
68
|
+
if text == "":
|
|
69
|
+
return Ok(None)
|
|
70
|
+
|
|
71
|
+
cleaned = remove_extra_whitespace(remove_extra_whitespace(text).replace(";", ""))
|
|
72
|
+
|
|
73
|
+
return Ok(
|
|
74
|
+
Author(
|
|
75
|
+
famous_name=cleaned,
|
|
76
|
+
)
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
except Exception as e:
|
|
80
|
+
return Err(
|
|
81
|
+
message=f"Could not parse '_person' field with value [[ {text} ]]. {e.__class__.__name__}: {e}",
|
|
82
|
+
code=-1,
|
|
83
|
+
error_type="ParsingError",
|
|
84
|
+
error_trace=f"{traceback.format_exc()}",
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def bibkey_parse(text: str, text_position_d: dict[str, int] | None = None) -> Ok[BibKey] | Err:
|
|
89
|
+
"""
|
|
90
|
+
Return either a Bibkey object, or a BibkeyError object to indicate a parsing error.
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
return Err(
|
|
94
|
+
message="TODO. Clean and adapt the commented out code below.",
|
|
95
|
+
code=-1,
|
|
96
|
+
error_type="NotImplementedError",
|
|
97
|
+
)
|
|
98
|
+
# try:
|
|
99
|
+
# parts = text.split(":")
|
|
100
|
+
# if len(parts) != 2:
|
|
101
|
+
# raise ValueError(f"Unexpected number of bibkey parts for '{text}': '{parts}'")
|
|
102
|
+
|
|
103
|
+
# author_parts = parts[0].split("-")
|
|
104
|
+
# year_parts = parts[1]
|
|
105
|
+
|
|
106
|
+
# if len(author_parts) == 1:
|
|
107
|
+
# first_author = author_parts[0]
|
|
108
|
+
# other_authors = None
|
|
109
|
+
# elif len(author_parts) == 2:
|
|
110
|
+
# first_author = author_parts[0]
|
|
111
|
+
# other_authors = author_parts[1]
|
|
112
|
+
# else:
|
|
113
|
+
# raise ValueError(f"Unexpected bibkey author parts for '{text}': '{author_parts}'")
|
|
114
|
+
|
|
115
|
+
# char_index_type_d = {i: (char, char.isdigit()) for i, char in enumerate(year_parts)}
|
|
116
|
+
|
|
117
|
+
# year_l: list[str] = []
|
|
118
|
+
# int_breakpoint = None
|
|
119
|
+
# for value in char_index_type_d.items():
|
|
120
|
+
# i, (char, is_digit) = value
|
|
121
|
+
# if is_digit:
|
|
122
|
+
# year_l.append(char)
|
|
123
|
+
# int_breakpoint = i
|
|
124
|
+
# else:
|
|
125
|
+
# break
|
|
126
|
+
|
|
127
|
+
# if year_l != []:
|
|
128
|
+
# year_int = int(f"{''.join(year_l)}")
|
|
129
|
+
# else:
|
|
130
|
+
# year_int = None
|
|
131
|
+
|
|
132
|
+
# if int_breakpoint is not None:
|
|
133
|
+
# year_suffix = year_parts[int_breakpoint + 1 :]
|
|
134
|
+
|
|
135
|
+
# else:
|
|
136
|
+
## all characters are non-digits
|
|
137
|
+
# year_suffix = "".join(year_parts)
|
|
138
|
+
|
|
139
|
+
# if year_suffix != "" and year_suffix not in ["unpub", "forthcoming"]:
|
|
140
|
+
# if len(year_suffix) > 1:
|
|
141
|
+
# if "unpub" not in year_suffix and "forthcoming" not in year_suffix:
|
|
142
|
+
# lgr.warning(f"Unexpected year suffix for '{text}': '{year_suffix}'")
|
|
143
|
+
# elif len(year_suffix) == 1:
|
|
144
|
+
# if year_suffix.isdigit():
|
|
145
|
+
# lgr.warning(f"Unexpected year suffix for '{text}': '{year_suffix}'")
|
|
146
|
+
|
|
147
|
+
# if year_int is None and year_suffix is None:
|
|
148
|
+
# raise ValueError(f"Could not parse year for '{text}': '{year_parts}'")
|
|
149
|
+
|
|
150
|
+
# if year_int is None:
|
|
151
|
+
# return Ok(Bibkey(
|
|
152
|
+
# first_author=first_author,
|
|
153
|
+
# year = year_int,
|
|
154
|
+
# ))
|
|
155
|
+
|
|
156
|
+
# else:
|
|
157
|
+
# return Ok(
|
|
158
|
+
# Bibkey(first_author=first_author, other_authors=other_authors, year=year_int, year_suffix=year_suffix)
|
|
159
|
+
# )
|
|
160
|
+
|
|
161
|
+
# except Exception as e:
|
|
162
|
+
# error_message = f"Could not parse bibkey for '{text}'"
|
|
163
|
+
|
|
164
|
+
# if text_position_d is None:
|
|
165
|
+
# return Err(
|
|
166
|
+
# message=f"Could not parse bibkey for '{text}'. {e.__class__.__name__}: {e}",
|
|
167
|
+
# code=-1,
|
|
168
|
+
# error_type="BibkeyError",
|
|
169
|
+
# error_trace=f"{traceback.format_exc()}",
|
|
170
|
+
# )
|
|
171
|
+
# else:
|
|
172
|
+
# return Err(
|
|
173
|
+
# message=f"Could not parse bibkey for '{text}' at position {text_position_d}. {e.__class__}: {e}",
|
|
174
|
+
# code=-1,
|
|
175
|
+
# error_type="BibkeyError",
|
|
176
|
+
# error_trace=f"{traceback.format_exc()}",
|
|
177
|
+
# )
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "philoch-bib-sdk"
|
|
3
|
+
version = "0.1.1-rc1"
|
|
4
|
+
description = "Standard development kit for the Philosophie Bibliography project"
|
|
5
|
+
authors = [
|
|
6
|
+
{name = "Luis Alejandro Bordo García", email = "luis.bordo@philosophie.ch"}
|
|
7
|
+
]
|
|
8
|
+
maintainers = [
|
|
9
|
+
{name = "Luis Alejandro Bordo García", email = "tech@philosophie.ch"}
|
|
10
|
+
]
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.13"
|
|
14
|
+
|
|
15
|
+
[build-system]
|
|
16
|
+
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
17
|
+
build-backend = "poetry.core.masonry.api"
|
|
18
|
+
|
|
19
|
+
[tool.poetry.dependencies]
|
|
20
|
+
aletk = "^0.1.6"
|
|
21
|
+
attrs = "^25.3.0"
|
|
22
|
+
|
|
23
|
+
[tool.poetry.group.dev.dependencies]
|
|
24
|
+
pytest = "^8.3.5"
|
|
25
|
+
mypy = "^1.15.0"
|
|
26
|
+
black = {extras = ["jupyter"], version = "^25.1.0"}
|
|
27
|
+
jupyter = "^1.1.1"
|
|
28
|
+
pytest-env = "^1.1.5"
|
|
29
|
+
|
|
30
|
+
[tool.mypy]
|
|
31
|
+
python_version = "3.13"
|
|
32
|
+
strict = true
|
|
33
|
+
explicit_package_bases = true
|
|
34
|
+
mypy_path = "."
|
|
35
|
+
|
|
36
|
+
[tool.pytest.ini_options]
|
|
37
|
+
minversion = "6.0"
|
|
38
|
+
addopts = "-ras -m 'not external'"
|
|
39
|
+
markers = [
|
|
40
|
+
"external: mark tests that require external API calls",
|
|
41
|
+
]
|
|
42
|
+
testpaths = ["tests"]
|
|
43
|
+
pythonpath = ["."]
|
|
44
|
+
env = [
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[[tool.mypy.overrides]]
|
|
48
|
+
module = [
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
ignore_missing_imports = true
|
|
52
|
+
[tool.black]
|
|
53
|
+
line-length = 120
|
|
54
|
+
target-version = ['py313']
|
|
55
|
+
include = '\.pyi?$'
|
|
56
|
+
skip-string-normalization = true
|
|
57
|
+
# 'extend-exclude' excludes files or directories in addition to the defaults
|
|
58
|
+
extend-exclude = '''
|
|
59
|
+
# A regex preceded with ^/ will apply only to files and directories
|
|
60
|
+
# in the root of the project.
|
|
61
|
+
(
|
|
62
|
+
^/foo.py # exclude a file named foo.py in the root of the project
|
|
63
|
+
| .*_pb2.py # exclude autogenerated Protocol Buffer files anywhere in the project
|
|
64
|
+
)
|
|
65
|
+
'''
|
|
66
|
+
|