rara-tools 0.6.13__tar.gz → 0.6.14__tar.gz

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.

Files changed (64) hide show
  1. {rara_tools-0.6.13/rara_tools.egg-info → rara_tools-0.6.14}/PKG-INFO +1 -1
  2. rara_tools-0.6.14/VERSION +1 -0
  3. rara_tools-0.6.14/rara_tools/constants/subject_indexer.py +85 -0
  4. rara_tools-0.6.14/rara_tools/formatters.py +106 -0
  5. {rara_tools-0.6.13 → rara_tools-0.6.14/rara_tools.egg-info}/PKG-INFO +1 -1
  6. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools.egg-info/SOURCES.txt +2 -0
  7. rara_tools-0.6.14/tests/test_formatters.py +15 -0
  8. rara_tools-0.6.13/VERSION +0 -1
  9. rara_tools-0.6.13/rara_tools/constants/subject_indexer.py +0 -14
  10. {rara_tools-0.6.13 → rara_tools-0.6.14}/LICENSE.md +0 -0
  11. {rara_tools-0.6.13 → rara_tools-0.6.14}/README.md +0 -0
  12. {rara_tools-0.6.13 → rara_tools-0.6.14}/pyproject.toml +0 -0
  13. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/constants/__init__.py +0 -0
  14. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/constants/digitizer.py +0 -0
  15. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/constants/general.py +0 -0
  16. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/constants/language_evaluator.py +0 -0
  17. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/constants/linker.py +0 -0
  18. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/constants/meta_extractor.py +0 -0
  19. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/constants/normalizers.py +0 -0
  20. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/constants/parsers.py +0 -0
  21. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/converters.py +0 -0
  22. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/decorators.py +0 -0
  23. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/digar_schema_converter.py +0 -0
  24. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/elastic.py +0 -0
  25. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/exceptions.py +0 -0
  26. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/normalizers/__init__.py +0 -0
  27. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/normalizers/authorities.py +0 -0
  28. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/normalizers/base.py +0 -0
  29. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/normalizers/bibs.py +0 -0
  30. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/normalizers/viaf.py +0 -0
  31. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/parsers/marc_parsers/base_parser.py +0 -0
  32. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/parsers/marc_parsers/ems_parser.py +0 -0
  33. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/parsers/marc_parsers/location_parser.py +0 -0
  34. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/parsers/marc_parsers/organization_parser.py +0 -0
  35. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/parsers/marc_parsers/person_parser.py +0 -0
  36. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/parsers/marc_parsers/title_parser.py +0 -0
  37. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/parsers/marc_records/base_record.py +0 -0
  38. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/parsers/marc_records/ems_record.py +0 -0
  39. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/parsers/marc_records/organization_record.py +0 -0
  40. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/parsers/marc_records/person_record.py +0 -0
  41. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/parsers/marc_records/title_record.py +0 -0
  42. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/parsers/tools/entity_normalizers.py +0 -0
  43. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/parsers/tools/marc_converter.py +0 -0
  44. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/parsers/tools/russian_transliterator.py +0 -0
  45. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/s3.py +0 -0
  46. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/task_reporter.py +0 -0
  47. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools/utils.py +0 -0
  48. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools.egg-info/dependency_links.txt +0 -0
  49. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools.egg-info/requires.txt +0 -0
  50. {rara_tools-0.6.13 → rara_tools-0.6.14}/rara_tools.egg-info/top_level.txt +0 -0
  51. {rara_tools-0.6.13 → rara_tools-0.6.14}/requirements.txt +0 -0
  52. {rara_tools-0.6.13 → rara_tools-0.6.14}/setup.cfg +0 -0
  53. {rara_tools-0.6.13 → rara_tools-0.6.14}/tests/test_digar_schema_converter.py +0 -0
  54. {rara_tools-0.6.13 → rara_tools-0.6.14}/tests/test_elastic.py +0 -0
  55. {rara_tools-0.6.13 → rara_tools-0.6.14}/tests/test_elastic_vector_and_search_operations.py +0 -0
  56. {rara_tools-0.6.13 → rara_tools-0.6.14}/tests/test_entity_normalizers.py +0 -0
  57. {rara_tools-0.6.13 → rara_tools-0.6.14}/tests/test_marc_parsers.py +0 -0
  58. {rara_tools-0.6.13 → rara_tools-0.6.14}/tests/test_normalization.py +0 -0
  59. {rara_tools-0.6.13 → rara_tools-0.6.14}/tests/test_s3_exceptions.py +0 -0
  60. {rara_tools-0.6.13 → rara_tools-0.6.14}/tests/test_s3_file_operations.py +0 -0
  61. {rara_tools-0.6.13 → rara_tools-0.6.14}/tests/test_sierra_converters.py +0 -0
  62. {rara_tools-0.6.13 → rara_tools-0.6.14}/tests/test_task_reporter.py +0 -0
  63. {rara_tools-0.6.13 → rara_tools-0.6.14}/tests/test_utils.py +0 -0
  64. {rara_tools-0.6.13 → rara_tools-0.6.14}/tests/test_viaf_client.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rara-tools
3
- Version: 0.6.13
3
+ Version: 0.6.14
4
4
  Summary: Tools to support Kata's work.
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: Programming Language :: Python :: 3.10
@@ -0,0 +1 @@
1
+ 0.6.14
@@ -0,0 +1,85 @@
1
+ from rara_tools.constants.normalizers import EntityType
2
+
3
+ COMPONENT_KEY = "subject_indexer"
4
+
5
+
6
+ class Tasks:
7
+ SINGLE = "run_subject_indexer_process"
8
+ PIPELINE = "run_subject_indexer_with_core_logic"
9
+
10
+
11
+ class Queue:
12
+ MAIN = "subject-indexer"
13
+
14
+
15
+ class StatusKeys:
16
+ EXTRACT_KEYWORDS = "extract_keywords"
17
+
18
+
19
+ class URLSource:
20
+ VIAF = "VIAF"
21
+ SIERRA = "Sierra"
22
+ EMS = "EMS"
23
+
24
+ class KeywordType:
25
+ LOC = "Kohamärksõnad"
26
+ TIME = "Ajamärksõnad"
27
+ TOPIC = "Teemamärksõnad"
28
+ GENRE = "Vormimärksõnad"
29
+ TITLE = "Teose pealkiri"
30
+ PER = "Isikunimi"
31
+ ORG = "Kollektiivi nimi"
32
+ EVENT = "Ajutine kollektiiv või sündmus"
33
+ CATEGORY = "Valdkonnamärksõnad"
34
+ UDC = "UDC Summary"
35
+ UDK = "UDK Rahvusbibliograafia"
36
+
37
+
38
+ class KeywordMARC:
39
+ PER = 600
40
+ ORG = 610
41
+ TOPIC = 650
42
+ GENRE = 655
43
+ TIME = 648
44
+ LOC = 651
45
+ EVENT = 611
46
+ TITLE = 630
47
+
48
+ class KeywordSource:
49
+ EMS = "EMS"
50
+ SIERRA = "SIERRA"
51
+ VIAF = "VIAF"
52
+ AI = "AI"
53
+
54
+
55
+ KEYWORD_TYPE_MAP = {
56
+ KeywordType.TIME: EntityType.KEYWORD,
57
+ KeywordType.GENRE: EntityType.KEYWORD,
58
+ KeywordType.LOC: EntityType.LOC,
59
+ KeywordType.PER: EntityType.PER,
60
+ KeywordType.ORG: EntityType.ORG,
61
+ KeywordType.TOPIC: EntityType.KEYWORD,
62
+ KeywordType.TITLE: EntityType.TITLE,
63
+ KeywordType.EVENT: EntityType.ORG
64
+ }
65
+
66
+ KEYWORD_MARC_MAP = {
67
+ KeywordType.LOC: KeywordMARC.LOC,
68
+ KeywordType.TIME: KeywordMARC.TIME,
69
+ KeywordType.TOPIC: KeywordMARC.TOPIC,
70
+ KeywordType.GENRE: KeywordMARC.GENRE,
71
+ KeywordType.TITLE: KeywordMARC.TITLE,
72
+ KeywordType.ORG: KeywordMARC.ORG,
73
+ KeywordType.PER: KeywordMARC.PER,
74
+ KeywordType.EVENT: KeywordMARC.EVENT
75
+ }
76
+
77
+ KEYWORD_TYPES_TO_IGNORE = [
78
+ KeywordType.CATEGORY,
79
+ KeywordType.UDC,
80
+ KeywordType.UDK
81
+ ]
82
+
83
+ EMS_ENTITY_TYPES = [EntityType.KEYWORD, EntityType.LOC]
84
+ SIERRA_ENTITY_TYPES = [EntityType.PER, EntityType.ORG, EntityType.TITLE]
85
+ VIAF_ENTITY_TYPES = [EntityType.PER, EntityType.ORG, EntityType.TITLE]
@@ -0,0 +1,106 @@
1
+ from typing import List, Tuple, Any
2
+ from rara_tools.constants.subject_indexer import (
3
+ EntityType, KeywordType, KeywordMARC, KeywordSource, URLSource,
4
+ KEYWORD_TYPE_MAP, KEYWORD_MARC_MAP, KEYWORD_TYPES_TO_IGNORE,
5
+ EMS_ENTITY_TYPES, SIERRA_ENTITY_TYPES, VIAF_ENTITY_TYPES
6
+ )
7
+
8
+ def _get_keyword_source(linked_doc: Any, entity_type: str, is_linked: bool
9
+ ) -> str:
10
+ """ Find keyword source.
11
+ """
12
+ if not is_linked:
13
+ source = KeywordSource.AI
14
+ elif entity_type in EMS_ENTITY_TYPES:
15
+ source = KeywordSource.EMS
16
+ elif entity_type in SIERRA_ENTITY_TYPES:
17
+ if linked_doc and linked_doc.elastic:
18
+ source = KeywordSource.SIERRA
19
+ elif linked_doc and linked_doc.viaf:
20
+ source = KeywordSource.VIAF
21
+ else:
22
+ source = KeywordSource.AI
23
+ else:
24
+ source = KeywordSource.AI
25
+ return source
26
+
27
+ def _find_indicators(entity_type: str, entity: str,
28
+ is_linked: bool
29
+ ) -> Tuple[str, str]:
30
+ """ Find MARC indicators 1 and 2.
31
+ """
32
+ ind1 = " "
33
+ ind2 = " "
34
+ if entity_type in SIERRA_ENTITY_TYPES:
35
+ if entity_type == EntityType.PER:
36
+ if "," in entity:
37
+ ind1 = "1"
38
+ else:
39
+ ind1 = "0"
40
+ else:
41
+ # 1 märksõna esimeseks elemendiks võimupiirkonna nimi, nt:
42
+ # (a) Eesti (b) Riigikogu - raske automaatselt määrata
43
+ # 2 märksõna esimeseks elemendiks nimi pärijärjestuses
44
+ ind1 = "2"
45
+ if not is_linked:
46
+ ind2 = "4"
47
+ elif entity_type in EMS_ENTITY_TYPES:
48
+ ind2 = "4"
49
+ return (ind1, ind2)
50
+
51
+
52
+ def format_keywords(flat_keywords: List[dict]) -> dict:
53
+ """ Formats unlinked keywords for Kata CORE.
54
+ """
55
+ ignored_keywords = []
56
+ filtered_keywords = []
57
+
58
+ for keyword_dict in flat_keywords:
59
+ keyword_type = keyword_dict.get("entity_type")
60
+ if keyword_type in KEYWORD_TYPES_TO_IGNORE:
61
+ ignored_keywords.append(keyword_dict)
62
+ else:
63
+ filtered_keywords.append(keyword_dict)
64
+
65
+ formatted_keywords = {
66
+ "keywords": [],
67
+ "other": ignored_keywords
68
+ }
69
+
70
+ for keyword_dict in filtered_keywords:
71
+ original_keyword = keyword_dict.get("keyword")
72
+ keyword_type = keyword_dict.get("entity_type")
73
+ entity_type = KEYWORD_TYPE_MAP.get(keyword_type, "")
74
+ marc_field = KEYWORD_MARC_MAP.get(str(keyword_type), "")
75
+ lang = keyword_dict.get("language", "")
76
+
77
+ ind1, ind2 = _find_indicators(
78
+ entity_type=entity_type,
79
+ entity=original_keyword,
80
+ is_linked=False
81
+ )
82
+ keyword_source = _get_keyword_source(
83
+ linked_doc=None,
84
+ is_linked=False,
85
+ entity_type=entity_type
86
+ )
87
+ new_keyword_dict = {
88
+ "dates": "",
89
+ "indicator1": ind1,
90
+ "indicator2": ind2,
91
+ "is_linked": False,
92
+ "keyword_source": keyword_source,
93
+ "lang": lang,
94
+ "location": "",
95
+ "marc_field": marc_field,
96
+ "numeration": "",
97
+ "organisation_sub_unit": "",
98
+ "original_keyword": original_keyword,
99
+ "persons_title": "",
100
+ "url": "",
101
+ "url_source": ""
102
+ }
103
+ new_keyword_dict.update(keyword_dict)
104
+ formatted_keywords["keywords"].append(new_keyword_dict)
105
+
106
+ return formatted_keywords
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rara-tools
3
- Version: 0.6.13
3
+ Version: 0.6.14
4
4
  Summary: Tools to support Kata's work.
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Classifier: Programming Language :: Python :: 3.10
@@ -8,6 +8,7 @@ rara_tools/decorators.py
8
8
  rara_tools/digar_schema_converter.py
9
9
  rara_tools/elastic.py
10
10
  rara_tools/exceptions.py
11
+ rara_tools/formatters.py
11
12
  rara_tools/s3.py
12
13
  rara_tools/task_reporter.py
13
14
  rara_tools/utils.py
@@ -48,6 +49,7 @@ tests/test_digar_schema_converter.py
48
49
  tests/test_elastic.py
49
50
  tests/test_elastic_vector_and_search_operations.py
50
51
  tests/test_entity_normalizers.py
52
+ tests/test_formatters.py
51
53
  tests/test_marc_parsers.py
52
54
  tests/test_normalization.py
53
55
  tests/test_s3_exceptions.py
@@ -0,0 +1,15 @@
1
+ import pytest
2
+ import os
3
+ from pprint import pprint
4
+ from rara_tools.formatters import format_keywords
5
+ from tests.test_utils import read_json_file
6
+
7
+ ROOT_DIR = os.path.join("tests", "test_data", "formatter")
8
+ INPUT_KEYWORDS_FILE_PATH = os.path.join(ROOT_DIR, "keywords.json")
9
+
10
+ INPUT_KEYWORDS = read_json_file(INPUT_KEYWORDS_FILE_PATH)
11
+
12
+ def test_formatting_keywords_for_core():
13
+ formatted_keywords = format_keywords(INPUT_KEYWORDS)
14
+ assert formatted_keywords
15
+ assert isinstance(formatted_keywords, dict)
rara_tools-0.6.13/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.6.13
@@ -1,14 +0,0 @@
1
- COMPONENT_KEY = "subject_indexer"
2
-
3
-
4
- class Tasks:
5
- SINGLE = "run_subject_indexer_process"
6
- PIPELINE = "run_subject_indexer_with_core_logic"
7
-
8
-
9
- class Queue:
10
- MAIN = "subject-indexer"
11
-
12
-
13
- class StatusKeys:
14
- EXTRACT_KEYWORDS = "extract_keywords"
File without changes
File without changes
File without changes
File without changes