Skip to content

Instantly share code, notes, and snippets.

@Epithumia
Last active November 8, 2019 20:56
Show Gist options
  • Save Epithumia/7374e61398a6fb0985e78949ef3a9c6b to your computer and use it in GitHub Desktop.
Save Epithumia/7374e61398a6fb0985e78949ef3a9c6b to your computer and use it in GitHub Desktop.
# Prendre https://github.com/hbenbel/French-Dictionary -> le fichier avec tous les mots/verbes/etc
from itertools import product, groupby
import unicodedata
mots = ['', 'REPONSE', 'ETONNANTE', 'DE', 'LA', 'PART', 'DE', 'NOS', 'GRANDS', 'ASTRES',
'FORT', 'PEU', 'CONCLUANTE', 'BIEN', 'QUE', 'NENNI', 'LANCONS', 'NOUS', 'TOUT', 'DE', 'MEME']
phrase = [[3,1,10,20,14,5], [6,4,15,17], [12,2], [19,4,18,20], [3,13],
[6,15,11,4,10,18], [4], [15,7,18,11,10], [5,3,12,9,4,15,13,10,4,8,14],
[15,19,12,11,7,17,5,13,10,20]]
with open('liste_francais.txt', 'r') as liste:
dico = liste.readlines()
dico_plein = [unicodedata.normalize("NFD", x.strip()).encode('ascii', 'ignore').decode('utf-8') for x in dico]
dico = []
for i in range(12):
dico.append([])
for mot in dico_plein:
if len(mot) <= 11:
dico[len(mot)].append(mot.upper())
del dico_plein
i = 0
for m in phrase:
mot = []
ens = []
for l in m:
poss = []
pre = sorted(mots[l])
mot_s = ''.join(ch for ch, _ in groupby(pre))
for c in mot_s:
poss.append(c)
ens.append(poss)
p = list(product(*ens))
i += 1
bound = len(p)
st = int(bound / 100)
print(i, '[' + str(bound )+ ']')
ans = []
count=0
for item in p:
count+=1
if st > 1000 and count%st == 0:
print(count/st, '%\r', end="")
w = ''.join(item)
if w in dico[len(w)]:
ans.append(w)
elif w[0:2] == 'RE' and w[2:] in dico[len(w[2:])]:
ans.append(w)
print(list(set(ans)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment