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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
| #!/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?") |