Package: dh-utils
Digital Humanities UtilitiesPython 3.6+ package containing various utilities relevant in the field of digital humanities.$pipinstalldh-utilsUnicode utilitiesConvert Greek beta code to unicode>>>fromdh_utils.unicodeimportbeta2uni>>>beta2uni('lo/gos')'λόγος'This is a wrapper of the CLTK converter. We used this converter to also create inverse:>>>fromdh_utils.unicodeimportuni2beta>>>uni2beta('λόγος')'lo/gos'NB: Sincecltkand its dependencynltkare relatively large, cltk is added as an optional dependency. To use thebeta2uniconverter, either install cltk separately usingpip install cltkor install dh-utils including this optional depency withpip install dh-utils[betacode].Decompose a unicode string>>>u.decompose('λόγος')λ U+03bb GREEK SMALL LETTER LAMDAο U+03bf GREEK SMALL LETTER OMICROŃ U+0301 COMBINING ACUTE ACCENTγ U+03b3 GREEK SMALL LETTER GAMMAο U+03bf GREEK SMALL LETTER OMICRONς U+03c2 GREEK SMALL LETTER FINAL SIGMATEI utilitiesConvert markdown to TEIA basic converter from markdown to TEI has been added. It will convert a markdown file like:Some paragraph block

> A blockquote

1. An
2. Ordered
3. List

Another paragraph block with _italics_ and __bold__, and:

* An
* Unordered
* Listusing a Python snippet like>>>fromdh_utils.teiimportmd2tei>>>withopen('file.md')asf:>>>md=md2tei(f.read())to the following TEI XML:<p>Someparagraphblock</p><quote><p>Ablockquote</p></quote><listrend="numbered"><item>An</item><item>Ordered</item><item>List</item></list><p>Anotherparagraphblockwith<hirend="italic">italics</hi>and<hirend="bold">bold</hi>,and:</p><listrend="bulleted"><item>An</item><item>Unordered</item><item>List</item></list>The functionmd2teiis syntactic sugar for the markdown extensionToTEI, which can be used in combination with other extensions as follows:>>>frommarkdownimportmarkdown>>>fromdh_utils.teiimportToTEI>>>markdown('some text',extensions=[ToTEI()])# Other extensions can be added to this listThe extensionToTEIin turn exists solely of the postprocessorTEIPostprocessor. It has priority 0, which usually means that it will run after all other postprocessors have finished. If any other behaviour or prioritization is required, the processorTEIPostprocessorcan also be directly imported (from dh_utils.tei import TEIPostprocessor) and used in a custommarkdown extension.Tag languagesTag languages in a given string based on its script:>>>fromdh_utils.teiimporttag_script>>>tag_script('A line contaning the hebrew אגוז מלך inline','Hebr')'A line contaning the hebrew <foreign xml:lang="he-Hebr">אגוז מלך</foreign> inline'It is also possible to tag a given language based on its script in a TEI XML document (NB: file will be overwritten!):>>>fromdh_utils.teiimporttag_script_from_file>>>tag_script_from_file('path/to/file.xml','Arab')The available scripts are stored indh_utils.tei.AVAILABLE_SCRIPTSand are enumerated below:>>>fromdh_utils.teiimportAVAILABLE_SCRIPTS>>>AVAILABLE_SCRIPTS['Arab','Copt','Hebr','Latn','Cyrl']Default language-script codes are used to tag the scripts (stored inDEFAULT_LCS), which can be adjusted using thelanguage_codekeyword argument:>>>t.tag_script_from_file('path/to/file.xml','Cyrl',language_code='ov-Cyrs')Refsdecl generatorTo generate refsdecl elements, the generator can be used to create etree xml elements:fromdh_utils.teiimportrefsdecl_generatorrefs_decl=refsdecl_generator.generate_for_file("./path/to/file")refs_decls=refsdecl_generator.generate_for_path("./path/to/files")It can also be used trough the command line interface:python -m dh_utils.tei.refsdecl_generator [--update] [PATH]By default, it does not update the file but outputs the refsdecl xml to the terminal. If the--updateflag is given, the file is updated with the generated refsdecl.MyCapytain-compatilble critical apparatusThe Python APIMyCapytainonly serves the main text of a CTS structured text version, and does not support stand-off annotation, bibliographies, critical apparati, etc. To overcome the last problem, we have developed a script that generates a separate text version of the critical apparatus that can be served throughMyCapytain. Brill'sScholarly Editionsuses these separate text versions, which can be displayedin parallel.The following snippet creates such a critapp file fromtextgroup.work.edition-extension.xmllocated inpath/to/data/textgroup/workand saves it astextgroup.work.edition-appcrit1.xml>>>fromdh_utils.teiimportcrit_appasca>>>data_dir="path/to/data/textgroup/work">>>filename="textgroup.work.edition-extension.xml">>>ca_ext="appcrit1"# Or any other extension>>>ca.create(filename,ca_ext,data_dir)If a file contains multiple critical apparati, these can be distinguished using/listApp[@type], e.g.:<listApptype="superior"><app/><app/>...</listApp><listApptype="inferior"><app/><app/>...</listApp>Using the above snippet will combine these apparati into one file. If these should be conerted to separate files, one can pass an additional argumentapp_typetoca.create(e.g.,ca.create(filename, ca_ext, data_dir app_type="superior")) to convert an apparatus separately.