Update my idea, now I want to create a txt file with the first word of the sentence and have the second word of the sentence inside, then delete the first word of the sentence and create another txt with the new first word and save it again word that follows and so on until ending with a sentence.
Example:
(Yo soy Lola.)
Yo.txt=soy
soy.txt=Lola.
Lola..txt=(no habra nada porque la oración concluyo)
If the second sentence that comes has words that have been created, then only the second word is added, but if the second word already exists in that file then it is not added.
Example.
(Yo seré Lola.)
Yo.txt= soy seré
seré.txt= Lola.
Lola.txt=(no habrá nada aqui oración terminada)
With this function I get the first word of the sentence.
def primera_pal(oracion):
for palabra in oracion.split():
print("llege a la funcion: ",palabra)
return palabra
ignore this
def procesar_parrafo(parrafo):
completo = ' '.join(parrafo)
#completo = completo.replace(",", ".")
completo = completo.replace(";", ".")
completo = completo.replace("—","")
completo = completo.replace("«", "")
completo = completo.replace("»", "")
lista_punto = completo.split(".")
return [x.strip() for x in lista_punto]
parrafo=[]
activar_af=0
with open(ruta_libros.format("quijote"), "r", encoding="utf-8") as libro:
parrafo = []
for line in libro:
line = line.strip() # Botar los whitespaces al final.
if line == '':
for oracion in procesar_parrafo(parrafo):
#print(oracion)
with open(ruta_libros.format("quijote2"), "a", encoding="utf-8") as librox:
Well here is the invention (I need to add the sentences in their respective files, with line break.)
### ENFOCATE DE AQUI PARA ABAJO #####
pal_en1=oracion
pal_en2=pal_en1
print("-----Pal 2 Antes: ",pal_en2)
activar_af=0
for oracionx in pal_en2.split():
#print("Oracionx: ", oracionx)
pr_pal = primera_pal(pal_en2)
#pr_pal=' '.join(pal_en2.split()[1:])
with open(ruta_conocimientos.format(pr_pal), "a", encoding="utf-8") as datox:
if oracionx not in "" and activar_af <=2:
print("La oracionx: ",oracionx)
print("Dentro-----------------------------------------")
print("primera_palabra: ",pr_pal)
datox.write(oracionx+" ")
pal_en2=pal_en2.replace(pr_pal,"",1)
activar_af+=1
if activar_af>=2:
datox.write("\n")
datox.close()
print("Pal 2 despues: ",pal_en2)
#if oracion not in "":
# librox.write(oracion+".")
parrafo = []
else:
#print(line)
parrafo.append(line)