R !!!keyness {{outline}} *複数の文書からなるコーパスがあったとして、 *その中の特定の文書が、ほかの残りと比べて、際立って違う言葉遣いをしていることを探る。 *二種類の文書に対して行うことで、二つの文書の相違を観察できる。 **targetとreference group *符号付き2x2の関連性スコア(association score) quanteda::<> *target で、注目したい文書を指定する。 **数字を入れれば、文書行列中の要素番号 **ほかには、文書行列に、各文書の属性情報をつけて置き、その属性でグループを指定する。 ***例えば、JANとNTVという属性をつけて、JANをターゲットに指定して、残りのNTVをreferenceとして比較する。 *measure = オプションで統計値を選べる。(signed というのは、プラスマイナスの符号を使うから) ** chi2 は、χ二乗 ** exact は、Fisher's exact test ** lr は、likelihood ratio(G2) {{pre nicestJAN.1st <- textstat_keyness(nicestJAN.dfm, 1) nicestJAN.1st feature chi2 p n_target n_reference 1 specialized 3.295107e+01 9.450749e-09 5 0 2 knowledge 1.741756e+01 3.000417e-05 5 3 3 bload 1.656914e+01 4.690807e-05 3 0 4 knowledges 8.652160e+00 3.266739e-03 2 0 5 subject 8.652160e+00 3.266739e-03 2 0 6 walking 8.652160e+00 3.266739e-03 2 0 7 dictionary 8.652160e+00 3.266739e-03 2 0 8 dictionaries 8.652160e+00 3.266739e-03 2 0 9 become 8.652160e+00 3.266739e-03 2 0 10 get 8.090752e+00 4.449170e-03 3 2 11 you 5.415006e+00 1.996438e-02 11 43 12 such 4.849584e+00 2.765279e-02 2 1 13 specific 4.849584e+00 2.765279e-02 2 1 14 does 4.849584e+00 2.765279e-02 2 1 15 something 4.849584e+00 2.765279e-02 2 1 16 better 3.007704e+00 8.286961e-02 2 2 17 to 2.199027e+00 1.380979e-01 11 57 18 one 1.950172e+00 1.625683e-01 2 3 textplot_keyness(nicestJAN.1st) }} {{ref_image keynes1st.png}} !!keynessの分析例:学習者コーパス NICESTのサンプルデータを使って !必要なパッケージ {{pre install.packages("quanteda", dependencies=T) library(quanteda) install.packages("readtext", dependencies=T) library(readtext) }} !データの構成 *NICEST sample files というディレクトリー内に二つのサブディレクトリー **NTV sample 10 **JPN sample 10 *それぞれサンプルエッセイの本文部分のみ、10個ずつ入れてある。 !データの読み込み *まず母語話者データ {{pre setwd("C:/Users/sugiura/.../NICEST sample files") # テキストファイルを読み込む。まずは、L1の母語話者データ nicestNTV.tmp <- readtext("NTV sample 10/*.txt") head(nicestNTV.tmp) ## readtext object consisting of 6 documents and 0 docvars. ## # Description: df[,2] [6 x 2] ## doc_id text ## * ## 1 ENG0002_1P1A.txt "\"There is a\"..." ## 2 ENG0002_2P5A.txt "\"By the yea\"..." ## 3 ENG0002_3P2A.txt "\"The questi\"..." ## 4 ENG0002_4P7A.txt "\"The questi\"..." ## 5 ENG0002_5P6A.txt "\"In the las\"..." ## 6 ENG0002_6P3A.txt "\"The questi\"..." }} !コーパスデータ化する {{pre nicestNTV.corpus <- corpus(nicestNTV.tmp) str(nicestNTV.corpus) ## List of 4 ## $ documents:'data.frame': 10 obs. of 1 variable: ## ..$ texts: chr [1:10] "There is a well known phrase, frequently employed in denigration rather than compliment, which describes a pers"| __truncated__ "By the year 2026, will there be fewer cars in use than there are in 2016?\nThis is a difficult question to answ"| __truncated__ "The question of whether young people enjoy life more than older people do is one fraught with potentially insur"| __truncated__ "The question of whether it is concepts or facts that are more important foci for students is a hot topic for ma"| __truncated__ ... ## $ metadata :List of 2 ## ..$ source : chr "C:/Users/sugiura/Documents/* on x86-64 by sugiura" ## ..$ created: chr "Sun Dec 01 12:04:54 2019" ## $ settings :List of 12 ## ..$ stopwords : NULL ## ..$ collocations : NULL ## ..$ dictionary : NULL ## ..$ valuetype : chr "glob" ## ..$ stem : logi FALSE ## ..$ delimiter_word : chr " " ## ..$ delimiter_sentence : chr ".!?" ## ..$ delimiter_paragraph: chr "\n\n" ## ..$ clean_tolower : logi TRUE ## ..$ clean_remove_digits: logi TRUE ## ..$ clean_remove_punct : logi TRUE ## ..$ units : chr "documents" ## ..- attr(*, "class")= chr [1:2] "settings" "list" ## $ tokens : NULL summary(nicestNTV.corpus) ## Corpus consisting of 10 documents: ## ## Text Types Tokens Sentences ## ENG0002_1P1A.txt 290 717 30 ## ENG0002_2P5A.txt 361 899 28 ## ENG0002_3P2A.txt 388 987 33 ## ENG0002_4P7A.txt 438 1047 38 ## ENG0002_5P6A.txt 415 969 35 ## ENG0002_6P3A.txt 257 697 23 ## ENG0002_7P4A.txt 320 851 55 ## ENG0002_8P8A.txt 260 612 30 ## ENG0003_1P8B.txt 185 456 24 ## ENG0003_2P4B.txt 223 531 22 ## ## Source: C:/Users/sugiura/Documents/* on x86-64 by sugiura ## Created: Sun Dec 01 12:04:54 2019 ## Notes: }} !言語情報を属性として追加する *母語話者データはL1、学習者データはL2 {{pre docvars(nicestNTV.corpus, "lang") <- "L1" summary(nicestNTV.corpus) ## Corpus consisting of 10 documents: ## ## Text Types Tokens Sentences lang ## ENG0002_1P1A.txt 290 717 30 L1 ## ENG0002_2P5A.txt 361 899 28 L1 ## ENG0002_3P2A.txt 388 987 33 L1 ## ENG0002_4P7A.txt 438 1047 38 L1 ## ENG0002_5P6A.txt 415 969 35 L1 ## ENG0002_6P3A.txt 257 697 23 L1 ## ENG0002_7P4A.txt 320 851 55 L1 ## ENG0002_8P8A.txt 260 612 30 L1 ## ENG0003_1P8B.txt 185 456 24 L1 ## ENG0003_2P4B.txt 223 531 22 L1 ## ## Source: C:/Users/sugiura/Documents/* on x86-64 by sugiura ## Created: Sun Dec 01 12:04:54 2019 ## Notes: }} }}