Skip to content

Commit

Permalink
agents: fix GND person or organisation
Browse files Browse the repository at this point in the history
* Only uses records with 075 $b p/b/f for creating of GND records.

Co-Authored-by: Peter Weber <peter.weber@rero.ch>
  • Loading branch information
rerowep committed Feb 9, 2023
1 parent 60e982d commit c69e22d
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 15 deletions.
49 changes: 41 additions & 8 deletions rero_mef/marctojson/do_gnd_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
'u': 'Unknown'
}

RECORD_TYPES = {
'p': 'bf:Person',
'b': 'bf:Organisation',
'f': 'bf:Organisation',
'g': 'bf:Place',
's': 'bf:Concept',
'u': 'bf:Title'
}


class Transformation(object):
"""Transformation MARC21 to JSON for GND autority person."""
Expand All @@ -45,17 +54,41 @@ def __init__(self, marc, logger=None, verbose=False, transform=True):
if transform:
self._transform()

def get_type(self):
"""Get type of record.
Entitäten der GND (Satztypen) 075 $b TYPE $2 gndgen
- b Körperschaft
- f Konferenz
- g Geografikum
- n Person (nicht individualisiert)
- p Person (individualisiert)
- s Sachbegriff
- u Werk
"""
for field_075 in self.marc.get_fields('075') or []:
if field_075['2'] == 'gndgen':
return RECORD_TYPES.get(field_075['b'])

def _transform(self):
"""Call the transformation functions."""
if self.marc.get_fields('100') or \
self.marc.get_fields('110') or \
self.marc.get_fields('111'):
for func in dir(self):
if func.startswith('trans'):
func = getattr(self, func)
func()
record_type = self.get_type()
if record_type in ['bf:Person', 'bf:Organisation']:
if self.marc.get_fields('100') or \
self.marc.get_fields('110') or \
self.marc.get_fields('111'):
for func in dir(self):
if func.startswith('trans'):
func = getattr(self, func)
func()
else:
msg = 'No 100 or 110 or 111'
if self.logger and self.verbose:
self.logger.warning(f'NO TRANSFORMATION: {msg}')
self.json_dict = {'NO TRANSFORMATION': msg}
self.trans_gnd_pid()
else:
msg = 'No 100 or 110 or 111'
msg = f'Not a person or organisation: {record_type}'
if self.logger and self.verbose:
self.logger.warning(f'NO TRANSFORMATION: {msg}')
self.json_dict = {'NO TRANSFORMATION': msg}
Expand Down
9 changes: 3 additions & 6 deletions tests/unit/agents/examples/xml_minimal_record.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@

<record>
<leader>00589nx a2200193 45 </leader>
<datafield ind1=" " ind2=" " tag="710">
<subfield code="a">Paul</subfield>
<subfield code="b">VI</subfield>
<subfield code="c">pape</subfield>
<subfield code="d">1897-1978</subfield>
<datafield tag="043" ind1=" " ind2=" ">
<subfield code="c">XA-DE</subfield>
</datafield>
</record>
</record>
50 changes: 49 additions & 1 deletion tests/unit/agents/test_agent_gnd_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,55 @@

"""Test GND auth person."""

from agents_helpers import trans_prep
import os

from agents_helpers import build_xml_record_file, trans_prep
from pymarc import marcxml

from rero_mef.marctojson.do_gnd_agent import Transformation


def test_no_person_or_organisation():
"""Test no person or organisation."""
xml_part_to_add = """
<datafield tag="075" ind1=" " ind2=" ">
<subfield code="b">s</subfield>
<subfield code="2">gndgen</subfield>
</datafield>
"""
build_xml_record_file(xml_part_to_add)
current_dir = os.path.dirname(__file__)
file_name = os.path.join(
current_dir, 'examples/xml_minimal_record.xml')
records = marcxml.parse_xml_to_array(
file_name, strict=False, normalize_form=None)
data = Transformation(marc=records[0], logger=None,
verbose=False, transform=True)
assert data.json_dict == {
'NO TRANSFORMATION': 'Not a person or organisation: bf:Concept'}


def test_no_100_110_111():
"""Test np 100, 110, 111."""
xml_part_to_add = """
<datafield tag="075" ind1=" " ind2=" ">
<subfield code="b">p</subfield>
<subfield code="2">gndgen</subfield>
</datafield>
<datafield tag="075" ind1=" " ind2=" ">
<subfield code="b">piz</subfield>
<subfield code="2">gndspec</subfield>
</datafield>
"""
build_xml_record_file(xml_part_to_add)
current_dir = os.path.dirname(__file__)
file_name = os.path.join(
current_dir, 'examples/xml_minimal_record.xml')
records = marcxml.parse_xml_to_array(
file_name, strict=False, normalize_form=None)
data = Transformation(marc=records[0], logger=None,
verbose=False, transform=True)
assert data.json_dict == {'NO TRANSFORMATION': 'No 100 or 110 or 111'}


def test_gnd_deleted():
Expand Down

0 comments on commit c69e22d

Please # to comment.