Skip to content

Commit

Permalink
Start adding support for reprint
Browse files Browse the repository at this point in the history
  • Loading branch information
Xennis committed Apr 24, 2024
1 parent 0f77489 commit a8fd46e
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 1 deletion.
21 changes: 21 additions & 0 deletions epidoc/body.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,24 @@ def foreign_languages(body: Tag) -> dict[str, int]:
continue
result[lang] = result.get(lang, 0) + 1
return result


class _Head:

@staticmethod
def reprint_from(body: Tag) -> list[str]:
result: list[str] = []
for elem in body.findAll("ref", type="reprint-from"):
n = _normalize(elem.attrs.get("n"))
if n:
result.append(n)
return result

@staticmethod
def reprint_in(body: Tag) -> list[str]:
result: list[str] = []
for elem in body.findAll("ref", type="reprint-in"):
n = _normalize(elem.attrs.get("n"))
if n:
result.append(n)
return result
26 changes: 25 additions & 1 deletion tests/test_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from bs4 import BeautifulSoup

from epidoc.body import _Edition
from epidoc.body import _Edition, _Head

TESTDATA_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "testdata")

Expand All @@ -30,3 +30,27 @@ def test_all(self):
self.assertEqual(want_language, actual_language, msg="language")
actual_foreign_languages = _Edition.foreign_languages(elem)
self.assertEqual(want_foreign_languages, actual_foreign_languages, msg="foreign languages")


class HeadTest(unittest.TestCase):
def test_all(self):
tests = [
(
"3.xml",
["p.oxy;10;1271", "chla;4;266"],
[],
),
(
"4.xml",
[],
["c.ep.lat;;213"],
),
]
for filename, want_reprint_from, want_reprint_in in tests:
with self.subTest(filename):
with open(os.path.join(TESTDATA_DIR, "body", filename)) as f:
elem = BeautifulSoup(f.read(), features="lxml")
actual_reprint_from = _Head.reprint_from(elem)
self.assertEqual(want_reprint_from, actual_reprint_from, msg="reprint from")
actual_reprint_in = _Head.reprint_in(elem)
self.assertEqual(want_reprint_in, actual_reprint_in, msg="reprint in")
39 changes: 39 additions & 0 deletions tests/testdata/body/3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!-- DDB_EpiDoc_XML/c.ep.lat/c.ep.lat.213.xml
<availability>
<p>© Duke Databank of Documentary Papyri. This work is licensed under a <ref type="license" target="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 License</ref>.</p>
</availability>
-->
<body>
<head n="21785" xml:lang="en">
<date>AD 246</date>
<placeName>Oxyrhynchus</placeName>
<ref n="p.oxy;10;1271" type="reprint-from">P.Oxy. 10 1271; CPL 179</ref>
<ref n="chla;4;266" type="reprint-from">ChLA 4 266</ref>
</head>
<div xml:lang="la" type="edition" xml:space="preserve"><ab>
<lb n="1"/><foreign xml:lang="grc">Οὐαλερίῳ Φίρμῳ ἐπάρχῳ Αἰγύπτου

<lb n="2"/>παρὰ Αὐρηλίας <app type="editorial"><lem resp="BL cf. 8.243">Μαρκιανῆς</lem><rdg>Μαικιανῆσ</rdg></app> <expan>Σιδήτ<ex>ιδος</ex></expan>

<lb n="3"/>βούλομαι κύριε ἐκπλεῦσαι διὰ Φάρου.

<lb n="4"/>ἀξιῶ γράψαι σε τῷ ἐπιτρόπῳ τῆς Φά

<lb n="5" break="no"/>ρου ἀπολῦσαί με κατὰ τὸ ἔθος

<lb n="6"/><app type="editorial"><lem resp="BL cf. 8.243"><num value="3">γ</num> <expan><ex cert="low">ἔτους</ex></expan> <expan>ἐ<ex>παγομένων</ex></expan></lem><rdg><unclear>Π</unclear><supplied reason="lost">α</supplied><unclear>χὼν</unclear></rdg></app> <num value="1">α</num> διευτύχει </foreign>

<lb n="7"/><handShift new="m2"/>Valerius Firmus

<lb n="8"/>Asclepiade salu<unclear>t</unclear>em

<lb n="9"/>dimitti <choice><reg>iussi</reg><orig>iusi</orig></choice> de <unclear>P</unclear><supplied reason="lost">haro</supplied>

<lb n="10"/><choice><reg>commendo</reg><orig>comendo</orig></choice> <unclear>t</unclear><supplied reason="lost">ibi</supplied>

<lb n="11"/><handShift new="m3"/>vale iu<supplied reason="lost">ssi</supplied>

<lb n="12"/>datum <num>XVII</num> <expan><unclear>K</unclear><supplied reason="lost">al<ex>endas</ex></supplied></expan><supplied reason="lost"> <app type="editorial"><lem resp="BL cf. 8.243"><expan>Oct<ex>obres</ex></expan></lem><rdg><expan>Iun<ex>ias</ex></expan></rdg></app></supplied>

<lb n="13"/>Presenti <unclear>A</unclear><supplied reason="lost">lbino <expan>co<ex>n</ex>s<ex>ulibus</ex></expan></supplied> </ab></div>
</body>
13 changes: 13 additions & 0 deletions tests/testdata/body/4.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- DDB_EpiDoc_XML/p.oxy/p.oxy.10/p.oxy.10.1271.xml
<availability>
<p>© Duke Databank of Documentary Papyri. This work is licensed under a <ref type="license" target="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 License</ref>.</p>
</availability>
-->
<body>
<head xml:lang="en">
<date>AD 159</date>
<placeName>Oxyrhynchus</placeName>
<ref n="c.ep.lat;;213" type="reprint-in">C.Epist.Lat. 213</ref>
</head>
<div xml:lang="grc" type="edition" xml:space="preserve"><ab/></div>
</body>

0 comments on commit a8fd46e

Please sign in to comment.