philoch-bib-sdk 0.1.1rc1__tar.gz → 0.1.2__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 → philoch_bib_sdk-0.1.2}/PKG-INFO +1 -1
- philoch_bib_sdk-0.1.2/philoch_bib_sdk/__init__.py +0 -0
- philoch_bib_sdk-0.1.2/philoch_bib_sdk/py.typed +0 -0
- {philoch_bib_sdk-0.1.1rc1 → philoch_bib_sdk-0.1.2}/pyproject.toml +1 -1
- philoch_bib_sdk-0.1.1rc1/philoch_bib_sdk/logic/formatters.py +0 -89
- philoch_bib_sdk-0.1.1rc1/philoch_bib_sdk/logic/parsers.py +0 -177
- {philoch_bib_sdk-0.1.1rc1 → philoch_bib_sdk-0.1.2}/LICENSE +0 -0
- {philoch_bib_sdk-0.1.1rc1 → philoch_bib_sdk-0.1.2}/README.md +0 -0
- {philoch_bib_sdk-0.1.1rc1 → philoch_bib_sdk-0.1.2}/philoch_bib_sdk/logic/literals.py +0 -0
- {philoch_bib_sdk-0.1.1rc1 → philoch_bib_sdk-0.1.2}/philoch_bib_sdk/logic/models.py +0 -0
|
File without changes
|
|
File without changes
|
|
@@ -1,89 +0,0 @@
|
|
|
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
|
|
@@ -1,177 +0,0 @@
|
|
|
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
|
-
# )
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|