maggio 2019
All' ombra de' cipressi e dentro l' urne Confortate di pianto è forse il sonno Della morte men duro? Ove più il Sole Per me alla terra non fecondi questa Bella d' erbe famiglia e d' animali, E quando vaghe di lusinghe innanzi A me non danzeran l' ore future, Né da te, dolce amico, udrò più il verso E la mesta armonia che lo governa, Né più nel cor mi parlerà lo spirto Delle vergini Muse e dell' Amore, Unico spirto a mia vita raminga, Qual fia ristoro a' dì perduti un sasso Che distingua le mie dalle infinite
Il corpus consta di un testo, segmentato in 56 frammenti, corrispondenti alle frasi (divise da segni di interpunzione forti).
sepolcri.txt.1 "All' ombra de' cipressi e dentro l' urne Confortate di pianto è forse il sonno Della morte men duro?" sepolcri.txt.2 "Ove più il Sole Per me alla terra non fecondi questa Bella d' erbe famiglia e d' animali, E quando vaghe di lusinghe innanzi A me non danzeran l' ore future, Né da te, dolce amico, udrò più il verso E la mesta armonia che lo governa, Né più nel cor mi parlerà lo spirto Delle vergini Muse e dell' Amore, Unico spirto a mia vita raminga, Qual fia ristoro a' dì perduti un sasso Che distingua le mie dalle infinite Ossa che in terra e in mar semina morte?"
Il corpus consiste di
# testo originario e il l di le a che la i d 124 49 48 43 41 38 36 35 28 26
# testo normalizzato fare tomba urna terra vedere sotto ombra pianto forse morte 9 7 6 6 6 6 5 5 5 5
Più probabile = meno informativa
immagine di Sander Lestrade et al.. Unzipping Zipf’s law. PLOS ONE (2017). DOI: 10.1371/journal.pone.0181987
sepolcri.txt.1 "ombra cipressi dentro urne confortate pianto forse sonno morte men duro"
pronomi personali …
lemmi (+ tag grammaticale)
ombra cipresso dentro urna confortare pianto forse sonno morte meno duro
ombra cipress dentr urna confort piant fors sonn mort men dur
Nei testi brevi, come quelli di Twitter, l’unità di contesto è il testo stesso.
# importo il testo library(readtext) sepolcri <- readtext("sepolcri.txt") # creo il corpus library(quanteda) sep.corpus <- corpus(sepolcri)
# segmentazione (eventuale) secorpus <- corpus_reshape(sep.corpus, to = "sentences") # tokenizzazione septoks <- tokens(secorpus, remove_numbers = TRUE, remove_punct = TRUE)
“I Sepolcri”: 35 lemmi più ricorrenti
“I Promessi sposi”: social network analysis (Cross Library, 2012)
“Forum diabete”: two-mode network temi-attori (Vardanega e Vardanega, 2015)
indice giornaliero, con grandi fluttuazioni
i dati devono essere conservati
Vedi: https://developer.twitter.com
library(rtweet) # autorizzazione (log-in) t_oauth <- create_token(app = "miapp", consumer_key = "xxxxxxxxxxxxxxxxxxxx", consumer_secret = "xxxxxxxxxxxxxxxxxxxx") tw.df <- search_tweets("#rstats", n = 5)
names(tw.df)
[1] "user_id" "status_id" "created_at" [4] "screen_name" "text" "source" [7] "display_text_width" "reply_to_status_id" "reply_to_user_id" [10] "reply_to_screen_name" "is_quote" "is_retweet" [13] "favorite_count" "retweet_count" "hashtags" [16] "symbols" "urls_url" "urls_t.co" [19] "urls_expanded_url" "media_url" "media_t.co" [22] "media_expanded_url" "media_type" "ext_media_url" [25] "ext_media_t.co" "ext_media_expanded_url" "ext_media_type" [28] "mentions_user_id" "mentions_screen_name" "lang" [31] "quoted_status_id" "quoted_text" "quoted_created_at" [34] "quoted_source" "quoted_favorite_count" "quoted_retweet_count" [37] "quoted_user_id" "quoted_screen_name" "quoted_name" [40] "quoted_followers_count" "quoted_friends_count" "quoted_statuses_count" [43] "quoted_location" "quoted_description" "quoted_verified" [46] "retweet_status_id" "retweet_text" "retweet_created_at" [49] "retweet_source" "retweet_favorite_count" "retweet_retweet_count" [52] "retweet_user_id" "retweet_screen_name" "retweet_name" [55] "retweet_followers_count" "retweet_friends_count" "retweet_statuses_count" [58] "retweet_location" "retweet_description" "retweet_verified" [61] "place_url" "place_name" "place_full_name" [64] "place_type" "country" "country_code" [67] "geo_coords" "coords_coords" "bbox_coords" [70] "status_url" "name" "location" [73] "description" "url" "protected" [76] "followers_count" "friends_count" "listed_count" [79] "statuses_count" "favourites_count" "account_created_at" [82] "verified" "profile_url" "profile_expanded_url" [85] "account_lang" "profile_banner_url" "profile_background_url" [88] "profile_image_url"
tw.df$text
[1] "Getting prepared for #rstats @uRosconf!\nSee you on monday in Bucharest! https://t.co/XfYiCbKv4U" [2] "this, when you feed iris and mtcars in the bath after midnight . or you know just arrive at work on Monday. #rstats via @rstatsmemes FB https://t.co/PzqXSJo7TK" [3] "Hi #rstats #brasil, next week I'll be giving a talk and a mini course on highcharter at IV SER :) ser you there https://t.co/lTKQ34B2lp https://t.co/WdVZU2767y" [4] "\U0001f4d5 #Rbook: R, Databases, and Docker\nBy John David Smith, Sophie Yang, M. Edward (Ed) Borasky, Jim Tyhurst, Scott Came, Mary Anne Thygesen, and Ian Frantz\n#rstats #Rdatabase #dplyr #SQL #havefun\nhttps://t.co/PWWJTovQGK" [5] "New tutorial paper with @cedricbatailler and @paulbuerkner : An introduction to Bayesian multilevel models using #brms #Rstats \n\n https://t.co/oP8IndqrTN\n\nAs always, preprint on @PsyArXiv, code and supplementary materials are available on OSF: https://t.co/xvlHqetS1b"
library(tokenizers) stop <- stopwords::stopwords(language = "en", source = "snowball") tokenize_tweets(tw.df$text[c(1,4)], strip_url = T, stopwords = stop)
## [[1]] ## [1] "getting" "prepared" "#rstats" "@uRosconf" "see" "monday" ## [7] "bucharest" ## ## [[2]] ## [1] "<U+0001F4D5>" "#Rbook" "r" "databases" "docker" ## [6] "john" "david" "smith" "sophie" "yang" ## [11] "m" "edward" "ed" "borasky" "jim" ## [16] "tyhurst" "scott" "came" "mary" "anne" ## [21] "thygesen" "ian" "frantz" "#rstats" "#Rdatabase" ## [26] "#dplyr" "#SQL" "#havefun"
“We perform standard NLP pre-processing steps: (i) convert to lowercase, (ii) tokenize running text into words, (iii) apply basic orthographic repairs, (iv) remove URLs, (v) remove non-alphabetic characters (e.g. ‘#’ or ‘@’), (vi) remove stop words, (vi) if needed, stem words to get rid of inflected forms”
(Diego Zardetto, Istat)
Il problema è trovare/costruire/correggere un dizionario.
validazione dei risultati mediante analisi degli outliers
Slides di Diego Zardetto: https://www.istat.it/it/files//2018/07/SME_13ConfNazStat.pptx