texte-a-trous~20171216-172337.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import csv
  4. import random
  5. mots = []
  6. def main():
  7. with open("Lexique382.txt") as lexique:
  8. lexique = csv.reader(lexique, delimiter='\t')
  9. for raw in lexique:
  10. if raw[3] == "NOM":
  11. mots.append(Nom(raw[0], raw[4], raw[5]))
  12. print("%s %s ce que %s %s" % \
  13. (random.choice(mots).det_mot_vrb(), \
  14. random.choice(mots).pre_mot(), \
  15. random.choice(mots).det_mot_vrb(), \
  16. random.choice(mots).pre_mot()))
  17. class Nom():
  18. def __init__(self, mot, genre, nombre):
  19. self.mot = mot
  20. self.genre = genre
  21. self.nombre = nombre
  22. def det(self):
  23. if self.nombre == 'p':
  24. return "les "
  25. elif self.mot[0] in ['a','à','e','é','è','ê','i','o','u','y']:
  26. return "l'"
  27. elif self.genre == 'f':
  28. return "la "
  29. else:
  30. return "le "
  31. def pre(self):
  32. if self.det() == "les ":
  33. return "aux "
  34. if self.det() == "le ":
  35. return "au "
  36. if self.det() == "la ":
  37. return "à la "
  38. if self.det() == "l'":
  39. return "à l'"
  40. def vrb(self):
  41. if self.nombre == "p":
  42. return "sont"
  43. else:
  44. return "est"
  45. def det_mot_vrb(self):
  46. return self.det() + self.mot + " " + self.vrb()
  47. def pre_mot(self):
  48. return self.pre() + self.mot
  49. main()