Skip to content

Commit

Permalink
Additional updates based on discussion in PR #30
Browse files Browse the repository at this point in the history
* Remove originalsloc and physloc from fixtures
* Add bibliography data scenario to attribute and subfield variations fixture
* Remove holdings parsing code pending further discussion
* Update notes parsing code to remove duplicate code
* Update unit test values to account for code changes
  • Loading branch information
ehanson8 committed Sep 29, 2022
1 parent c27e8ae commit b8645e2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 85 deletions.
8 changes: 0 additions & 8 deletions tests/fixtures/ead/ead_record_all_fields.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
<origination>
<persname authfilenumber="nr99025435" source="viaf">Name 5</persname>
</origination>
<physloc>Yet more originals are here</physloc>
</did>
<arrangement>
<head>Arrangement</head>
Expand Down Expand Up @@ -92,13 +91,6 @@
</genreform>
<geogname>Boston, MA</geogname>
</controlaccess>
<originalsloc>
<head>Originals Location</head>
<p>Some originals are here</p>
</originalsloc>
<originalsloc>
<p>Some originals are there</p>
</originalsloc>
<prefercite>
<head>Preferred Citation</head>
<p>Charles J. Connick Stained Glass Foundation Collection, VC-0002, box X. Massachusetts Institute of Technology, Department of Distinctive Collections, Cambridge, Massachusetts.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@
</part>
</persname>
</origination>
<physloc>
<emph>Data enclosed in subelement</emph>
</physloc>
</did>
<arrangement>
<head></head>
Expand All @@ -140,6 +137,14 @@
<bibliography>
<head>Head tag but no other data</head>
</bibliography>
<bibliography>
<head></head>
<bibref>
<title>
<part>Data with blank head element</part>
</title>
</bibref>
</bibliography>
<bibliography>
<bibref>
<title>
Expand Down Expand Up @@ -174,16 +179,6 @@
<emph>Data enclosed in subelement</emph>
</geogname>
</controlaccess>
<originalsloc>
<head></head>
<p></p>
</originalsloc>
<originalsloc>
<head></head>
</originalsloc>
<originalsloc>
<head>Head tag but no other data</head>
</originalsloc>
<prefercite>
<head></head>
<p></p>
Expand Down
2 changes: 0 additions & 2 deletions tests/fixtures/ead/ead_record_blank_optional_fields.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<origination>
<persname></persname>
</origination>
<physloc></physloc>
</did>
<acqinfo></acqinfo>
<appraisal></appraisal>
Expand All @@ -29,7 +28,6 @@
<geogname></geogname>
</controlaccess>
<custodhist></custodhist>
<originalsloc></originalsloc>
<prefercite></prefercite>
<processinfo></processinfo>
<scopecontent></scopecontent>
Expand Down
45 changes: 19 additions & 26 deletions tests/test_ead.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,17 @@ def test_ead_record_all_fields_transform_correctly():
range=timdex.Date_Range(gte="1905", lte="2012"),
)
],
holdings=[
timdex.Holding(
note="Some originals are here",
),
timdex.Holding(
note="Some originals are there",
),
timdex.Holding(location="Yet more originals are here"),
],
identifiers=[timdex.Identifier(value="1234", kind="Collection Identifier")],
languages=["English", "French"],
locations=[timdex.Location(value="Boston, MA")],
notes=[
timdex.Note(
value=[
"Affiches americaines San Domingo: Imprimerie royale du Cap, 1782. "
"Nos. 30, 35.",
],
kind="Bibliography",
),
timdex.Note(
value=[
"Charles J. Connick (1875-1945) was an American stained glass artist "
Expand Down Expand Up @@ -102,15 +100,6 @@ def test_ead_record_all_fields_transform_correctly():
],
kind="Scope and Contents",
),
timdex.Note(
value=[
"Affiches americaines",
"San Domingo:",
"Imprimerie",
"royale du Cap, 1782. Nos. 30, 35.",
],
kind="Bibliography",
),
],
)

Expand Down Expand Up @@ -321,21 +310,25 @@ def test_ead_record_with_attribute_and_subfield_variations_transforms_correctly(
),
timdex.Date(note="approximate", value="1905"),
],
holdings=[
timdex.Holding(location="Data enclosed in subelement"),
],
identifiers=[
timdex.Identifier(
value="Data enclosed in subelement", kind="Collection Identifier"
)
],
locations=[timdex.Location(value="Data enclosed in subelement")],
notes=[
timdex.Note(value=["Data with blank head tag"]),
timdex.Note(value=["Data with no head tag"]),
timdex.Note(value=["Data with blank head tag"]),
timdex.Note(value=["Data with no head tag"]),
timdex.Note(value=["Data with no head element"]),
timdex.Note(value=["Data with blank head element"], kind="Bibliography"),
timdex.Note(value=["Data with no head element"], kind="Bibliography"),
timdex.Note(
value=["Data with blank head tag"], kind="Biography or History"
),
timdex.Note(value=["Data with no head tag"], kind="Biography or History"),
timdex.Note(
value=["Data with blank head tag"], kind="Scope and Contents Note"
),
timdex.Note(
value=["Data with no head tag"], kind="Scope and Contents Note"
),
],
)

Expand Down
55 changes: 19 additions & 36 deletions transmogrifier/sources/ead.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,7 @@ def get_optional_fields(self, xml: Tag) -> Optional[dict]:
# funding_information field not used in EAD. titlestmt > sponsor was considered
# but did not fit the usage of this field in other sources.

# holdings
for holding_element in collection_description.find_all(
"originalsloc", recursive=False
):
if holding_value := self.create_string_from_mixed_value(
holding_element, " ", ["head"]
):
fields.setdefault("holdings", []).append(
timdex.Holding(note=holding_value)
)
for holding_element in collection_description_did.find_all(
"physloc", recursive=False
):
if holding_value := self.create_string_from_mixed_value(
holding_element,
" ",
):
fields.setdefault("holdings", []).append(
timdex.Holding(location=holding_value)
)
# holdings omitted pending discussion on how to map originalsloc and physloc

# identifiers
for id_element in collection_description_did.find_all(
Expand Down Expand Up @@ -184,31 +165,33 @@ def get_optional_fields(self, xml: Tag) -> Optional[dict]:
# notes
for note_element in collection_description.find_all(
[
"bibliography",
"bioghist",
"scopecontent",
],
recursive=False,
):
if note_element.name == "bibliography":
subelement_tag = "bibref"
else:
subelement_tag = "p"
note_value = []
for p_element in note_element.find_all("p", recursive=False):
if p_value := self.create_string_from_mixed_value(
p_element,
for subelement in note_element.find_all(subelement_tag, recursive=False):
if subelement_value := self.create_string_from_mixed_value(
subelement,
" ",
):
note_value.append(p_value)
note_value.append(subelement_value)
if note_value:
note = timdex.Note(value=note_value)
note_head_element = note_element.find("head")
if note_head_element and note_head_element.string:
note.kind = note_head_element.string
fields.setdefault("notes", []).append(note)

for note_element in collection_description.find_all("bibliography"):
if note_value := self.create_list_from_mixed_value(note_element, ["head"]):
note = timdex.Note(value=note_value)
note_head_element = note_element.find("head")
if note_head_element and note_head_element.string:
note.kind = note_head_element.string
note_head_element = note_element.find("head", string=True)
note = timdex.Note(
value=note_value,
kind=(
note_head_element.string
if note_head_element
else self.crosswalk_type_value(note_element.name)
),
)
fields.setdefault("notes", []).append(note)

return fields
Expand Down

0 comments on commit b8645e2

Please sign in to comment.