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

@@ -117,7 +117,9 @@ class AuthoritiesRecordNormalizer(RecordNormalizer):
117
117
  self._add_author(record, viaf_record)
118
118
 
119
119
  def _normalize_record(self, record: Record, sierraID: str,
120
- viaf_record: VIAFRecord, is_editing_existing_record: bool) -> Record:
120
+ viaf_record: VIAFRecord,
121
+ is_editing_existing_record: bool,
122
+ original_entity: str) -> Record:
121
123
 
122
124
  self._normalize_sierra(record, sierraID)
123
125
  self._normalize_viaf(record, viaf_record)
@@ -360,7 +360,7 @@ class RecordNormalizer:
360
360
  return viaf_record
361
361
 
362
362
  def _normalize_record(self, record: Record, sierraID: str,
363
- viaf_record: VIAFRecord, is_editing_existing_record: bool) -> Record:
363
+ viaf_record: VIAFRecord, is_editing_existing_record: bool, original_entity: str) -> Record:
364
364
  return record
365
365
 
366
366
  @property
@@ -374,7 +374,11 @@ class RecordNormalizer:
374
374
  logger.error(f"Failed to normalize record: {e}")
375
375
  continue
376
376
  return result
377
-
377
+
378
+ @property
379
+ def first(self) -> Record:
380
+ return next(iter(self))
381
+
378
382
  def __iter__(self) -> Iterator:
379
383
  viaf_id_path = "viaf.queryResult.records.record.0.recordData.VIAFCluster.viafID"
380
384
  sierra_id_path = "sierraID"
@@ -391,7 +395,7 @@ class RecordNormalizer:
391
395
  record = self._normalize_common(record, is_editing_existing_record)
392
396
 
393
397
  normalized_record = self._normalize_record(
394
- record, sierra_id, viaf_record, is_editing_existing_record)
398
+ record, sierra_id, viaf_record, is_editing_existing_record, original_entity=entity)
395
399
 
396
400
  normalized_record.fields.sort(key=lambda field: field.tag)
397
401
 
@@ -1,4 +1,5 @@
1
1
  from pymarc import (Field, Subfield, Record)
2
+ from typing import List, Optional
2
3
 
3
4
  from rara_tools.constants import EMPTY_INDICATORS
4
5
  from rara_tools.normalizers.viaf import VIAFRecord
@@ -34,10 +35,57 @@ class BibRecordNormalizer(RecordNormalizer):
34
35
  ]
35
36
 
36
37
  self._add_fields_to_record(record, fields)
38
+
39
+ def _include_name_variations(self, record: Record, viaf_record: VIAFRecord) -> None:
40
+ """ Include name variations from VIAF record as 400|t fields """
41
+
42
+ if not viaf_record or not viaf_record.name_variations:
43
+ return
44
+
45
+ existing_name_variations = record.get_fields("400")
46
+ existing_variations = [sf.value for field in existing_name_variations for sf in field.get_subfields("t")]
47
+
48
+ fields = []
49
+
50
+ for variation in viaf_record.name_variations:
51
+ if variation not in existing_variations:
52
+ fields.append(
53
+ Field(
54
+ tag="400",
55
+ indicators=EMPTY_INDICATORS,
56
+ subfields=[
57
+ Subfield("t", variation)
58
+ ]
59
+ )
60
+ )
61
+
62
+ self._add_fields_to_record(record, fields)
63
+
64
+ def _add_author(self, record: Record, viaf_record: Optional[VIAFRecord], original_entity: str) -> Optional[Field]:
65
+ if record.get("100") or record.get("110") or record.get("111"):
66
+ return record
37
67
 
38
- def _normalize_viaf(self, record: Record, viaf_record: VIAFRecord) -> None:
68
+ type_map = {
69
+ "Personal": "100",
70
+ "Corporate": "110",
71
+ "Collective": "111"
72
+ }
73
+
74
+ tag = type_map.get(getattr(viaf_record, "name_type", None), "100")
75
+ title = getattr(viaf_record, "name", None) or original_entity
39
76
 
77
+ fields = [Field(tag=tag, indicators=EMPTY_INDICATORS, subfields=[Subfield("t", title)])]
78
+
79
+ self._add_fields_to_record(record, fields)
80
+
81
+ if viaf_record:
82
+ self._include_name_variations(record, viaf_record)
83
+
84
+ def _normalize_viaf(self, record: Record, viaf_record: VIAFRecord, original_entity: str) -> None:
85
+
40
86
  if not viaf_record:
87
+ # viaf record not found, include original entity as 100|t
88
+ self._add_author(record, viaf_record=None, original_entity=original_entity)
41
89
  return record
42
90
 
43
91
  viaf_id = viaf_record.viaf_id
@@ -52,12 +100,12 @@ class BibRecordNormalizer(RecordNormalizer):
52
100
  ]
53
101
 
54
102
  self._add_fields_to_record(record, fields)
55
- self._add_author(record, viaf_record)
103
+ self._add_author(record, viaf_record, original_entity=original_entity)
56
104
 
57
105
  def _normalize_record(self, record: Record, sierraID: str,
58
- viaf_record: VIAFRecord, is_editing_existing_record: bool) -> Record:
106
+ viaf_record: VIAFRecord, is_editing_existing_record: bool, original_entity: str) -> Record:
59
107
 
60
108
  self._normalize_sierra(record)
61
- self._normalize_viaf(record, viaf_record)
109
+ self._normalize_viaf(record, viaf_record, original_entity=original_entity)
62
110
 
63
111
  return record
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rara-tools
3
- Version: 0.7.10
3
+ Version: 0.7.11
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=r0RPG4eM-REPIR1DrIJnvYPQtQrzkgdvX9tvhNWjQ0Y,5250
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=7YlUFlhQTCJOT7umcrZE2Td_w1YIpBxVqW0b7rBDTbU,4645
24
- rara_tools/normalizers/base.py,sha256=BpRI2BSA9qKW0ux3rFJMTQsxjPB8gYObHtcvDoJwMOU,15256
25
- rara_tools/normalizers/bibs.py,sha256=5NZooArBYaRE_MCG2g3A4kxiRzMoXAqGkx_hCbPzKlM,2018
23
+ rara_tools/normalizers/authorities.py,sha256=0R1YpZCVtwKj1fgzLvPYfw-R4v_hBocB9dHwMF2JR7c,4720
24
+ rara_tools/normalizers/base.py,sha256=wiza01rldAhdH5rszE0z7ehE8EHSeKnNb-RmetFiZYE,15388
25
+ rara_tools/normalizers/bibs.py,sha256=7H-spiqj6x8Xk4JQkBY5GK7q5pKjYUmXTRFf0RgzC-w,4040
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.10.dist-info/licenses/LICENSE.md,sha256=hkZVnIZll7e_KNEQzeY94Y9tlzVL8iVZBTMBvDykksU,35142
43
- rara_tools-0.7.10.dist-info/METADATA,sha256=hQFvtq4KzNHR_aDzynXw2WJH-HbdKJshP0oYoy1kmss,4080
44
- rara_tools-0.7.10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
45
- rara_tools-0.7.10.dist-info/top_level.txt,sha256=JwfB5b8BAtW5OFKRln2AQ_WElTRyIBM4nO0FKN1cupY,11
46
- rara_tools-0.7.10.dist-info/RECORD,,
42
+ rara_tools-0.7.11.dist-info/licenses/LICENSE.md,sha256=hkZVnIZll7e_KNEQzeY94Y9tlzVL8iVZBTMBvDykksU,35142
43
+ rara_tools-0.7.11.dist-info/METADATA,sha256=OvVJG6looJ5yhNhMJ-jUV74t1u6aymlzajNqMokUa54,4080
44
+ rara_tools-0.7.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
45
+ rara_tools-0.7.11.dist-info/top_level.txt,sha256=JwfB5b8BAtW5OFKRln2AQ_WElTRyIBM4nO0FKN1cupY,11
46
+ rara_tools-0.7.11.dist-info/RECORD,,