Changes for Tools/Subj-Obj_Verif.ipynb: 267 added lines, 0 removed lines.
Original line number
Diff line number
Diff line
%% Cell type:markdown id:11a737a9 tags:
#Script Python qui récupère les attributs des tokens dans un XML et les dispose dans un tableur, pour vérification des erreurs concernant subj/expl et (i)obj en relation avec leurs verbes, en se fondant sur le score de dépendance.
%% Cell type:code id:879b8e0a tags:
``` python
importxml.etree.ElementTreeasET
importre
importcsv
```
%% Cell type:code id:40c33ae3 tags:
``` python
#On renseigne les chemins des fichiers
path_in=""
path_out=""
path_out_2=""
path_out_3=""
```
%% Cell type:code id:64a7b859 tags:
``` python
defget_w_text(word):
"""
Function taking a <tei:w> element and
returning its compiled textual content.
:param word: ET.Element('w')
"""
# Preparing the return string as an empty string.
texte=""
# If there is text directly inside <w> element and
# before the first child, add it.
ifword.text:
texte+=str(word.text)
# Loop on all current <w> children.
foriteminword:
# If current child is <tei:height> or <tei:supplied>
ifitem.tag=='height'oritem.tag=='supplied':
# Add text.
texte+=str(item.text)
# If any, add the text following current child.
ifitem.tail:
texte+=str(item.tail)
# If current child is <tei:lb>, add the following text.
elifitem.tag=='lb':
ifitem.tail:
texte+=str(item.tail)
# If current child is <tei:choice>, add the second child of <choice>
# (<tei:reg> or <tei:expan>), then add the text following current child if any.
elifitem.tag=='choice':
texte+=str(item[1].text)
ifitem.tail:
texte+=str(item.tail)
# If current child is <tei:c>, add its text, then the following text if any.
elifitem.tag=='c':
texte+=item.text
ifitem.tail:
texte+=str(item.tail)
# If current child is <tei:hi>, add its text, then the following text if any.
elifitem.tag=='hi':
texte+=item.text
ifitem.tail:
texte+=item.tail
# If current child is <tei:add>, loop on its children and do the same checks.
elifitem.tag=='add':
# On refait tous les tests.
ifitem.find('.')==None:
texte=str(item.text)
else:
ifitem.text:
texte+=str(item.text)
forsubiteminitem:
ifsubitem.tag=='lb':
ifsubitem.tail:
texte+=str(subitem.tail)
elifsubitem.tag=='choice':
texte+=str(subitem[1].text)
ifsubitem.tail:
texte+=str(subitem.tail)
else:
print(f"Please modify me, I can't deal with this token yet:\n\t{ET.tostring(word).decode('utf-8')}")
returntexte
```
%% Cell type:code id:f08992c2 tags:
``` python
#On part des NP-subj/obj/iobj pour chercher le verbe
futurcsv=[]
nosubj_liste=[]
manysubj_liste=[]
# On ouvre le fichier d'entrée
withopen(path_in,encoding="utf8")asxml:
# On importe le XML-TEI d'entrée et on le lit.
tree=ET.parse(path_in)
root=tree.getroot()
#On boucle sur les balises w en reprenant la hiérarchie