-
Notifications
You must be signed in to change notification settings - Fork 0
/
to_translate.py
34 lines (29 loc) · 1015 Bytes
/
to_translate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import xml.etree.ElementTree as et
file = open("train_data/tourkikes_agglikes.txt")
critiques = file.readlines()
lista = []
for item in critiques:
if item != "\n":
lista.append(item.strip())
tree = et.parse("train_data/train_english.xml")
root = tree.getroot()
critiques = []
critique_to_opinion = []
test = False
for review in root:
for sentences in review:
for sentence in sentences:
opinions = sentence.find("Opinions")
if test:
sentence.find("text").text = lista[0]
lista = lista[1:]
if opinions:
if not test:
critiques.append(sentence.find("text").text)
sentence.find("text").text = lista[0]
lista = lista[1:]
critique_to_opinion.append([])
for opinion in opinions:
tag = opinion.attrib
critique_to_opinion[-1].append(tag)
tree.write("train_data/train_turkish.xml")