1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import csv
- import random
- mots = []
- def main():
- with open("Lexique382.txt") as lexique:
- lexique = csv.reader(lexique, delimiter='\t')
- for raw in lexique:
- if raw[3] == "NOM":
- mots.append(Nom(raw[0], raw[4], raw[5]))
- print("%s %s ce que %s %s" % \
- (random.choice(mots).det_mot_vrb(), \
- random.choice(mots).pre_mot(), \
- random.choice(mots).det_mot_vrb(), \
- random.choice(mots).pre_mot()))
- class Nom():
- def __init__(self, mot, genre, nombre):
- self.mot = mot
- self.genre = genre
- self.nombre = nombre
- def det(self):
- if self.nombre == 'p':
- return "les "
- elif self.mot[0] in ['a','à','e','é','è','ê','i','o','u','y']:
- return "l'"
- elif self.genre == 'f':
- return "la "
- else:
- return "le "
- def pre(self):
- if self.det() == "les ":
- return "aux "
- if self.det() == "le ":
- return "au "
- if self.det() == "la ":
- return "à la "
- if self.det() == "l'":
- return "à l'"
- def vrb(self):
- if self.nombre == "p":
- return "sont"
- else:
- return "est"
- def det_mot_vrb(self):
- return self.det() + self.mot + " " + self.vrb()
- def pre_mot(self):
- return self.pre() + self.mot
- main()
|