Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. import texte
  2.  
  3. ponctuation = ",.:;'-"
  4.  
  5. def compter_ponctuation(txt):
  6.   nombre = 0
  7.   for x in txt:
  8.     if x in ponctuation:
  9.       nombre += 1
  10.   return nombre
  11.  
  12. def compter_mots(txt):
  13.   for x in ponctuation:
  14.     txt = txt.replace(x," " )
  15.   tableau = txt.split(" ")
  16.   nombre_mots = 0
  17.   for y in tableau:
  18.     if len(y) > 0:
  19.       nombre_mots += 1
  20.   return nombre_mots
  21.  
  22. def compter_frequences(txt):
  23.   for x in ponctuation:
  24.     txt = txt.replace(x," " )
  25.   tableau = txt.split(" ")
  26.   mots_comptes = {}
  27.   for mot in tableau:
  28.     if mot in mots_comptes:
  29.       mots_comptes[mot]+= 1
  30.     else:
  31.       if len(mot)>0:
  32.         mots_comptes[mot] = 1
  33.   return mots_comptes
  34.  
  35.  
  36.  
  37. #print(texte.article)
  38. #print("\nponctuation:")
  39. #print(compter_ponctuation(texte.article))
  40. #print("mots:")
  41. #print(compter_mots(texte.article))
  42. #print("mots frequents:")
  43.  
  44. #decompte = compter_frequences(texte.article)
  45.  
  46. #for i in sorted(decompte,key=decompte.get,reverse=True ):
  47. #  print(i,decompte[i])
  48.  
  49. # Maintenant on analyse le sondage
  50.  
  51. import donnees
  52.  
  53. txt = " ".join(donnees.donnees).lower()
  54.  
  55. #decompte = compter_frequences(txt)
  56.  
  57. #for i in sorted(decompte,key=decompte.get,reverse=True ):
  58. #  print(i,decompte[i])
  59.  
  60. import nltk
  61. token =  txt.split()
  62.  
  63. freq = nltk.FreqDist(token)
  64.  
  65. freq.plot(20, cumulative=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement