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

@@ -11,7 +11,7 @@ class AuthoritiesRecordNormalizer(RecordNormalizer):
11
11
  """ Normalize authorities records """
12
12
 
13
13
  def __init__(self, linking_results: List[dict] = [], sierra_data: List[dict] = [],
14
- classified_fields: List[str] = [],
14
+ classified_fields: List[List[dict]] = [],
15
15
  ALLOW_EDIT_FIELDS: List[str] = ["008", "925"],
16
16
  REPEATABLE_FIELDS: List[str] = ["024", "035", "400", "667"]):
17
17
 
@@ -34,7 +34,7 @@ class RecordNormalizer:
34
34
  entities: List of Full names (str). If included, will use NormLinker to match with normalized records on KATA elastic.
35
35
  """
36
36
 
37
- def __init__(self, linking_results: List[dict] = [], sierra_data: List[dict] = [], classified_fields: List[str] = [],
37
+ def __init__(self, linking_results: List[dict] = [], sierra_data: List[dict] = [], classified_fields: List[List[dict]] = [],
38
38
  ALLOW_EDIT_FIELDS: List[str] = ["925"], REPEATABLE_FIELDS: List[str] = ["667"]):
39
39
 
40
40
  # Include, if will replace existing field
@@ -44,16 +44,16 @@ class RecordNormalizer:
44
44
  # leader applied to new records
45
45
  self.DEFAULT_LEADER = "01682nz a2200349n 4500" # must be 24 digits
46
46
 
47
- def _setup_records(self, linking_results: List[dict], sierra_data: List[dict], classified_fields: List[str] = []) -> JSONReader:
47
+ def _setup_records(self, linking_results: List[dict], sierra_data: List[dict], classified_fields: List[List[dict]] = []) -> JSONReader:
48
48
  """Setup initial MARC records and data.
49
49
 
50
50
  If no linked entities or more than one linked entity found, we create a new record.
51
51
  If one linked entity found, we create an updated record from the linked entity data.
52
52
  """
53
-
54
53
  linked_records = []
55
-
56
- for linked in linking_results or []:
54
+
55
+ for idx, linked in enumerate(linking_results or []):
56
+
57
57
  if not isinstance(linked, dict):
58
58
  continue
59
59
 
@@ -70,12 +70,12 @@ class RecordNormalizer:
70
70
  })
71
71
  self.records_extra_data.append({
72
72
  "entity": entity,
73
- "classified_fields": classified_fields,
73
+ "classified_fields": classified_fields[idx] if idx < len(classified_fields) else [],
74
74
  "edited": False
75
75
  })
76
76
  continue
77
77
 
78
- if len(linked_info) > 1:
78
+ elif len(linked_info) > 1:
79
79
  # Multiple linked entities found, create new record
80
80
  logger.info(
81
81
  f"Multiple linked entities found for {entity}. Creating new record.")
@@ -85,7 +85,7 @@ class RecordNormalizer:
85
85
  })
86
86
  self.records_extra_data.append({
87
87
  "entity": entity,
88
- "classified_fields": classified_fields,
88
+ "classified_fields": classified_fields[idx] if idx < len(classified_fields) else [],
89
89
  "edited": False
90
90
  })
91
91
  continue
@@ -100,7 +100,7 @@ class RecordNormalizer:
100
100
  self.records_extra_data.append({
101
101
  "entity": entity,
102
102
  "viaf": linked_item.get("viaf", {}),
103
- "classified_fields": classified_fields,
103
+ "classified_fields": classified_fields[idx] if idx < len(classified_fields) else [],
104
104
  "type": "linked",
105
105
  "edited": True
106
106
  })
@@ -359,10 +359,12 @@ class RecordNormalizer:
359
359
  def _include_classified_fields(self, record: Record, classified_fields: list[dict]) -> None:
360
360
  """Include classified fields from core, if any.
361
361
  e.g. classified_fields=[{'670': {'ind1': ' ', 'ind2': '0', 'subfields': [{'a': 'Päikesekiri, 2021'}]}}]
362
+
363
+ For each record, we need a list of dicts, to handle repeatable fields.
362
364
  """
363
365
  if not classified_fields:
364
366
  return
365
-
367
+
366
368
  fields = [
367
369
  Field(
368
370
  tag=str(tag),
@@ -373,7 +375,6 @@ class RecordNormalizer:
373
375
  for tag, v in field_dict.items()
374
376
  ]
375
377
 
376
- logger.info(f"Adding classified fields: {[f.tag for f in fields]}")
377
378
  self._add_fields_to_record(record, fields)
378
379
 
379
380
  def _normalize_common(self, record: Record, is_editing_existing_record: bool, classified_fields: List[dict]) -> None:
@@ -474,6 +475,13 @@ class RecordNormalizer:
474
475
  def _normalize_record(self, record: Record, sierraID: str,
475
476
  viaf_record: VIAFRecord, is_editing_existing_record: bool, original_entity: str) -> Record:
476
477
  return record
478
+
479
+ def get_record(self, index: int) -> Record:
480
+ """Get normalized record by index."""
481
+ for idx, record in enumerate(self):
482
+ if idx == index:
483
+ return record
484
+ raise IndexError("Record index out of range.")
477
485
 
478
486
  @property
479
487
  def data(self) -> List[dict]:
@@ -490,7 +498,7 @@ class RecordNormalizer:
490
498
  @property
491
499
  def first(self) -> Record:
492
500
  return next(iter(self))
493
-
501
+
494
502
  def __iter__(self) -> Iterator:
495
503
  viaf_id_path = "viaf.queryResult.records.record.0.recordData.VIAFCluster.viafID"
496
504
  sierra_id_path = "sierraID"
@@ -12,7 +12,7 @@ class BibRecordNormalizer(RecordNormalizer):
12
12
  """ Normalize bib records. """
13
13
 
14
14
  def __init__(self, linking_results: List[dict] = [], sierra_data: List[dict] = [],
15
- classified_fields: List[str] = [],
15
+ classified_fields: List[List[dict]] = [],
16
16
  ALLOW_EDIT_FIELDS: List[str] = ["008", "925"],
17
17
  REPEATABLE_FIELDS: List[str] = ["667"]):
18
18
  super().__init__(linking_results, sierra_data, classified_fields)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rara-tools
3
- Version: 0.7.14
3
+ Version: 0.7.15
4
4
  Summary: Tools to support Kata's work.
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: Programming Language :: Python :: 3.10
@@ -20,9 +20,9 @@ rara_tools/core_formatters/formatted_keyword.py,sha256=hhi6wh4ErFionjBqYsEeKGbf1
20
20
  rara_tools/core_formatters/formatted_meta.py,sha256=WEnMs8K0YeTLGjXn_mxQTpshxcz5_9YjvqcbRFa3M1g,5605
21
21
  rara_tools/core_formatters/formatted_object.py,sha256=7a499ZmcZXOqtlwxDi6FWHWF5a6HdCsduS22wV3uHIE,5656
22
22
  rara_tools/normalizers/__init__.py,sha256=_NqpS5w710DhaURytHq9JpEt8HgYpSPfRDcOtOymJgE,193
23
- rara_tools/normalizers/authorities.py,sha256=U3IjQW3XaxAiIJ30Jlq6ON8fdXgrtgNwrvX8oy_iKL0,5304
24
- rara_tools/normalizers/base.py,sha256=SkbzmAOX5C6PbEFC9i_mpzK1u6LMAh7PavG52ULeO2Y,19744
25
- rara_tools/normalizers/bibs.py,sha256=DMjJj1mCVVWRpL2NuR6b7W1RWqkx50xix34X_tyxJig,3931
23
+ rara_tools/normalizers/authorities.py,sha256=iW3cYOqqVJKy4CcnG9_T6dN-1bBT1e-0jtLYvco-MyQ,5311
24
+ rara_tools/normalizers/base.py,sha256=LzjQ6HZEdsnEbQzhTRJU23f16nch7ZgM6efXEY45zNY,20190
25
+ rara_tools/normalizers/bibs.py,sha256=s8NGoieCjiftASUb--1YvYZ0VzW6uBt2ZidhLi_wP9A,3938
26
26
  rara_tools/normalizers/reader.py,sha256=GYCkAtnsNx135w5lD-_MqCZzdHQHHPDF-pDxYj839Vo,1595
27
27
  rara_tools/normalizers/viaf.py,sha256=C-NfbvL83ZcHVB9ICMw43wAMYKTqDTHU3ZT2mXKec00,24288
28
28
  rara_tools/parsers/marc_parsers/base_parser.py,sha256=Kdw4aivJf2FkWgIK7pJtHtVXF_G1pjHVQ7IcFItSqy8,1649
@@ -39,8 +39,8 @@ rara_tools/parsers/marc_records/title_record.py,sha256=XrtJ4gj7wzSaGxNaPtPuawmqq
39
39
  rara_tools/parsers/tools/entity_normalizers.py,sha256=VyCy_NowCLpOsL0luQ55IW-Qi-J5oBH0Ofzr7HRFBhM,8949
40
40
  rara_tools/parsers/tools/marc_converter.py,sha256=LgSHe-7n7aiDrw2bnsB53r3fXTRFjZXTwBYfTpL0pfs,415
41
41
  rara_tools/parsers/tools/russian_transliterator.py,sha256=5ZU66iTqAhr7pmfVqXPAI_cidF43VqqmuN4d7H4_JuA,9770
42
- rara_tools-0.7.14.dist-info/licenses/LICENSE.md,sha256=hkZVnIZll7e_KNEQzeY94Y9tlzVL8iVZBTMBvDykksU,35142
43
- rara_tools-0.7.14.dist-info/METADATA,sha256=GIybax1V5ZqALB6SH-oN-e0Cu9-0dbt7rRph7lsEY-Q,4080
44
- rara_tools-0.7.14.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
45
- rara_tools-0.7.14.dist-info/top_level.txt,sha256=JwfB5b8BAtW5OFKRln2AQ_WElTRyIBM4nO0FKN1cupY,11
46
- rara_tools-0.7.14.dist-info/RECORD,,
42
+ rara_tools-0.7.15.dist-info/licenses/LICENSE.md,sha256=hkZVnIZll7e_KNEQzeY94Y9tlzVL8iVZBTMBvDykksU,35142
43
+ rara_tools-0.7.15.dist-info/METADATA,sha256=_McWtiEQK0TGptlidWNxJ26zgdWB_kNk00DSrIAhtB8,4080
44
+ rara_tools-0.7.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
45
+ rara_tools-0.7.15.dist-info/top_level.txt,sha256=JwfB5b8BAtW5OFKRln2AQ_WElTRyIBM4nO0FKN1cupY,11
46
+ rara_tools-0.7.15.dist-info/RECORD,,