EDIT: fichier XMLXML liste des Parsing chaînes en python
-<corpus lang="en" id="subtask2-heterographic">
-<text id="het_1">
<word id="het_1_1">'</word>
<word id="het_1_2">'</word>
<word id="het_1_3">I</word>
<word id="het_1_4">'</word>
<word id="het_1_5">m</word>
<word id="het_1_6">halfway</word>
<word id="het_1_7">up</word>
<word id="het_1_8">a</word>
<word id="het_1_9">mountain</word>
<word id="het_1_10">,</word>
<word id="het_1_11">'</word>
<word id="het_1_12">'</word>
<word id="het_1_13">Tom</word>
<word id="het_1_14">alleged</word>
<word id="het_1_15">.</word>
</text>
-<text id="het_2">
<word id="het_2_1">I</word>
<word id="het_2_2">'</word>
<word id="het_2_3">d</word>
<word id="het_2_4">like</word>
<word id="het_2_5">to</word>
<word id="het_2_6">be</word>
<word id="het_2_7">a</word>
<word id="het_2_8">Chinese</word>
<word id="het_2_9">laborer</word>
<word id="het_2_10">,</word>
<word id="het_2_11">said</word>
<word id="het_2_12">Tom</word>
<word id="het_2_13">coolly</word>
<word id="het_2_14">.</word>
</text>
</corpus>
Je suis l'analyse d'un fichier XML sur python et obtenir le texte que je veux. Chaque balise de texte représente une phrase dans le fichier XML et je veux placer chaque phrase comme élément de liste séparé dans une liste.
tree = ET.ElementTree(file='subtask2-heterographic-test.xml')
root = tree.getroot()
lst = []
for elem in root:
for w in elem:
lst.append(w.text)
>> ["'", "'", 'I', "'", 'm', 'halfway', 'up', 'a', 'mountain', ',', "'", "'", 'Tom', 'alleged', '.', 'I', "'", 'd', 'like', 'to', 'be', 'a', 'Chinese', 'laborer', ',', 'said', 'Tom', 'coolly', '.', 'Dentists', ...]
Ceci donne juste tous les mots dans le fichier XML sans séparer la phrase. Comment puis-je le corriger pour mettre chaque phrase dans la liste sous la forme d'une liste de chaînes?
sortie finale prévue:
>> [["'", "'", 'I', "'", 'm', 'halfway', 'up', 'a', 'mountain', ',', "'", "'", 'Tom', 'alleged', '.'] , ['I', "'", 'd', 'like', 'to', 'be', 'a', 'Chinese', 'laborer', ',', 'said', 'Tom', 'coolly', '.'], ['Dentists', ...] ]
votre fragment publier xml au début – RomanPerekhrest
@RomanPerekhrest Désolé. Édité. – user6792790
ok, nous avons eu l'entrée. Maintenant, postez la sortie finale attendue s'il vous plaît – RomanPerekhrest