Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
| Entrambe le parti precedenti la revisione Revisione precedente Prossima revisione | Revisione precedente | ||
|
distribuzione_delle_frequenze_senza_nltk [2021/06/02 17:57] 31.156.199.251 |
distribuzione_delle_frequenze_senza_nltk [2021/06/02 18:15] (versione attuale) admin |
||
|---|---|---|---|
| Linea 1: | Linea 1: | ||
| - | ====== Distribuzione delle frequenze | + | ====== Distribuzione delle frequenze ====== |
| Esemplificazione su una singola frase. Si noti, innanzitutto, | Esemplificazione su una singola frase. Si noti, innanzitutto, | ||
| <code python> | <code python> | ||
| import matplotlib.pyplot as plt | import matplotlib.pyplot as plt | ||
| frase=' | frase=' | ||
| - | #Se si è in ambiente shell (interfaccia a riga di comando richiamabile da " | ||
| - | # anziché utilizzare il comando print è possibile | ||
| - | #digitare semplicemente il nome della variabile di cui si vuole ispezionare il valore. | ||
| - | #Ad es., anziché digitare **print(frase)**INVIO basta digitare **frase**INVIO. | ||
| print(frase) | print(frase) | ||
| + | #Se si è in ambiente shell | ||
| + | # | ||
| + | #anziché utilizzare il comando “print” è possibile digitare solamente | ||
| + | #il nome della variabile di cui si vuole ispezionare il valore. | ||
| + | #Ad es., anziché digitare “print(frase)”INVIO basta digitare “frase”INVIO. | ||
| frase=frase.split() | frase=frase.split() | ||
| print(frase) | print(frase) | ||
| Linea 19: | Linea 20: | ||
| fd.sort(reverse=True) | fd.sort(reverse=True) | ||
| print(fd) | print(fd) | ||
| - | for i in range(1,11): print(i) | + | sequenza=range(1,len(fd)+1) |
| - | plt.plot(range(1, | + | for i in sequenza: print(i) |
| + | plt.plot(sequenza,fd,'.') | ||
| plt.show() | plt.show() | ||
| </ | </ | ||
| - | <code python> | ||
| - | import matplotlib.pyplot as plt | ||
| - | frase=u' | ||
| - | print frase | ||
| - | frase=frase.split() | ||
| - | print frase | ||
| - | print len(frase) | ||
| - | print set(frase) | ||
| - | print len(set(frase)) | ||
| - | print frase.count(' | ||
| - | fd=[frase.count(i) for i in set(frase)] | ||
| - | print fd | ||
| - | fd.sort(reverse=True) | ||
| - | print fd | ||
| - | for i in range(1, | ||
| - | plt.plot(range(1, | ||
| - | plt.show() | ||
| - | </ | ||
| - | |||
| ---- | ---- | ||
| Applicazione al testo ' | Applicazione al testo ' | ||
| <code python> | <code python> | ||
| - | import codecs | ||
| import re | import re | ||
| import matplotlib.pyplot as plt | import matplotlib.pyplot as plt | ||
| - | file=codecs.open('Testi/ | + | with open('testi/ |
| - | testo=file.read() | + | testo=testo[1704:] |
| - | + | ||
| - | testo=testo[1758:] | + | |
| testo=re.sub("'","' | testo=re.sub("'","' | ||
| testo=re.sub(" | testo=re.sub(" | ||
| testo=testo.lower() | testo=testo.lower() | ||
| testo=testo.split() | testo=testo.split() | ||
| - | |||
| fd=[testo.count(i) for i in set(testo)] | fd=[testo.count(i) for i in set(testo)] | ||
| fd.sort(reverse=True) | fd.sort(reverse=True) | ||
| Linea 69: | Linea 48: | ||
| frase=frase.split() | frase=frase.split() | ||
| occ_forma=[(frase.count(i), | occ_forma=[(frase.count(i), | ||
| - | print occ_forma | + | print(occ_forma) |
| occ_forma.sort(reverse=True) | occ_forma.sort(reverse=True) | ||
| - | print occ forma | + | print (occ_forma) |
| fd=[i[0] for i in occ_forma] | fd=[i[0] for i in occ_forma] | ||
| forme=[i[1] for i in occ_forma] | forme=[i[1] for i in occ_forma] | ||