Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import string
- import matplotlib.pyplot as plt
- import numpy as np
- alphabet = string.ascii_lowercase # lettres a .. z
- alphabet_chiffes = [i for i in range(26)] # chiffres 1 .. 26
- anglais = [8.167, 1.492, 2.782, 4.253, 12.702, 2.228, 2.015, 6.094, 6.966, 0.153, 0.772,
- 4.025, 2.406, 6.749, 7.507, 1.929, 0.095, 5.987, 6.327, 9.056, 2.758, 0.978, 2.360,
- 0.150, 1.974, 0.074]
- francais = [7.636, 0.901, 3.260, 3.669, 14.715, 1.066, 0.866, 0.737, 7.529, 0.613, 0.0074,
- 5.456, 2.968, 7.095, 7.596, 2.521, 1.362, 6.693, 7.948, 7.244, 6.311, 1.838, 0.049,
- 0.427, 0.128, 0.326]
- allemand = [6.516, 1.886, 2.732, 5.076, 16.396, 1.656, 3.009, 4.577, 6.550, 0.268, 1.417,
- 3.437, 2.534, 9.776, 2.594, 0.670, 0.018, 7.003, 7.270, 6.154, 4.166, 0.846, 1.921,
- 0.034, 0.039, 1.134]
- espagnol = [11.525, 2.215, 4.019, 5.010, 12.181, 0.692, 1.768, 0.703, 6.247, 0.493, 0.011,
- 4.967, 3.157, 6.712, 8.683, 2.510, 0.877, 6.871, 7.977, 4.632, 2.927, 1.138, 0.017,
- 0.215, 1.008, 0.467]
- text = [
- """
- TMAIER BERACUO RSU NU REBRA PRCEEH EIANTT NE ONS EBC NU GAOFREM EIMATR RERNAD
- APR L RDUOE LAHECLE UIL TTNI A EUP SREP EC LGNGAEA TE RBONUJO ERMNOUSI DU
- UBRACEO QUE OVSU EEST LIJO UQE OUVS EM MSZELBE BAEU ASNS MIERNT IS RVETO AGRAME
- ES PRARPTOE A OEVTR AMGUPLE VUOS SEET EL PNIHXE DSE OSHET ED CSE BIOS A ESC MSOT
- LE OUBRCEA NE ES ESTN ASP DE IEJO TE OUPR ERRNOTM AS BELEL XOVI IL OREVU NU RGLEA
- ECB ILESSA EBOMTR AS PIOER EL NRDAER S EN ISIAST TE ITD MNO NOB EUSRMNOI NRPEEAZP
- QEU UTOT EUTLRFTA IVT XUA SPNEDE DE UECIL UQI L TECEOU TECET NEOCL VATU BNEI UN
- GMAEORF SNAS TUOED LE EOABURC OHENTXU TE NSCOFU UJRA SMIA UN EPU TRDA UQ NO
- EN L Y ARRPEIDNT ULSP
- """, # francais
- """
- WRE TREITE SO TSPA CUDHR AHNCT UND WIND SE STI RED AEVRT MTI ESEIMN IDNK RE ATH
- END NEABNK WLOH IN EMD AMR ER AFTSS HIN IHSERC RE AHTL HIN MRWA EINM SHNO SAW
- SRTIBG UD SO NGBA DNEI EIHSGTC ESISTH RAETV UD DEN LERNIOKG NITHC NDE LOENINKGRE
- TIM OKRN UDN CHWFSEI NEIM NSOH ES STI IEN BIFTRLSEEEN DU BILESE IKDN OMKM EHG MIT
- MIR RAG ECHNOS EPELSI EIPSL IHC ITM RDI HNCMA BEUTN MBLUNE DINS NA DEM TNDRAS
- NMIEE UTETMR AHT CAMHN UDNGEL GDAWEN MIEN EATRV MENI VEART DUN OSTHER DU
- CINTH SAW KNNOEIREGL RIM ILEES PRSTVRCIEH ISE IHGRU BEEILB RIGUH MNEI KNDI NI
- """, #allemand
- """
- DSNOACAIF ORP ANU DAEDALRI DNAAEIMTI EQU NNCOSETE EL RSTEOUL SMA AACTFAITNS
- UQE LE TSVAO OINSRVUE DE US ANIGIICANOM EIORDP TOOD RTEIENS RPO LE ITOABOLRROA
- ED QIUAMALI USOP A NSSRCAEAD LA TMREAAI NXTADAUEE ROP GOARLS EMESS DE
- NNAMICLUIAPO Y LOVOIV A RES LE RHMEOB EOMDNEERPRD DE LOS RSOPMRIE OMTSIPE UEQ
- CIIDADE LE RTDAAOZ ED LSA CELSAL Y LA NICOIOPS ED LAS UESVNA SSACA Y ES ITRMNEEOD
- QEU AERFU EL UEQIN IIIRDEGAR LA NAIORTREICP DE AL RRTEIA
- """, # espagnol
- """
- IMTRUESMME DNA TEH LNGIIV SI EYAS SIFH REA GJPNUIM DNA HET TTNOCO IS GHIH OH
- OUYR DDADY SI IRHC DAN ROUY MA SI DOGO GKOILON OS USHH LTLIET BBYA NDOT OUY CYR
- NEO OF HESET GNSRONIM YUO RE NANGO SIER PU SNIGING NAD OULLY EPADRS YUOR GINSW
- DAN LYOLU KATE OT HET KSY TUB ITLL THAT MGNIRNO EREHT NATI INTGOHN CAN AHMR OYU
- TWIH DADYD NDA MYMMA NSTIDGAN YB
- """ # anglais
- ]
- def occurence(text):
- text = text.lower()
- compteur_lettre = 0
- # dictionaire initial avec toutes les lettres et leurs frequences de 0
- dict_alpha = {i : 0 for i in string.ascii_lowercase}
- # compte le nombre de lettres et les ajoutes au dict. ci dessus
- for letter in text :
- for alpha in alphabet:
- if letter == alpha:
- dict_alpha[letter] += 1
- compteur_lettre += 1
- # convertis les compteurs en frequences (pourcentage) dans un dict. final
- dict_frequence = {l : (n/compteur_lettre)*100 for (l,n) in dict_alpha.items()}
- return dict_frequence
- def plotter(dict_final):
- # graphique du texte a etudier dans la premiere fenetre
- plt.figure(1)
- plt.subplot(1,1,1)
- plt.bar(alphabet_chiffes, dict_final.values())
- plt.ylabel("texte")
- # graphique des frequences des langues dans la deuxieme fenetre
- plt.figure(2)
- plt.subplot(2,2,1)
- plt.bar(alphabet_chiffes, anglais)
- plt.ylabel("anglais")
- plt.subplot(2,2,2)
- plt.bar(alphabet_chiffes, francais)
- plt.ylabel("francais")
- plt.subplot(2,2,3)
- plt.bar(alphabet_chiffes, allemand)
- plt.ylabel("allemand")
- plt.subplot(2,2,4)
- plt.bar(alphabet_chiffes, espagnol)
- plt.ylabel("espagnol")
- plt.show()
- while True:
- print("Quelle text desirez-vous etudier? [1,2,3,4]")
- t = input(">>>")
- t = text[int(t)-1]
- print(f"Generations des graphics pour le texte:\n{t}")
- print("Pour etudier un autre texte, fermez les pages des graphiques")
- plotter(occurence(t))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement