premier commit

This commit is contained in:
MALINGREY Adrien
2026-02-04 12:42:17 +00:00
parent 67dfc08956
commit a2c0fece12
6 changed files with 8960 additions and 88 deletions

23
markov.py Normal file
View File

@@ -0,0 +1,23 @@
from collections import defaultdict
from random import choice, randrange
suivants = defaultdict(list)
with open("fra_wikipedia_2021_10K-sentences.txt", "r", encoding="utf-8") as fichier:
for phrase in fichier:
antepenultieme, penultieme = "", ""
for word in phrase.split():
suivants[(antepenultieme, penultieme)].append(word)
antepenultieme, penultieme = penultieme, word
def parle():
phrases = []
for _ in range(randrange(1, 4)):
antepenultieme, penultieme = "", ""
phrase = []
while mots_possibles := suivants[(antepenultieme, penultieme)]:
mot_suivants = choice(mots_possibles)
phrase.append(mot_suivants)
antepenultieme, penultieme = penultieme, mot_suivants
phrases.append(" ".join(phrase))
return "\n".join(phrases)