Skip to content

Commit

Permalink
notes
Browse files Browse the repository at this point in the history
  • Loading branch information
jonavellecuerdo committed Jul 25, 2024
1 parent f6e8748 commit 2d2f83e
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 79 deletions.
89 changes: 89 additions & 0 deletions tests/sources/xml/test_marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=(
"""
<datafield tag="245" ind1="0" ind2="0">
<subfield code="c">arranged by the Arts Council of Great Britain.</subfield>
</datafield>
<datafield tag="500" ind1=" " ind2=" ">
<subfield code="a">Opera in 5 acts.</subfield>
</datafield>
<datafield tag="502" ind1=" " ind2=" ">
<subfield code="a">Thesis (D.SC.)--University of London.</subfield>
</datafield>
<datafield tag="504" ind1=" " ind2=" ">
<subfield code="a">Includes bibliographical references and index.</subfield>
</datafield>
<datafield tag="508" ind1=" " ind2=" ">
<subfield code="a">Producer, Toygun Kirali.</subfield>
</datafield>
<datafield tag="511" ind1="0" ind2=" ">
<subfield code="a">Lamoureux Concerts Orchestra ; Igor Markevitch, conductor.</subfield>
</datafield>
<datafield tag="515" ind1=" " ind2=" ">
<subfield code="a">Suspended publication 1944-52.</subfield>
</datafield>
<datafield tag="522" ind1=" " ind2=" ">
<subfield code="a">Canada.</subfield>
</datafield>
<datafield tag="533" ind1=" " ind2=" ">
<subfield code="a">Electronic reproduction.</subfield>
<subfield code="b">New York :</subfield>
<subfield code="c">Springer,</subfield>
<subfield code="d">2008.</subfield>
</datafield>
<datafield tag="534" ind1=" " ind2=" ">
<subfield code="p">Originally published</subfield>
<subfield code="c">New York : Garland, 1987.</subfield>
</datafield>
<datafield tag="588" ind1="0" ind2=" ">
<subfield code="a">Hard copy version record.</subfield>
</datafield>
<datafield tag="590" ind1=" " ind2=" ">
<subfield code="a">Rare Book copy: Advance copy notice inserted.</subfield>
</datafield>
"""
)
)
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"
Expand Down
168 changes: 89 additions & 79 deletions transmogrifier/sources/xml/marc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]:
"""
Expand Down

0 comments on commit 2d2f83e

Please sign in to comment.