Changes for corpus-construction/add-structure-to-transkribus-tei/ts-to-tei.ipynb: 5 added lines, 5 removed lines.
Original line number
Diff line number
Diff line
%% Cell type:markdown id: tags:
# Transform a TEI-XML export from Transkribus into TEI-XML according to the ConDÉ project specifications.
This script may be optimised or partly rewritten. If I rewrite it, this version will be kept as documentation for the building of the ConDÉ corpus.
You are free to use this script for your own corpus. Know however that you may need to adapt your data, or adapt the script to your data.
Transkribus format observations:
### Transkribus format observations:
* Informations are split into graphical information (description of text zones on the original image by giving coordinates for the pixels which form the corners of the zone) and textual information, and both are linked through identifiers. This may be shortly summarised thus:
```xml
<TEI>
<teiHeader/>
<facsimile>
<zoneid="paragid">
<zoneid="lineid"/>
</zone>
</facsimile>
<text>
<pfacs="#paragid">
<lfacs="#lineid">text</l>
</p>
</text>
</TEI>
```
* Anything you type within Transkribus will be noted in the graphic description part instead (`/TEI/facsimile/zone`). Yet you are going to more-or-less copy graphical information and transform the full structure of the text: it is therefore more convenient to base oneself on the text and test the types of the zones through the identifiers.
* Any type given to a zone through the Transkribus GUI will be noted in the graphic description part of this zone (`/TEI/facsimile/zone`). Yet you are going to more-or-less copy graphical information and transform the full structure of the text: it is therefore more convenient to base oneself on the text and test the types of the zones through the identifiers.
* Transkribus takes all text information at the same level: zones and lines. This script aims to structure the data better.
### Imports and reclarations
%% Cell type:code id: tags:
``` python
importxml.etree.ElementTreeasET
importre
# This is the TEI namespace declaration.
# Since it is the main namespace, no prefix is added.
### FUNCTION: convert XML data to ConDÉ semantic TEI
Where the actual script takes place.
ConDÉ format specifics (note: attributes will be noted as att. in the XPath expressions, since the *at* sign is used for user identification on GitHub):
* Three levels of text division: `/TEI/text/div[att.type="part"]/div[att.type="chapter"]/div[att.type="section"]`
* The initial Transkribus types (in `//zone/att.subtype`) have been manually changed to resemble the semantic typing I had in mind, through automatic search and replace in a text editor (I used Oxygen). If you need to adapt this script to your own texts, please change zone types where needed (e.g. in `if para.get('subtype') == "titre":...`.
* If your text may be divided into front, body and back matters, the corresponding TEI elements `/TEI/text/(front|body|back)` must be added manually before application of current script around the identified paragraphs.
* Elements `//l[att.subtype="sectionhead"]` did not get this subtype attribute from Transkribus, but from a regular expression search and replace: by identifying the specifics of the section titles, I was able to get most of them by a regular expression. This meant a search and replace had to be made for each sample in the corpus.
* The initial Transkribus types (in `//zone/att.subtype`) have been manually changed to resemble the semantic typing I had in mind, through automatic search and replace in a text editor (I used [Oxygen](https://www.oxygenxml.com/)). If you need to adapt this script to your own texts, please change zone types where needed (e.g. in `if para.get('subtype') == "titre":...`.
* If your text may be divided into front, body and back matters, as ours could, the corresponding TEI elements `/TEI/text/(front|body|back)` must be added manually before application of current script around the identified paragraphs.
* Elements `//l[att.subtype="sectionhead"]` did not get this subtype attribute from Transkribus, but from a regular expression search and replace directly in the XML file: by identifying the specifics of the section titles, I was able to get most of them by a regular expression. This meant a search and replace had to be made for each sample in the corpus.
%% Cell type:code id: tags:
``` python
defto_tei(xml_entree,chemin_sortie):
"""
Function reading a TEI-XML file written by Transkribus prepared with zone typing,
and returning a more semantically encoded TEI-XML file.
:param xml_entree: As a string, the local path to the Transkribus TEI-XML output to read.
:param chemin_sortie: As a string, the local path to write the resulting XML file to.
"""
# Declare a dict. for identifiers.
transcriptions={}
# The lines of these types are not actually part of the text
# and must be kept apart: they are about the page/codex format