Skip to content

Commit

Permalink
documents: simplify subjects structure
Browse files Browse the repository at this point in the history
* Uses entity for subjects and imported subjects.
* Uses entity for genreForm and imported genreForm.
* Uses entities as subject subdivisions.
* Removes non working entity links such as timestamps, places, etc.
* Removes entity links for imported version of subjects and genreForm.
* Removes subject factory.

Signed-off-by: Johnny Mariéthoz <[email protected]>
  • Loading branch information
jma committed Mar 9, 2023
1 parent 5d2eaad commit aac5d59
Show file tree
Hide file tree
Showing 41 changed files with 18,019 additions and 9,533 deletions.
18,372 changes: 12,668 additions & 5,704 deletions data/documents_big.json

Large diffs are not rendered by default.

6,391 changes: 4,387 additions & 2,004 deletions data/documents_small.json

Large diffs are not rendered by default.

26 changes: 0 additions & 26 deletions rero_ils/modules/documents/commons/__init__.py

This file was deleted.

259 changes: 0 additions & 259 deletions rero_ils/modules/documents/commons/subjects.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
do_scale_and_cartographic, do_sequence_numbering, \
do_specific_document_relation, do_summary, do_table_of_contents, \
do_temporal_coverage, do_title, do_type, \
do_usage_and_access_policy_from_field_506_540
do_usage_and_access_policy_from_field_506_540, perform_subdivisions

marc21 = ReroIlsMarc21Overdo()

Expand Down Expand Up @@ -525,19 +525,6 @@ def marc21_to_subjects_6XX(self, key, value):
subjects : for 6xx with $2 rero
subjects_imported : for 6xx having indicator 2 '0' or '2'
"""

def perform_subdivisions(field):
"""Perform subject subdivisions from MARC field."""
subdivisions = {
'v': 'genreForm_subdivisions',
'x': 'topic_subdivisions',
'y': 'temporal_subdivisions',
'z': 'place_subdivisions'
}
for code, subdivision in subdivisions.items():
for subfield_value in utils.force_list(value.get(code, [])):
field.setdefault(subdivision, []).append(subfield_value)

type_per_tag = {
'600': DocumentSubjectType.PERSON,
'610': DocumentSubjectType.ORGANISATION,
Expand All @@ -551,19 +538,6 @@ def perform_subdivisions(field):
'655': DocumentSubjectType.TOPIC
}

field_data_per_tag = {
'600': 'preferred_name',
'610': 'preferred_name',
'611': 'preferred_name',
'600t': 'title',
'610t': 'title',
'611t': 'title',
'630': 'title',
'650': 'term',
'651': 'preferred_name',
'655': 'term'
}

subfield_code_per_tag = {
'600': 'abcd',
'610': 'ab',
Expand Down Expand Up @@ -617,7 +591,7 @@ def perform_subdivisions(field):
if tag_key == '655':
# remove the square brackets
string_build = re.sub(r'^\[(.*)\]$', r'\1', string_build)
subject[field_data_per_tag[tag_key]] = string_build
subject['authorized_access_point'] = string_build

if tag_key in ['610', '611']:
subject['conference'] = conference_per_tag[tag_key]
Expand Down Expand Up @@ -650,24 +624,23 @@ def perform_subdivisions(field):
identifier = build_identifier(value)
if identifier:
subject['identifiedBy'] = identifier
perform_subdivisions(subject)
if field_key != 'genreForm':
perform_subdivisions(subject, value)

if subject.get('$ref') or subject.get(field_data_per_tag[tag_key]):
self.setdefault(field_key, []).append(subject)
if subject.get('$ref') or subject.get('authorized_access_point'):
self.setdefault(field_key, []).append(dict(entity=subject))
elif indicator_2 in ['0', '2']:
term_string = build_string_from_subfields(
value, 'abcdefghijklmnopqrstuw', ' - ')
if term_string:
data = {
'type': type_per_tag[tag_key],
'source': source_per_indicator_2[indicator_2],
field_data_per_tag[tag_key]: term_string.rstrip('.')
'authorized_access_point': term_string.rstrip('.')
}
perform_subdivisions(data)
if tag_key in ['610', '611']:
data['conference'] = conference_per_tag[tag_key]
perform_subdivisions(data, value)
if data:
self.setdefault(config_field_key, []).append(data)
self.setdefault(config_field_key, []).append(dict(entity=data))


@marc21.over('sequence_numbering', '^362..')
Expand Down
Loading

0 comments on commit aac5d59

Please sign in to comment.