#!/usr/bin/env python
# -*- coding: utf8 -*-
# Publié sous les termes de la CC-BY-SA
import re
from sys import argv
import random
start = "o"
fic = open ("texte.txt", "w")
fic.close()
while start == "o" or start == "O" :
print (" ")
print ("Ceci est un générateur de descritif d'image. Indiquez l'objet principal pour chaque zone. S'il vous souhaitez ne rien indiquer, écrivez 'rien'.")
fic = open("image.txt","r")
tableau = tuple(fic.readlines())
for i in range(0,len(tableau)):
print (tableau[i].strip())
liste =("123456789")
reponse = ["","","","","","","","","",""]
for i in range(0,len(liste)):
reponse[i] = input ("Que voit on en "+ liste[i] +" ? ")
if reponse[i] == "rien" :
print ("Aucune description")
else :
print ("Vous avez écrit : " + reponse[i])
def generateur_phrase (plan,obj) :
if obj != "rien":
fic = open ("comment.txt", "r")
n_ligne_com = tuple (fic.readlines())
ranc = random.randint(0,len(n_ligne_com))-1
fic.close()
fic = open (str(plan)+".txt", "r")
n_ligne = tuple (fic.readlines())
ran = random.randint(0,len(n_ligne))-1
fic.close()
fic = open ("verbes.txt", "r")
n_ligne_verbe = tuple (fic.readlines())
ranv = random.randint(0,len(n_ligne_verbe))-1
fic.close()
fic = open ("ponctuation.txt", "r")
pon = tuple (fic.readlines())
ranp = random.randint(0,len(pon))-1
fic.close()
texte = n_ligne_com[ranc].strip()+" "+n_ligne[ran].strip()+" "+n_ligne_verbe[ranv].strip()+" "+obj
print (texte)
# print (n_ligne_com[ranc].strip()+" "+n_ligne[ran].strip()+" "+n_ligne_verbe[ranv].strip()+" "+obj, end =pon[ranp])
fic = open ("texte.txt", "a")
fic.write(texte)
fic.close()
# print (" {} {} {}".format(n_ligne[ran].strip(),n_ligne_verbe[ranv].strip(),obj), end =pon[ranp])
print ("\n"+"Voici la description de votre image"+"\n")
for i in range(9):
generateur_phrase (i+1, reponse[i])
print (" ")
start = input("Voulez-vous effectuer une autre description ? (o/n) : ")
BDD = []
liste_def = []
count = 0
nb_passe = input ("combien de passage?")
fin = [",", ")", ".", "!", "»", "]"]
fic = open ("texte.txt", "r")
#source = turple (fic.readlines())
source = str (fic.readlines())
print (source)
fic.close()
liste_source = source.rstrip('\n\r').split(" ")
long_source = len(liste_source)
with open ("thes_fr.dat", 'r') as base:
for ligne in base:
ligne = ligne.rstrip('\n').split("|")
BDD.append(ligne)
#if ligne[1].decode('utf-8').isdigit():
if ligne[1].isdigit():
liste_def.append(int(count))
count += 1
for x in range(int(nb_passe)):
mot = ''
fin_mot = ''
while len(mot) < 4:
#num_choix_mot_source = randrange(long_source)
num_choix_mot_source = random.randrange(long_source)
mot = liste_source[num_choix_mot_source]
for i in fin:
if mot[-1] == i:
fin_mot = i #conserve la fin du mot
print(fin_mot)
mot = mot[:-1] # tronque la fin du mot
for i in range(len(liste_def)):
if mot == BDD[liste_def[i]][0]: # ne parcourt que les lignes de définition
nb_sens = int(BDD[liste_def[i]][1]) # check le nb de sens
if nb_sens != 1:
choix_sens = random.randrange(nb_sens)+1
liste_mot = BDD[int(liste_def[i])+choix_sens] #choisi parmi les différents sens
else:
liste_mot = BDD[int(liste_def[i])+1]
synonyme = liste_mot[random.randrange(len(liste_mot)-1)+1] #choisi un mot dans la liste choisie
print('''"{0}" est devenu "{1}"'''.format(mot, synonyme))
liste_source[num_choix_mot_source] = synonyme+fin_mot #remplace le mot dans la liste en ajoutant la fin éventuelle
final = ""
for i in liste_source:
final += i + " "
#print (final.decode('utf-8'))
print (final)
ok = input ("ok?");
Partager