plusieurs sources, plusieurs phrases
This commit is contained in:
10
markov.py
10
markov.py
@@ -2,17 +2,19 @@ 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 path in (
|
||||
"fra_wikipedia_2021_10K-sentences.txt",
|
||||
):
|
||||
with open(path, "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():
|
||||
def parle(nb_phrases=1):
|
||||
phrases = []
|
||||
for _ in range(randrange(1, 4)):
|
||||
for _ in range(nb_phrases):
|
||||
antepenultieme, penultieme = "", ""
|
||||
phrase = []
|
||||
while mots_possibles := suivants[(antepenultieme, penultieme)]:
|
||||
|
||||
Reference in New Issue
Block a user