NOTA: Il codice sorgente Python completo, relativo all'articolo "Validation of Simultaneous Additive Trees in Textual Data Visualization"
(convegno JADT_2026 a Palermo [Italia]), è disponibile. Cliccare su:
: Python_CA_AT_ValidationI
Caricamento del file compresso contenente codici e dati [cartella: "ADT_py"]
Il codice di queste due funzioni, insieme ai relativi contesti d'uso, costituisce un esempio didattico tratto dal volume *Analyse des Données Textuelles* (L. Lebart, B. Pincemin, C. Poudat), Presses de l'Université du Québec, 2019. Analyse des Données Textuelles (L. Lebart, B. Pincemin, C. Poudat), Presse de l'Université du Québec, 2019.
Il linguaggio di programmazione Python — la cui prima versione risale al 1989, a opera di Guido van Rossum — rappresenta lo strumento versatile ideale per i ricercatori che lavorano con i testi. Pur essendo di facile approccio, questo linguaggio open source offre una sorta di sintesi tra i linguaggi di scripting, come Perl, e i classici linguaggi orientati agli oggetti, come C++ o Java. È possibile scaricare Python (inclusa l'interfaccia IDLE, per una maggiore comodità d'uso)https://www.python.org e apprendere in modo interattivo, avvalendosi delle funzioni di aiuto disponibili.
LI seguenti programmi presuppongono, ovviamente, che il lettore possieda una certa conoscenza delle nozioni di base del linguaggio. Tali basi possono essere acquisite in modo interattivo consultando, ad esempio, la guida scaricata insieme a Python (pulsanti: Aiuto, quindi Tutorial nell'interfaccia IDLE) oppure, a titolo di esempio, il corso di Python di Thierry Lecroq. .
La seguente scheda di riferimento essenziale potrebbe rivelarsi utile (come riassunto sintetico):Esempio di scheda di riferimento per Python::
Esempio di scheda di riferimento per Python:
Memento_Poznan
Sul Web è disponibile una moltitudine di libri e manuali per imparare Python.
1- 1- Calcolo e stampa di una tabella lessicale (parole X testi)
2- 2- Calcolo e stampa di una concordanza a partire da una serie di testi
Si tratta, in sostanza, di entrare – grazie al linguaggio Python – nella "scatola nera" di una funzionalità comune, presente nella maggior parte dei software statistici per l'analisi dei testi. È evidente che il codice potrebbe essere molto più compatto, ma forse meno leggibile.
Comandi per l'interprete Python (ad esempio IDLE)
#-------------------------------------
import os # modulo os
os.chdir("c:/ADT_py") # nome della cartella contenente il programma e i dati
# nella directory radice "c:/" per questo esempio
chemin = "poem.txt" # nome del file di testo (nella stessa cartella)
import table_lex_E # programmi: table_lex_E.py
# (nella stessa cartella)
from table_lex_E import * # funzioni di importazione
#-------------------------------------
tablex(chemin, 2) # esegue la funzione tablex()
# inclusa nel file: table_lex_E.py
# (con: soglia = 2: valore predefinito della soglia di frequenza).
#-------------------------------------
Il piccolo file di dati di test «poem.txt» è fornito all'interno della cartella ADT_py.
[Testi in formato DtmVic: separatori di testo: “****” (all'inizio della riga) seguiti da 4 spazi e dal titolo del testo.
Fine del testo: “====” (all'inizio della riga)]..
**** LAMARTINE voilà les feuilles sans sève, qui tombent sur le gazon voilà le vent qui s'élève, et gémit dans le vallon voilà l'errante hirondelle, qui rase du bout de l'aile, l'eau dormante des marais... voilà l'enfant des chaumières, qui glane sur la bruyère, le bois tombé des forêts... **** GAUTIER l'automne va finir, au milieu du ciel terne, dans un cercle blafard et livide que cerne un nuage plombe, le soleil dort. du fond des étangs remplis d'eau monte un brouillard qui fond collines, champs, hameaux dans une même teinte. sur les carreaux la pluie en larges gouttes tinte. **** VERLAINE les sanglots longs des violons de l'automne blessent mon coeur d’une langueur monotone. tout suffocant et blême, quand sonne l'heure, je me souviens des jours anciens et je pleure. **** BRUGNOT l'herbe se fane dans les près, les jours de soleil sont passés les feuilles jaunes et pourprées jonchent les sentiers effacés. le voilà donc mon bel automne. **** BAUDELAIRE bientôt nous plongerons dans les froides ténèbres adieu, vive clarté de nos étés trop courts. j'entends déjà tomber avec des chocs funèbres le bois retentissant sur le pavé des cours. =====
Questo mini-corpus ha il solo scopo di verificare il corretto funzionamento del codice. Lo stesso codice genererà la tabella lessicale del corpus "Stato dell'Unione" (State of the Union) (un corpus circa 2000 volte più grande) in pochi secondi (in quest'ultimo caso, è opportuno iniziare con una soglia di frequenza minima di 200 per le parole). La tabella sottostante mostra il contenuto del file "tablexfile.txt" prodotto dalla funzione tablex().
Tabella lessicale che incrocia parole e poesie
LAMARTI GAUTIER VERLAIN BRUGNOT BAUDELA automne 0 1 1 1 0 bois 1 0 0 0 1 d 0 1 1 0 0 dans 1 2 0 1 1 de 1 0 1 1 1 des 3 1 2 0 2 du 1 2 0 0 0 eau 1 1 0 0 0 et 1 1 2 1 0 feuilles 1 0 0 1 0 fond 0 2 0 0 0 je 0 0 2 0 0 jours 0 0 1 1 0 l 4 1 2 1 0 la 1 1 0 0 0 le 4 1 0 1 2 les 1 1 1 4 1 mon 0 0 1 1 0 qui 4 1 0 0 0 soleil 0 1 0 1 0 sur 2 1 0 0 1 un 0 3 0 0 0 une 0 1 1 0 0 voilà 4 0 0 1 0
Comandi per l'interprete Python (ad esempio IDLE)
#-------------------------------------
import os # modulo os
os.chdir("c:/ADT_py") # nome della cartella contenente il programma e i dati
# nella directory radice "c:/" per questo esempio
chemin = " SOTU_40_08.txt " # nome del file di testo (nella stessa cartella)
# (Speech: STATE OF THE UNION of presidents 41 à 44)
import concord_E # file-programma: concord_E.py (stessa cartella)
from concord_E import * # chiamata alle funzioni di concord_E.py
#-------------------------------------
target = “dream” # parola chiave = la parola "dream""
conco (chemin, target) # esegue la funzione conco() inclusa in: concord_E.py
#-------------------------------------
La tabella sottostante rappresenta il contenuto del file "concordance.txt" prodotto dalla funzione conco().Tabella di concordanza [KWIC] per la parola "dream"
**** ----------- 41BUSH 17825 families achieve the dream of home ownership. but make no 17898 your living rooms, hold fast to your dreams because ultimately America's 17942 t century. our nation is the enduring dream of every immigrant 17961 he future we can make for ourselves. but dreams alone won't 18095 uture, every kid is the same: full of dreams, ready to take on the world 18104 on on a new century, your century, on dreams we cannot see, on the destiny 18324 have the bad dreams children once had in decad 18408 real estate. for those Americans who dream of buying a first **** ----------- 42CLINTON 18569 enter it having secured the American dream for ourselves and for future 18620 billion to make the dream of enterprise zones real, we 18897 ation, and a fair shot at the American dream, they will do extraordinary 18904 working, the American dream has been slipping away. in 199 19286 on a mission: to restore the American dream for all our people and to mak 19494 n entrepreneurs are living the American dream. if we want it to stay that 19714 promise of this country, the enduring dream from that first and most-sacr 19734 ions: first, how do we make the American dream of opportunity for all a reali 19768 our individual dreams must be realized by our co 19961 resources, and even dreams. bosnia and we stood up for p 20204 ll cultures. this will no longer be a dream, but a necessity. and over 20672 me here to work for their own American dreams. let's keep our cities going 21129 union of our founders' dreams. we are now, at the end o 21144 he more perfect union of our founders' dreams. 21167 nt, America again has the confidence to dream big dreams. but we must not 21168 complacency. we will be judged by the dreams and deeds we pass on to ou 21231 their test scores. to make the American dream achievable for all, we must ma 21532 we remain a new nation. as long as our dreams outweigh our memories, **** ----------- 43BUSH 21683 d in the way of families achieving their dreams. the surplus is not the 22540 not punish, the efforts and dreams of entrepreneurs. small bu 22769 we live in the country where the biggest dreams are born. 22770 the abolition of slavery was only a dream until it was fulfilled. the 22771 fall of imperial communism was only a dream until, one day, it was accomp 22772 our generation has dreams of its own, and we also go 22776 founding ideals and carried on a noble dream. tonight we are comforted by 22797 dom's cause. far from being a hopeless dream, the advance of freedom 23027 raise their sights and achieve their dreams. a hopeful society comes to t 23196 blood and bodies to put an end to your dreams, and what is coming is even 23397 ountry, there are boys and girls with dreams and a decent education **** ----------- 44OBAMA 23645 you built your dreams upon that’s now hanging by a 23902 he most power or celebrity, but from the dreams and aspirations of 24004 when an entrepreneur takes a chance on a dream, or a worker decides its time 24273 ertain; to do what it took to keep the dream of this nation alive for their 24286 this moment to start anew, to carry the dream forward,