Skip to content

Commit

Permalink
⚡ Added support for distinct variation unit IDs defined by combinatio…
Browse files Browse the repository at this point in the history
…n of n, from, and to attributes
  • Loading branch information
jjmccollum committed Jan 8, 2025
1 parent c0193ec commit f468e5c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
32 changes: 16 additions & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "teiphy"
version = "0.1.15"
version = "0.1.16"
description = "Converts TEI XML collations to NEXUS and other formats"
authors = ["Joey McCollum and Robert Turnbull"]
license = "MIT"
Expand Down
4 changes: 3 additions & 1 deletion teiphy/variation_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ def __init__(self, xml: et.Element, verbose: bool = False):
xml: An lxml.etree.Element representing an app element.
verbose: An optional boolean flag indicating whether or not to print status updates.
"""
# Use its xml:id if it has one; otherwise, use its n attribute if it has one:
# Use its xml:id if it has one; otherwise, use its n, from, and to attributes if it has them:
self.id = ""
if xml.get("{%s}id" % xml_ns) is not None:
self.id = xml.get("{%s}id" % xml_ns)
elif xml.get("n") is not None:
self.id = xml.get("n")
if xml.get("from") is not None and xml.get("to") is not None:
self.id += "_" + xml.get("from") + "_" + xml.get("to")
# Initialize its list of readings:
self.readings = []
# Initialize its dictionaries of intrinsic and transcriptional relations:
Expand Down
21 changes: 21 additions & 0 deletions tests/test_variation_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,27 @@ def test_init_n_id(self):
vu = VariationUnit(xml)
self.assertEqual(vu.id, "39")

def test_init_n_from_to_id(self):
xml = et.fromstring(
"""
<app n="Jude1" type="main" from="4" to="8">
<rdg
wit="P72 01 02 03 020 044 056 0142 1 3 5 18 33 35 43 61 62 69 81 88 93 94 102 103 105 133 141 149 172 177 189 201 203 204 218 226 241 242 254 263 296 307 309 312 314 321 322 323 326 327 328 337 363 367 378 383 384 386 394 398 425 429 431 432 436 442 444 450 453 454 456 457 458 460 462 465 466 467 479 483 491 496 506 522 547 603 604 606 608 614 618 621 622 623 625 629 630 631 632 633 634 635 636 639 641 656 664 665 676 720 757 801 823 824 832 876 901 910 913 915 917 918 928 945 959 986 997 999 1040 1058 1066 1069 1070 1072 1075 1094 1100 1101 1102 1104 1105 1106 1107 1162 1241 1242 1243 1244 1247 1248 1249 1250 1251 1270 1292 1297 1311 1315 1352 1359 1367 1384 1390 1398 1400 1404 1409 1425 1448 1482 1490 1503 1505 1508 1509 1521 1523 1524 1548 1563 1595 1597 1598 1599 1610 1611 1617 1618 1619 1628 1636 1637 1642 1649 1652 1656 1673 1678 1704 1717 1718 1720 1723 1725 1726 1727 1728 1731 1732 1733 1735 1737 1738 1739 1740 1741 1745 1746 1747 1748 1749 1750 1752 1754 1761 1762 1763 1765 1766 1767 1768 1799 1827 1828 1830 1831 1832 1834 1836 1837 1838 1840 1842 1843 1844 1845 1846 1850 1852 1853 1854 1855 1856 1858 1864 1865 1869 1874 1875 1876 1877 1880 1882 1885 1891 1892 1894 1896 1897 1902 1903 2080 2131 2138 2143 2147 2180 2186 2197 2200 2218 2221 2242 2243 2255 2261 2289 2298 2318 2344 2352 2378 2401 2404 2412 2431 2466 2473 2492 2494 2495 2501 2523 2527 2544 2554 2558 2587 2626 2652 2653 2691 2696 2704 2723 2774 2776 2777 2805 2815 2816 2818 L147 L427 L585 L593 L596 L603 L884 L1196 L1281 L1440 L2087 NA28 RP 206S 90a 90b L1196_2 L1281_2 L585_2"
varSeq="1" n="a" type="-">ιησου χριστου δουλος</rdg>
<rdg
wit="018 025 049 6 38 42 51 57 76 82 97 101 104 110 131 142 175 181 205 209 216 221 223 234 250 252 302 308 319 325 330 385 390 393 404 421 424 440 451 452 459 468 469 489 517 582 592 601 605 607 615 616 617 619 620 627 628 637 638 642 680 699 808 912 914 919 920 921 922 927 935 941 996 1003 1022 1099 1103 1115 1127 1149 1161 1175 1240 1245 1277 1319 1354 1360 1405 1424 1495 1501 1573 1594 1609 1622 1626 1643 1646 1661 1668 1719 1721 1722 1729 1730 1734 1736 1742 1743 1744 1753 1757 1760 1769 1780 1795 1829 1835 1839 1841 1847 1849 1851 1857 1859 1860 1861 1862 1863 1868 1870 1871 1872 1873 1886 1888 1889 1890 1893 1895 2085 2086 2125 2127 2191 2194 2201 2279 2288 2356 2374 2400 2423 2475 2483 2484 2502 2508 2511 2516 2541 2625 2627 2674 2675 2705 2712 2716 2718 2736 2746 205abs L6 L62 L145 L156 L162 L241 L422 L591 L604 L606 L608 L617 L623 L740 L809 L840 L921 L938 L1141 L1178 L1279 L1441 L1505 L1818 L2024 L2106 L427_2"
varSeq="2" n="b" type="transposition">χριστου ιησου δουλος</rdg>
<rdg wit="180 1751 1881 L164" varSeq="3" n="c" type="transposition">δουλος ιησου χριστου</rdg>
<rdg wit="256 1067" varSeq="4" n="d" type="omission">χριστου δουλος</rdg>
<rdg wit="1702" varSeq="5" n="e" type="singular">ιησου χριστου δουλος ιουδας ιησου χριστου
δουλος</rdg>
<rdg wit="796" varSeq="6" n="f" type="singular"></rdg>
</app>
"""
)
vu = VariationUnit(xml)
self.assertEqual(vu.id, "Jude1_4_8")

def test_init_readings_lem_wits(self):
xml = et.fromstring(
"""
Expand Down

0 comments on commit f468e5c

Please sign in to comment.