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
|
from random import choice, randrange
|
||||||
|
|
||||||
suivants = defaultdict(list)
|
suivants = defaultdict(list)
|
||||||
|
for path in (
|
||||||
with open("fra_wikipedia_2021_10K-sentences.txt", "r", encoding="utf-8") as fichier:
|
"fra_wikipedia_2021_10K-sentences.txt",
|
||||||
|
):
|
||||||
|
with open(path, "r", encoding="utf-8") as fichier:
|
||||||
for phrase in fichier:
|
for phrase in fichier:
|
||||||
antepenultieme, penultieme = "", ""
|
antepenultieme, penultieme = "", ""
|
||||||
for word in phrase.split():
|
for word in phrase.split():
|
||||||
suivants[(antepenultieme, penultieme)].append(word)
|
suivants[(antepenultieme, penultieme)].append(word)
|
||||||
antepenultieme, penultieme = penultieme, word
|
antepenultieme, penultieme = penultieme, word
|
||||||
|
|
||||||
def parle():
|
def parle(nb_phrases=1):
|
||||||
phrases = []
|
phrases = []
|
||||||
for _ in range(randrange(1, 4)):
|
for _ in range(nb_phrases):
|
||||||
antepenultieme, penultieme = "", ""
|
antepenultieme, penultieme = "", ""
|
||||||
phrase = []
|
phrase = []
|
||||||
while mots_possibles := suivants[(antepenultieme, penultieme)]:
|
while mots_possibles := suivants[(antepenultieme, penultieme)]:
|
||||||
|
|||||||
Reference in New Issue
Block a user