I am trying to replace words from one column in another column in a text:
Text:
While these delays were noted, active nuclear power plants have been building individual warehouses within their facilities to store the dangerous spent fuel from their reactors.
Column text:
verify, they verified
this, these
delay, delays
the, the
central, central
nuclear, nuclear
have, have
go, gone
build, build
warehouse, warehouses
individual, individual
its, its
installation, installations
spend, spent
reactor, reactors
meter, m
second, s
page, p
actor, actors
Script:
import csv
with open('teste_es.csv', 'r') as f, open('lemas-lexemas.csv', 'r') as c:
csv_texto = csv.reader(f)
csv_lemas = csv.reader(c, delimiter = ',')
for p in csv_texto:
texto = ''.join(p)
texto = texto.lower()
for tokens in csv_lemas:
lemas = tokens[0]
lexemes = tokens[1]
nuevo_texto = texto.replace(lexemes, lemas)
texto = nuevo_texto
print(nuevo_texto)
Result:
Within a second second, the rear-end cluster or the active nuclear power station will have to be converted to a single centimeter within seconds, depending on the page to save the second page, or it will be possible to drill down from the second reactor.
The problem is that my program replaces letters within words:
while it became metro in the second because the first letter "m" is replaced by "metro". I do not know how to make each word be replaced. Yes I can use split (), but I have many lines in my text and I can not lose them (if I do a split () and then a join (), I lose my split lines)