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 [2021/10/25 14:10] 65.21.180.48 versione precedente ripristinata (2021/06/02 18:15) |
distribuzione_delle_frequenze [2024/07/07 18:48] (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=' | ||
| Linea 28: | Linea 28: | ||
| ---- | ---- | ||
| Applicazione al testo ' | Applicazione al testo ' | ||
| - | <code python> | + | <code python |
| import re | import re | ||
| import matplotlib.pyplot as plt | import matplotlib.pyplot as plt | ||
| - | with open(' | + | f = open(' |
| + | testo = f.read() | ||
| testo=testo[1704: | testo=testo[1704: | ||
| + | |||
| + | # istruzioni per l' | ||
| testo=re.sub("'","' | testo=re.sub("'","' | ||
| testo=re.sub(" | testo=re.sub(" | ||
| testo=testo.lower() | testo=testo.lower() | ||
| + | # fine istruzioni per l' | ||
| + | |||
| 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) | ||
| - | plt.plot(range(1, | + | plt.plot(range(1, |
| plt.show() | plt.show() | ||
| </ | </ | ||
| ---- | ---- | ||
| Il codici seguente usano una lista di tuple, denominata " | Il codici seguente usano una lista di tuple, denominata " | ||
| - | <code python | + | <code python |
| - | frase=u' | + | frase=' |
| 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] | ||
| - | plt.plot(range(len(fd)), | + | plt.plot(range(len(fd)), |
| plt.xticks(range(len(fd)), | plt.xticks(range(len(fd)), | ||
| plt.show() | plt.show() | ||
| - | |||
| </ | </ | ||
| - | + | <code python | |
| - | + | import | |
| - | <code python | + | |
| - | import | + | |
| import matplotlib.pyplot as plt | import matplotlib.pyplot as plt | ||
| - | file=codecs.open('Documents/ | + | f = open('testi/ |
| - | testo=file.read() | + | testo = f.read() |
| + | testo=testo[1704: | ||
| # istruzioni per l' | # istruzioni per l' | ||
| - | # ... | + | testo=re.sub("'","' |
| + | testo=re.sub(' | ||
| + | testo=testo.lower() | ||
| + | # fine istruzioni per l' | ||
| testo=testo.split() | testo=testo.split() | ||
| Linea 77: | Linea 82: | ||
| forme=[i[1] for i in occ_forma] | forme=[i[1] for i in occ_forma] | ||
| n=50 | n=50 | ||
| - | plt.plot(range(n), | + | plt.plot(range(n), |
| plt.xticks(range(n), | plt.xticks(range(n), | ||
| plt.show() | plt.show() | ||
| </ | </ | ||
| + | |||
| + | {{:: | ||