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

@@ -1,13 +1,14 @@
1
1
  from typing import List, NoReturn, Tuple
2
2
  from abc import abstractmethod
3
3
  from pymarc.record import Record
4
+ from pymarc.marcjson import JSONHandler
4
5
  from rara_tools.constants.parsers import GeneralMarcIDs
5
6
 
6
7
 
7
8
  class BaseRecord:
8
9
  """ Implements general logic of parsing MARC files.
9
10
  """
10
- def __init__(self, record: Record, add_variations: bool = False) -> NoReturn:
11
+ def __init__(self, record: Record | dict, add_variations: bool = False) -> NoReturn:
11
12
  """ Initializes BaseRecord object.
12
13
 
13
14
  Parameters
@@ -21,8 +22,8 @@ class BaseRecord:
21
22
  via rara-norm-linker, it is necessary to enable this.
22
23
  """
23
24
  self.add_variations: bool = add_variations
24
- self.__record_mrc: Record = record
25
- self.__record_dict: dict = record.as_dict()["fields"]
25
+ self.__record_marc: Record = self._get_record_marc(record)
26
+ self.__record_dict: dict = self.marc_record.as_dict()["fields"]
26
27
 
27
28
  self.__id_field_id: List[str] = GeneralMarcIDs.ID
28
29
  self.__id_source_field_id: List[str] = GeneralMarcIDs.ID_SOURCE
@@ -30,6 +31,13 @@ class BaseRecord:
30
31
  self.__identifier: str = ""
31
32
  self.__identifier_source: str = ""
32
33
 
34
+ def _get_record_marc(self, record: Record | dict) -> Record:
35
+ """ Converts dict-type records into pymarc.Record objects.
36
+ """
37
+ if isinstance(record, dict):
38
+ record = JSONHandler().elements([record])[0]
39
+ return record
40
+
33
41
  def get_values(self,
34
42
  marc_ids: List[str],
35
43
  subfield_id: str | List[str] = "",
@@ -101,7 +109,7 @@ class BaseRecord:
101
109
 
102
110
  @property
103
111
  def marc_record(self) -> Record:
104
- return self.__record_mrc
112
+ return self.__record_marc
105
113
 
106
114
  @property
107
115
  def marc_json_record(self) -> dict:
@@ -1,7 +1,7 @@
1
1
  from typing import List, NoReturn
2
2
  from pymarc.record import Record
3
3
  from rara_tools.parsers.marc_records.base_record import BaseRecord
4
- from rara_tools.constants.parsers import OrganizationMarcIDs
4
+ from rara_tools.constants.parsers import OrganizationMarcIDs, LOGGER
5
5
  import regex as re
6
6
  import json
7
7
 
@@ -38,9 +38,9 @@ class OrganizationRecord(BaseRecord):
38
38
  self.__name: str = ""
39
39
  self.__original_name: dict = {}
40
40
  self.__name_specification: str = ""
41
- self.__life_years: str = ""
42
- self.__birth_year: int = -1
43
- self.__death_year: int = -1
41
+ self.__dates: str = ""
42
+ self.__location: str = ""
43
+ self.__numeration: str = ""
44
44
  self.__name_variations: List[str] = []
45
45
  self.__source: str = ""
46
46
  self.__description: str = ""
@@ -57,7 +57,10 @@ class OrganizationRecord(BaseRecord):
57
57
 
58
58
 
59
59
  def _clean_value(self, value: str) -> str:
60
- cleaned_value = value.strip("., ")
60
+ try:
61
+ cleaned_value = value.strip("., ")
62
+ except Exception as e:
63
+ cleaned_value = ""
61
64
  return cleaned_value
62
65
 
63
66
  def _merge_and_clean(self, value: dict, keys: List[str]) -> str:
@@ -82,7 +85,10 @@ class OrganizationRecord(BaseRecord):
82
85
  "b": self._clean_value(values[0].get("b", ""))
83
86
  }
84
87
  else:
85
- print(self.marc_record)
88
+ LOGGER.info(
89
+ f"Could not parse subfields 'a' and/or 'b' from " \
90
+ f"field {self.__name_field_id}. Record:\n{self.marc_record}"
91
+ )
86
92
  return self.__original_name
87
93
 
88
94
  @property
@@ -91,6 +97,39 @@ class OrganizationRecord(BaseRecord):
91
97
  self.__name = self._merge_and_clean(self.original_name, ["a", "b"])
92
98
  return self.__name
93
99
 
100
+ @property
101
+ def dates(self) -> str:
102
+ if not self.__dates:
103
+ values = self.get_values(
104
+ marc_ids=self.__name_field_id,
105
+ subfield_id="d"
106
+ )
107
+ if values:
108
+ self.__dates = self._clean_value(values[0])
109
+ return self.__dates
110
+
111
+ @property
112
+ def location(self) -> str:
113
+ if not self.__location:
114
+ values = self.get_values(
115
+ marc_ids=self.__name_field_id,
116
+ subfield_id="c"
117
+ )
118
+ if values:
119
+ self.__location = self._clean_value(values[0])
120
+ return self.__location
121
+
122
+ @property
123
+ def numeration(self) -> str:
124
+ if not self.__numeration:
125
+ values = self.get_values(
126
+ marc_ids=self.__name_field_id,
127
+ subfield_id="n"
128
+ )
129
+ if values:
130
+ self.__numeration = self._clean_value(values[0])
131
+ return self.__numeration
132
+
94
133
  @property
95
134
  def acronyms(self) -> List[str]:
96
135
  if not self.__acronyms:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rara-tools
3
- Version: 0.6.11
3
+ Version: 0.6.13
4
4
  Summary: Tools to support Kata's work.
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: Programming Language :: Python :: 3.10
@@ -26,16 +26,16 @@ rara_tools/parsers/marc_parsers/location_parser.py,sha256=dSU9dQoGV5z0ajhLI1bn3A
26
26
  rara_tools/parsers/marc_parsers/organization_parser.py,sha256=faqQEYsut_ZF3kX1QycTnbRIqC7W8sULxmG75ICfya8,1629
27
27
  rara_tools/parsers/marc_parsers/person_parser.py,sha256=iMycHSlgfvgB0axE_rneB5sImVlc920FcBnTsUsmVW4,1582
28
28
  rara_tools/parsers/marc_parsers/title_parser.py,sha256=uZiYb_aZWzv_xLEBSZmFt2vN6UIauNSFRCkNG_ZKL10,1570
29
- rara_tools/parsers/marc_records/base_record.py,sha256=05XW1oQ5fCJWxBpmBFwGVGLChGE0P605HNUdvXGiif8,4330
29
+ rara_tools/parsers/marc_records/base_record.py,sha256=yllX2ArjBm9PfUnH6dk3__Rb2LQuEGCYqZGVKBzqSl0,4673
30
30
  rara_tools/parsers/marc_records/ems_record.py,sha256=B2YZLEeDd-GmmYqxhczbMsSEB7-x6ZLjB8OeDnzOxww,9376
31
- rara_tools/parsers/marc_records/organization_record.py,sha256=HmDqAqAL_Tw7ppEsS5HfogrfNuQMNChCkrdPu6K-SUE,9141
31
+ rara_tools/parsers/marc_records/organization_record.py,sha256=WFmmMBiZUhaIMh-j06ChH37JLT7yFG7ZDc_0keqjIYo,10355
32
32
  rara_tools/parsers/marc_records/person_record.py,sha256=AtGESwFmN5YvrBES0BsfTgOZbroB4l0SuFRznumfmJA,7867
33
33
  rara_tools/parsers/marc_records/title_record.py,sha256=XrtJ4gj7wzSaGxNaPtPuawmqqkXsVX5HAAKfXTSo4mA,6855
34
34
  rara_tools/parsers/tools/entity_normalizers.py,sha256=VyCy_NowCLpOsL0luQ55IW-Qi-J5oBH0Ofzr7HRFBhM,8949
35
35
  rara_tools/parsers/tools/marc_converter.py,sha256=LgSHe-7n7aiDrw2bnsB53r3fXTRFjZXTwBYfTpL0pfs,415
36
36
  rara_tools/parsers/tools/russian_transliterator.py,sha256=5ZU66iTqAhr7pmfVqXPAI_cidF43VqqmuN4d7H4_JuA,9770
37
- rara_tools-0.6.11.dist-info/licenses/LICENSE.md,sha256=hkZVnIZll7e_KNEQzeY94Y9tlzVL8iVZBTMBvDykksU,35142
38
- rara_tools-0.6.11.dist-info/METADATA,sha256=QzQV8b9zxNtmjVx2i2w2j96NDzPSLzA0XrOZIYrwQIw,4080
39
- rara_tools-0.6.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
40
- rara_tools-0.6.11.dist-info/top_level.txt,sha256=JwfB5b8BAtW5OFKRln2AQ_WElTRyIBM4nO0FKN1cupY,11
41
- rara_tools-0.6.11.dist-info/RECORD,,
37
+ rara_tools-0.6.13.dist-info/licenses/LICENSE.md,sha256=hkZVnIZll7e_KNEQzeY94Y9tlzVL8iVZBTMBvDykksU,35142
38
+ rara_tools-0.6.13.dist-info/METADATA,sha256=P_y0fL650yYO1aN0Db2d_2pq93g99ytU8_pNq6kl0iY,4080
39
+ rara_tools-0.6.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
40
+ rara_tools-0.6.13.dist-info/top_level.txt,sha256=JwfB5b8BAtW5OFKRln2AQ_WElTRyIBM4nO0FKN1cupY,11
41
+ rara_tools-0.6.13.dist-info/RECORD,,