commited all contents created by participants
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
import nltk
|
||||
from duckduckpy import query
|
||||
import random
|
||||
|
||||
# ------------------ #
|
||||
# en-tête du script > déclaration des fonctions
|
||||
# ------------------ #
|
||||
|
||||
# fonction qui extrait les mots et les stockent dans une liste
|
||||
def words_extract( str ):
|
||||
tokens = nltk.word_tokenize( str )
|
||||
words = []
|
||||
for word, pos in nltk.pos_tag(tokens):
|
||||
if pos == 'NN':
|
||||
words.append(word)
|
||||
return words
|
||||
|
||||
# fonction qui génère un nombre aléatoire à partir de la liste de mots pour pouvoir choisir un mot
|
||||
def rand_words( list ):
|
||||
list_len = len( list )
|
||||
ran_num = random.randint(0,list_len-1)
|
||||
return ran_num
|
||||
|
||||
# fonction pour chercher dans duckduckgo
|
||||
def srch_engine( list, num ):
|
||||
srch = query(list[num], container='dict')
|
||||
res = srch['related_topics'][0]['text']
|
||||
return res
|
||||
|
||||
# ------------------ #
|
||||
# corps du script > appel des fonctions
|
||||
# ------------------ #
|
||||
|
||||
# phrase de départ
|
||||
sentence = "Encoded inside a beautiful microchip are the blue patterns of my small fingertips"
|
||||
|
||||
# ------------------- #
|
||||
# niveau 1
|
||||
# ------------------- #
|
||||
|
||||
# 1
|
||||
print('\n')
|
||||
print('1. ' + sentence)
|
||||
|
||||
# extraction des mots de la phrase de départ
|
||||
words = words_extract( sentence )
|
||||
|
||||
# 1.2
|
||||
print(words)
|
||||
|
||||
# 1.3 - génération du nombre pour le choix du mot
|
||||
ran_num = rand_words( words )
|
||||
print(ran_num)
|
||||
|
||||
# ------------------- #
|
||||
# niveau 2
|
||||
# ------------------- #
|
||||
|
||||
# 2 - on va chercher une phrase à partir du mot sélectionné
|
||||
sentence2 = srch_engine(words, ran_num)
|
||||
print('\t 2. ' + sentence2)
|
||||
|
||||
# extraction des mots de la phrase 2
|
||||
words = words_extract( sentence2 )
|
||||
|
||||
# 2.2
|
||||
print(words)
|
||||
|
||||
# 2.3 - génération du nombre pour le choix du mot
|
||||
ran_num = rand_words( words )
|
||||
print(ran_num)
|
||||
|
||||
# ------------------- #
|
||||
# niveau 3
|
||||
# ------------------- #
|
||||
|
||||
# 3 - on va chercher une phrase à partir du mot sélectionné
|
||||
sentence3 = srch_engine(words, ran_num)
|
||||
print('\t\t 3. ' + sentence3)
|
||||
|
||||
# extraction des mots de la phrase 2
|
||||
words = words_extract( sentence3 )
|
||||
|
||||
# 3.2
|
||||
print(words)
|
||||
|
||||
# 3.3 - génération du nombre pour le choix du mot
|
||||
ran_num = rand_words( words )
|
||||
print(ran_num)
|
||||
|
||||
# ------------------- #
|
||||
# niveau 4
|
||||
# ------------------- #
|
||||
|
||||
# 4 - on va chercher une phrase à partir du mot sélectionné
|
||||
sentence4 = srch_engine(words, ran_num)
|
||||
print('\t\t\t 4. ' + sentence4)
|
||||
|
||||
# extraction des mots de la phrase 2
|
||||
words = words_extract( sentence4 )
|
||||
|
||||
# 4.2
|
||||
print(words)
|
||||
|
||||
# 4.3 - génération du nombre pour le choix du mot
|
||||
ran_num = rand_words( words )
|
||||
print(ran_num)
|
||||
|
||||
# ------------------- #
|
||||
# niveau 5
|
||||
# ------------------- #
|
||||
|
||||
# 5 - on va chercher une phrase à partir du mot sélectionné
|
||||
sentence5 = srch_engine(words, ran_num)
|
||||
print('\t\t\t\t 5. ' + sentence5)
|
||||
|
||||
# extraction des mots de la phrase 2
|
||||
words = words_extract( sentence5 )
|
||||
|
||||
# 5.2
|
||||
print(words)
|
||||
|
||||
# 5.3 - génération du nombre pour le choix du mot
|
||||
ran_num = rand_words( words )
|
||||
print(ran_num)
|
||||
|
||||
# ------------------- #
|
||||
# écriture du fichier
|
||||
# ------------------- #
|
||||
|
||||
# on ouvre un fichier
|
||||
file = open('ola#5doc/jeremie_nuel/infra-ordinaire.txt', 'w')
|
||||
# on l'écrit
|
||||
file.write('\n 1.' + sentence )
|
||||
file.write('\n\t 2. ' + sentence2 )
|
||||
file.write('\n\t\t 3. ' + sentence3 )
|
||||
file.write('\n\t\t\t 4. ' + sentence4 )
|
||||
file.write('\n\t\t\t\t 5. ' + sentence5 )
|
||||
file.close()
|
||||
print('fichier écrit')
|
||||
Reference in New Issue
Block a user