Advertisement
Guest User

Untitled

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