rara-tools 0.4.3__py3-none-any.whl → 0.4.4__py3-none-any.whl
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.
Potentially problematic release.
This version of rara-tools might be problematic. Click here for more details.
- rara_tools/converters.py +42 -4
- {rara_tools-0.4.3.dist-info → rara_tools-0.4.4.dist-info}/METADATA +1 -1
- {rara_tools-0.4.3.dist-info → rara_tools-0.4.4.dist-info}/RECORD +6 -6
- {rara_tools-0.4.3.dist-info → rara_tools-0.4.4.dist-info}/WHEEL +1 -1
- {rara_tools-0.4.3.dist-info → rara_tools-0.4.4.dist-info}/licenses/LICENSE.md +0 -0
- {rara_tools-0.4.3.dist-info → rara_tools-0.4.4.dist-info}/top_level.txt +0 -0
rara_tools/converters.py
CHANGED
|
@@ -14,9 +14,46 @@ class SierraResponseConverter:
|
|
|
14
14
|
def _map_control_fields(field: dict) -> dict:
|
|
15
15
|
# for tags < 010, no subfields, instead one str value in "value"
|
|
16
16
|
return {field["tag"]: field["value"]}
|
|
17
|
+
|
|
18
|
+
def _map_data_field_subfields(self, subfields: list) -> list:
|
|
19
|
+
""" Maps data field subfields to the standardised format, if necessary.
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
Args:
|
|
22
|
+
subfields (list): List of subfields in format e.g
|
|
23
|
+
"subfields": [
|
|
24
|
+
{
|
|
25
|
+
"code": "a",
|
|
26
|
+
"data": "foo"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"code": "c",
|
|
30
|
+
"data": "by me."
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
list: standardised marc-in-json format. e.g
|
|
36
|
+
"subfields": [
|
|
37
|
+
{ "a": "foo /" },
|
|
38
|
+
{ "c": "by me." }
|
|
39
|
+
]
|
|
40
|
+
"""
|
|
41
|
+
result = []
|
|
42
|
+
for subfield in subfields:
|
|
43
|
+
|
|
44
|
+
code = subfield.get("code")
|
|
45
|
+
data = subfield.get("data")
|
|
46
|
+
|
|
47
|
+
if not code or not data:
|
|
48
|
+
# assume that the subfield is already in the correct format
|
|
49
|
+
return subfields
|
|
50
|
+
else:
|
|
51
|
+
result.append({code: data})
|
|
52
|
+
|
|
53
|
+
return result
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _map_data_fields(self, field: dict) -> dict:
|
|
20
57
|
""" Maps marc fields > 010.
|
|
21
58
|
|
|
22
59
|
Args:
|
|
@@ -27,12 +64,13 @@ class SierraResponseConverter:
|
|
|
27
64
|
"""
|
|
28
65
|
|
|
29
66
|
data = field["data"]
|
|
67
|
+
subfields = data.get("subfields", [])
|
|
30
68
|
|
|
31
69
|
# Order matters ind1, in2, subfields
|
|
32
70
|
field_data = {
|
|
33
71
|
"ind1": data.get("ind1", " "),
|
|
34
72
|
"ind2": data.get("ind2", " "),
|
|
35
|
-
"subfields":
|
|
73
|
+
"subfields": self._map_data_field_subfields(subfields)
|
|
36
74
|
}
|
|
37
75
|
|
|
38
76
|
return {field["tag"]: field_data}
|
|
@@ -41,7 +79,7 @@ class SierraResponseConverter:
|
|
|
41
79
|
def _is_marc21structured(field: dict) -> bool:
|
|
42
80
|
"""Checks if the field is already structured according to MARC21 in JSON"""
|
|
43
81
|
return any(key.isdigit() for key in field.keys())
|
|
44
|
-
|
|
82
|
+
|
|
45
83
|
def _handle_field_type(self, field: dict) -> dict:
|
|
46
84
|
|
|
47
85
|
if self._is_marc21structured(field):
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
rara_tools/converters.py,sha256=
|
|
1
|
+
rara_tools/converters.py,sha256=a1dEMa0TwcO9UmjuSBkiuc7LGmH0d_dB6wwoTLpdZhI,4040
|
|
2
2
|
rara_tools/decorators.py,sha256=MjOyvZ5nTkwxwx2JLFEGpKKBysvecFw6EN6UDrSvZLU,2187
|
|
3
3
|
rara_tools/digar_schema_converter.py,sha256=k95U2iRlEA3sh772-v6snhHW6fju6qSTMnvWJ6DpzZk,14254
|
|
4
4
|
rara_tools/elastic.py,sha256=dw61Z6SxhItNqN35m_3UBy41ppRMhBQLqYriZRo6zGA,13513
|
|
@@ -31,8 +31,8 @@ rara_tools/parsers/marc_records/title_record.py,sha256=0FnX1kl9InELlSqMGECjswEbh
|
|
|
31
31
|
rara_tools/parsers/tools/entity_normalizers.py,sha256=afOMqJoL4aeq0cfsohIuxkxzvqNdZ_ba7U32eyogbzk,8722
|
|
32
32
|
rara_tools/parsers/tools/marc_converter.py,sha256=PUbggzJ_wHfke_bHTF2LOZyzX1t0wRM8qIFL36Dl3AI,414
|
|
33
33
|
rara_tools/parsers/tools/russian_transliterator.py,sha256=5ZU66iTqAhr7pmfVqXPAI_cidF43VqqmuN4d7H4_JuA,9770
|
|
34
|
-
rara_tools-0.4.
|
|
35
|
-
rara_tools-0.4.
|
|
36
|
-
rara_tools-0.4.
|
|
37
|
-
rara_tools-0.4.
|
|
38
|
-
rara_tools-0.4.
|
|
34
|
+
rara_tools-0.4.4.dist-info/licenses/LICENSE.md,sha256=hkZVnIZll7e_KNEQzeY94Y9tlzVL8iVZBTMBvDykksU,35142
|
|
35
|
+
rara_tools-0.4.4.dist-info/METADATA,sha256=mUnO4FnBrYwmUWwx2ukdsg4SD7pfVWBhd3r7RTv1iYU,4054
|
|
36
|
+
rara_tools-0.4.4.dist-info/WHEEL,sha256=ooBFpIzZCPdw3uqIQsOo4qqbA4ZRPxHnOH7peeONza0,91
|
|
37
|
+
rara_tools-0.4.4.dist-info/top_level.txt,sha256=JwfB5b8BAtW5OFKRln2AQ_WElTRyIBM4nO0FKN1cupY,11
|
|
38
|
+
rara_tools-0.4.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|