From 2d2f83e9e02cfbe76be45cd09003d4585349d1de Mon Sep 17 00:00:00 2001 From: jonavellecuerdo Date: Thu, 25 Jul 2024 17:36:06 -0400 Subject: [PATCH] notes --- tests/sources/xml/test_marc.py | 89 +++++++++++++++ transmogrifier/sources/xml/marc.py | 168 +++++++++++++++-------------- 2 files changed, 178 insertions(+), 79 deletions(-) diff --git a/tests/sources/xml/test_marc.py b/tests/sources/xml/test_marc.py index cef9d43..cc5686c 100644 --- a/tests/sources/xml/test_marc.py +++ b/tests/sources/xml/test_marc.py @@ -1461,6 +1461,95 @@ def test_marc_get_locations_transforms_correctly_if_fields_blank(): assert Marc.get_locations(source_record) is None +def test_get_notes_success(): + source_record = create_marc_source_record_stub( + datafield_insert=( + """ + + arranged by the Arts Council of Great Britain. + + + Opera in 5 acts. + + + Thesis (D.SC.)--University of London. + + + Includes bibliographical references and index. + + + Producer, Toygun Kirali. + + + Lamoureux Concerts Orchestra ; Igor Markevitch, conductor. + + + Suspended publication 1944-52. + + + Canada. + + + Electronic reproduction. + New York : + Springer, + 2008. + + + Originally published + New York : Garland, 1987. + + + Hard copy version record. + + + Rare Book copy: Advance copy notice inserted. + + """ + ) + ) + assert Marc.get_notes(source_record) == [ + timdex.Note( + value=["arranged by the Arts Council of Great Britain"], + kind="Title Statement of Responsibility", + ), + timdex.Note(value=["Opera in 5 acts"], kind="General Note"), + timdex.Note( + value=["Thesis (D.SC.)--University of London"], kind="Dissertation Note" + ), + timdex.Note( + value=["Includes bibliographical references and index"], + kind="Bibliography Note", + ), + timdex.Note( + value=["Producer, Toygun Kirali"], kind="Creation/Production Credits Note" + ), + timdex.Note( + value=["Lamoureux Concerts Orchestra ; Igor Markevitch, conductor"], + kind="Participant or Performer Note", + ), + timdex.Note( + value=["Suspended publication 1944-52"], kind="Numbering Peculiarities Note" + ), + timdex.Note(value=["Canada"], kind="Geographic Coverage Note"), + timdex.Note( + value=["Electronic reproduction. New York : Springer, 2008"], + kind="Reproduction Note", + ), + timdex.Note( + value=["Originally published New York : Garland, 1987"], + kind="Original Version Note", + ), + timdex.Note( + value=["Hard copy version record"], + kind="Source of Description Note", + ), + timdex.Note( + value=["Rare Book copy: Advance copy notice inserted"], kind="Local Note" + ), + ] + + def test_marc_record_missing_leader_skips_record(caplog): marc_xml_records = Marc.parse_source_file( "tests/fixtures/marc/marc_record_missing_leader.xml" diff --git a/transmogrifier/sources/xml/marc.py b/transmogrifier/sources/xml/marc.py index 70696f1..d6cd72f 100644 --- a/transmogrifier/sources/xml/marc.py +++ b/transmogrifier/sources/xml/marc.py @@ -90,85 +90,7 @@ def get_optional_fields(self, source_record: Tag) -> dict | None: fields["locations"] = self.get_locations(source_record) # notes - note_marc_fields = [ - { - "tag": "245", - "subfields": "c", - "kind": "Title Statement of Responsibility", - }, - { - "tag": "500", - "subfields": "a", - "kind": "General Note", - }, - { - "tag": "502", - "subfields": "abcdg", - "kind": "Dissertation Note", - }, - { - "tag": "504", - "subfields": "a", - "kind": "Bibliography Note", - }, - { - "tag": "508", - "subfields": "a", - "kind": "Creation/Production Credits Note", - }, - { - "tag": "511", - "subfields": "a", - "kind": "Participant or Performer Note", - }, - { - "tag": "515", - "subfields": "a", - "kind": "Numbering Peculiarities Note", - }, - { - "tag": "522", - "subfields": "a", - "kind": "Geographic Coverage Note", - }, - { - "tag": "533", - "subfields": "abcdefmn", - "kind": "Reproduction Note", - }, - { - "tag": "534", - "subfields": "abcefklmnoptxz", - "kind": "Original Version Note", - }, - { - "tag": "588", - "subfields": "a", - "kind": "Source of Description Note", - }, - { - "tag": "590", - "subfields": "a", - "kind": "Local Note", - }, - ] - for note_marc_field in note_marc_fields: - for datafield in source_record.find_all( - "datafield", tag=note_marc_field["tag"] - ): - if note_value := ( - self.create_subfield_value_string_from_datafield( - datafield, - note_marc_field["subfields"], - " ", - ) - ): - fields.setdefault("notes", []).append( - timdex.Note( - value=[note_value.rstrip(" .")], - kind=note_marc_field["kind"], - ) - ) + fields["notes"] = self.get_notes(source_record) # numbering @@ -944,6 +866,94 @@ def get_locations(cls, source_record: Tag) -> list[timdex.Location] | None: ) return locations or None + @classmethod + def get_notes(cls, source_record: Tag) -> list[timdex.Note] | None: + notes = [] + note_marc_fields = [ + { + "tag": "245", + "subfields": "c", + "kind": "Title Statement of Responsibility", + }, + { + "tag": "500", + "subfields": "a", + "kind": "General Note", + }, + { + "tag": "502", + "subfields": "abcdg", + "kind": "Dissertation Note", + }, + { + "tag": "504", + "subfields": "a", + "kind": "Bibliography Note", + }, + { + "tag": "508", + "subfields": "a", + "kind": "Creation/Production Credits Note", + }, + { + "tag": "511", + "subfields": "a", + "kind": "Participant or Performer Note", + }, + { + "tag": "515", + "subfields": "a", + "kind": "Numbering Peculiarities Note", + }, + { + "tag": "522", + "subfields": "a", + "kind": "Geographic Coverage Note", + }, + { + "tag": "533", + "subfields": "abcdefmn", + "kind": "Reproduction Note", + }, + { + "tag": "534", + "subfields": "abcefklmnoptxz", + "kind": "Original Version Note", + }, + { + "tag": "588", + "subfields": "a", + "kind": "Source of Description Note", + }, + { + "tag": "590", + "subfields": "a", + "kind": "Local Note", + }, + ] + for note_marc_field in note_marc_fields: + notes.extend( + [ + timdex.Note( + value=[note_value.rstrip(" .")], + kind=note_marc_field["kind"], + ) + for datafield in source_record.find_all( + "datafield", tag=note_marc_field["tag"] + ) + if ( + note_value := ( + cls.create_subfield_value_string_from_datafield( + datafield, + note_marc_field["subfields"], + " ", + ) + ) + ) + ] + ) + return notes or None + @staticmethod def get_main_titles(xml: Tag) -> list[str]: """