rara-tools 0.1.0__py3-none-any.whl → 0.2.0__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.

@@ -0,0 +1 @@
1
+ from .normalizers import *
@@ -0,0 +1,17 @@
1
+ from pymarc import Indicators
2
+ import os
3
+
4
+ EMPTY_INDICATORS = Indicators(" ", " ")
5
+ VIAF_ALLOWED_SOURCES = ["LC", "DNB", "LNB", "NLL",
6
+ "ERRR", "J9U"]
7
+
8
+ ES_HOST = os.getenv("ELASTIC_TEST_URL", "http://localhost:9200")
9
+
10
+ LINKER_CONFIG = {
11
+ "add_viaf_info": True,
12
+ "vectorizer_data_path": "./vectorizer_data",
13
+ "per_config": {"es_host": ES_HOST},
14
+ "org_config": {"es_host": ES_HOST},
15
+ "loc_config": {"es_host": ES_HOST},
16
+ "ems_config": {"es_host": ES_HOST},
17
+ }
rara_tools/converters.py CHANGED
@@ -1,19 +1,22 @@
1
- from .exceptions import SierraResponseConverterException
1
+ from rara_tools.exceptions import SierraResponseConverterException
2
2
 
3
3
 
4
4
  class SierraResponseConverter:
5
5
  """Converts a JSON response from the Sierra API to MARC-in-JSON format."""
6
-
6
+
7
7
  def __init__(self, response: dict):
8
8
  if not isinstance(response, dict):
9
- raise SierraResponseConverterException("Please provide a valid JSON response.")
9
+ raise SierraResponseConverterException(
10
+ "Please provide a valid JSON response.")
10
11
  self.response = response
11
-
12
- def _map_control_fields(self, field: dict) -> dict:
13
- # for tags < 010, no subfields, instead one str value in "value"
12
+
13
+ @staticmethod
14
+ def _map_control_fields(field: dict) -> dict:
15
+ # for tags < 010, no subfields, instead one str value in "value"
14
16
  return {field["tag"]: field["value"]}
15
-
16
- def _map_data_fields(self, field: dict) -> dict:
17
+
18
+ @staticmethod
19
+ def _map_data_fields(field: dict) -> dict:
17
20
  """ Maps marc fields > 010.
18
21
 
19
22
  Args:
@@ -22,60 +25,66 @@ class SierraResponseConverter:
22
25
  Returns:
23
26
  dict: standardised marc-in-json format.
24
27
  """
25
-
28
+
26
29
  data = field["data"]
27
-
30
+
28
31
  # Order matters ind1, in2, subfields
29
32
  field_data = {
30
33
  "ind1": data.get("ind1", " "),
31
34
  "ind2": data.get("ind2", " "),
32
35
  "subfields": data.get("subfields", [])
33
36
  }
34
-
37
+
35
38
  return {field["tag"]: field_data}
36
-
37
- def _is_marc21structured(self, field: dict) -> bool:
39
+
40
+ @staticmethod
41
+ def _is_marc21structured(field: dict) -> bool:
38
42
  """Checks if the field is already structured according to MARC21 in JSON"""
39
43
  return any(key.isdigit() for key in field.keys())
40
-
41
-
44
+
42
45
  def _handle_field_type(self, field: dict) -> dict:
43
-
46
+
44
47
  if self._is_marc21structured(field):
45
48
  return field
46
-
49
+
47
50
  if field.get("data"):
48
51
  return self._map_data_fields(field)
49
-
52
+
50
53
  tag = field.get("tag")
51
-
54
+
52
55
  if not tag:
53
- raise SierraResponseConverterException("Field is missing MARC21 tag.")
54
-
56
+ raise SierraResponseConverterException(
57
+ "Field is missing MARC21 tag.")
58
+
55
59
  if tag < "010":
56
60
  return self._map_control_fields(field)
57
61
  else:
58
62
  return self._map_data_fields(field)
59
-
63
+
60
64
  def _convert_response(self) -> list:
61
65
  entries = self.response.get("entries")
62
66
  if not entries:
63
- raise SierraResponseConverterException("No entries found in the response.")
64
-
67
+ raise SierraResponseConverterException(
68
+ "No entries found in the response.")
69
+
65
70
  try:
66
- return {"fields": [
67
- {e["id"]: [
68
- self._handle_field_type(f) for f in e["marc"]["fields"]
71
+ return [
72
+ {
73
+ "sierraID": str(e["id"]),
74
+ "leader": e["marc"]["leader"],
75
+ "fields": [
76
+ self._handle_field_type(f) for f in e["marc"]["fields"]
69
77
  ]}
70
78
  for e in entries
71
- ]}
72
-
79
+ ]
80
+
73
81
  except KeyError as e:
74
- raise SierraResponseConverterException(f"Malformed response: missing key {e}")
75
-
76
-
82
+ raise SierraResponseConverterException(
83
+ f"Malformed response: missing key {e}")
84
+
77
85
  def convert(self) -> list:
78
86
  try:
79
87
  return self._convert_response()
80
88
  except Exception as e:
81
- raise SierraResponseConverterException(f"An unexpected error occurred: {e}")
89
+ raise SierraResponseConverterException(
90
+ f"An unexpected error occurred: {e}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rara-tools
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: Tools to support Kata's work.
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: Programming Language :: Python :: 3.10
@@ -13,8 +13,11 @@ License-File: LICENSE.md
13
13
  Requires-Dist: elasticsearch==8.*
14
14
  Requires-Dist: elasticsearch_dsl==8.*
15
15
  Requires-Dist: minio==7.*
16
+ Requires-Dist: rara-norm-linker==1.*
16
17
  Requires-Dist: requests
17
18
  Requires-Dist: iso639-lang
19
+ Requires-Dist: pymarc
20
+ Requires-Dist: glom
18
21
  Provides-Extra: testing
19
22
  Requires-Dist: pytest>=8.0; extra == "testing"
20
23
  Requires-Dist: pytest-order; extra == "testing"
@@ -1,4 +1,4 @@
1
- rara_tools/converters.py,sha256=O769zNjde1VCfEUF2VU_49IAbm8NT-cG-VR0uPxixtE,2687
1
+ rara_tools/converters.py,sha256=_1ZRH4ACLOolI1G5b_aSssN68rWOvan-q2dTq7D7-j4,2794
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=MgPHxZ3UbSTIL8_sT9gU5V4PLKJjo3aQ8CGyhXjRz6M,13065
@@ -6,11 +6,12 @@ rara_tools/exceptions.py,sha256=YQyaueUbXeTkJYFDEuN6iWTXMI3eCv5l7PxGp87vg5I,550
6
6
  rara_tools/s3.py,sha256=9ziDXsLjBtFAvsjTPxFddhfvkpA8773rzPJqO7y1N5Q,6415
7
7
  rara_tools/task_reporter.py,sha256=WCcZts9dAUokPc4vbrG3-lNAFLnWaMgE3b3iaUB7mr8,3256
8
8
  rara_tools/utils.py,sha256=9vSbmuWYU5ydr4lXBKlUKa0xzDccFsaJv4T-XwgUfuY,2578
9
- rara_tools/constants/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ rara_tools/constants/__init__.py,sha256=r78laM9vyRDAvzDhPvzDlhaX6qPwUUBBtwf1WosrW3o,27
10
10
  rara_tools/constants/digitizer.py,sha256=MND0dUQySBAOVWzuUBxQGZWv_Ckdz2jCp25F2_oHGi8,496
11
11
  rara_tools/constants/general.py,sha256=aVUQTMss89atAkTDZKJXNdnsBHPX-RSrlBOtt-wdPGU,195
12
- rara_tools-0.1.0.dist-info/licenses/LICENSE.md,sha256=hkZVnIZll7e_KNEQzeY94Y9tlzVL8iVZBTMBvDykksU,35142
13
- rara_tools-0.1.0.dist-info/METADATA,sha256=TM89xbTBJiyz3ZNXbYzLwYi84ChYLDN9Lyo2XZ-posE,3916
14
- rara_tools-0.1.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
15
- rara_tools-0.1.0.dist-info/top_level.txt,sha256=JwfB5b8BAtW5OFKRln2AQ_WElTRyIBM4nO0FKN1cupY,11
16
- rara_tools-0.1.0.dist-info/RECORD,,
12
+ rara_tools/constants/normalizers.py,sha256=eM-REyHen8MdBRYD0s2fQcYrvWxDwWfZlYGpBvdLog0,494
13
+ rara_tools-0.2.0.dist-info/licenses/LICENSE.md,sha256=hkZVnIZll7e_KNEQzeY94Y9tlzVL8iVZBTMBvDykksU,35142
14
+ rara_tools-0.2.0.dist-info/METADATA,sha256=YgPsOKoNplzOs4PVlgJX9eaw65iTSfD9C-Ba374fK2A,3995
15
+ rara_tools-0.2.0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
16
+ rara_tools-0.2.0.dist-info/top_level.txt,sha256=JwfB5b8BAtW5OFKRln2AQ_WElTRyIBM4nO0FKN1cupY,11
17
+ rara_tools-0.2.0.dist-info/RECORD,,