Changes for corpus-construction/add-structure-to-transkribus-tei/add_xmlid_to_divs.ipynb: 4 added lines, 0 removed lines.
Original line number
Diff line number
Diff line
%% Cell type:markdown id: tags:
# Adding semi-automatic @xml:id to structured TEI-XML files
Script constructing identifiers for TEI-XML divs, according to the ConDÉ project schema, all values separated by `-`, all body div numbers formatted with three digits and all front|back div numbers formatted with two digits.
For `//tei:text/tei:front` and `//tei:text/tei:back` divs, the construction is as follows:
* source id,
* type of edition (base/txm/simplified),
* current version (alpha/beta)
* frontMatter or backMatter
* number of current front/div or back/div
* subtype of current front/div if any,
* number of current front/div/div if subject div is inside a div itself (max 2 levels of div in front and back).
Changes for corpus-construction/add-structure-to-transkribus-tei/extract-ambiguous-tokens-from-xml.ipynb: 43 added lines, 7 removed lines.
Original line number
Diff line number
Diff line
%% Cell type:markdown id: tags:
# Extract ambiguous tokens into CSV file
From one TEI-XML file, this script extracts all tokens whose linguistic enrichment is unsure, whether because the lemmatiser gave several possible options, or because it could not give one.
This script has possible issues which need to be examined and dealt with eventually. They include these facts:
* the XML information is parsed *without* namespace information (so the TEI namespace declaration needs to be removed from the XML file for the script to work),
* the `get_text()` function may be obsolete,
* the `get_text()` function has two versions, one is commented,
* documentation is currently in French and old.
### IMPORTS and declarations
%% Cell type:code id: tags:
``` python
importxml.etree.ElementTreeasET
importcsv
importdatetime
```
%% Cell type:markdown id: tags:
### FUNCTION: extract the text from a given token
%% Cell type:code id: tags:
``` python
defget_text(token):
texte=""
choice=["corr","expan","reg"]
w_token=ET.fromstring(token)
ifw_token.text:
texte+=w_token.text
"""for item in w_token.findall("./*"):
# if item.tag == '{http://tei-c.org/ns/1.0}height' or item.tag == '{http://tei-c.org/ns/1.0}supplied':
if item.tag == 'c' or item.tag == 'supplied':
texte += str(item.text)
# S'il y a du texte après la balise fermante et avant
# le prochain enfant ou la balise fermante du <w>,
# on l'ajoute.
if item.tail:
texte += str(item.tail)
# elif item.tag == '{http://tei-c.org/ns/1.0}lb':
elif item.tag == 'lb':
if item.tail:
texte += str(item.tail)
# Si l'enfant est un <choice>, on récupère le texte de son
# second enfant et on vérifie s'il y a du texte après le <choice>.
Changes for corpus-construction/disambiguate-lemmatization-in-corrected-file/REV_1_script_id_tokens.ipynb: 38 added lines, 72 removed lines.
Original line number
Diff line number
Diff line
%% Cell type:markdown id: tags:
# Re-numbering tokens after revisions
* __Note__: This script is similar to [this one](../lemmatize-new-witness/NV_1_numerotation_tokens.ipynb), which is rather meant for a file whose `<w>` still have no `att.n` attributes.
* __Note__: due to the fact that on GitHub the `@` sign is used to tag users, it is replaced by `att.` in XPath expressions.
This script takes a valid TEI-XML file, tokenised with `//tei:w[att.n]` elements. Its only function will remove the current `att.n` when they are there, and give a new unique number to each `<w>` element, within an `att.n` attribute, in the reading order.
### FUNCTION: give each `<w>` element a (new?) number
%% Cell type:code id: tags:
``` python
defid_tokens_in_tei(chemin_entree,chemin_sortie):
"""
Fonction permettant de lire un fichier XML-TEI pour cibler les
éléments <w> et leur ajouter un @n unique, numéroté à partir de 1.
Si on souhaite utiliser des entités, elles sont résolues dans le
fichier de sortie, mieux vaut donc les installer ensuite.
:param chemin_entree: Le chemin local du fichier XML-TEI tokenisé
aux éléments <w> duquel on souhaite ajouter des numéros.
:param chemin_sortie: Le chemin local auquel on souhaite écrire le
fichier XML-TEI de sortie avec ses @n ajoutés.
This function takes a valid TEI-XML file as input.
It targets all <w> elements and gives them a unique
@n attribute, numbered from 1, removing the previous
one if needed. The result is a valid TEI-XML file.
:param chemin_entree: The local path to the tokenized
TEI-XML file whose <w> elements need to be numbered.
:param chemin_sortie: The local path for the output file.