1-1. 19대 문재인 대통령 취임사
moon <- scan(file.choose(),sep = "\n",what = "char",comment.char = "",quote="")
moon <- SimplePos22(moon)
df_moon <- moon %>% melt %>% as_tibble()
df_moon <- df_moon %>% select(3,1)
df_moon <- df_moon %>%
mutate(noun=str_match(value,"([가-힣]+)/N")[,2])
df_moon <- df_moon %>% na.omit()
df_moon <- df_moon %>% mutate(length=str_length(noun))
df_moon <- df_moon %>% filter(length>=2)
df_moon
## # A tibble: 404 x 4
## L1 value noun length
## <int> <chr> <chr> <int>
## 1 1 존경/NC+하고/JC 존경 2
## 2 1 사랑하/NC+는/JX 사랑하 3
## 3 1 국민/NC 국민 2
## 4 1 여러분/NP 여러분 3
## 5 1 감사/NC+하/XS+ㅂ니다/EF 감사 2
## 6 1 국민/NC 국민 2
## 7 1 여러분/NP+의/JC 여러분 3
## 8 1 위대한/NC 위대한 3
## 9 1 선택/NC+에/JC 선택 2
## 10 1 머리/NC 머리 2
## # ... with 394 more rows
1-2. 18대 박근혜 대통령 취임사
park <- scan(file.choose(),sep = "\n",what = "char",comment.char = "",quote="")
park <- SimplePos22(park)
df_park <- park %>% melt %>% as_tibble()
df_park <- df_park %>% select(3,1)
df_park <- df_park %>%
mutate(noun=str_match(value,"([가-힣]+)/N")[,2])
df_park <- df_park %>% na.omit()
df_park <- df_park %>% mutate(length=str_length(noun))
df_park <- df_park %>% filter(length>=2)
df_park
## # A tibble: 696 x 4
## L1 value noun length
## <int> <chr> <chr> <int>
## 1 1 희망/NC+의/JC 희망 2
## 2 1 시대/NC+를/JC 시대 2
## 3 1 열겠습니/NC 열겠습니 4
## 4 2 존경하/NC+는/JX 존경하 3
## 5 2 국민여러분/NC 국민여러분 5
## 6 3 해외동포/NC 해외동포 4
## 7 3 여러분/NP 여러분 3
## 8 4 오늘/NC 오늘 2
## 9 4 대한민국/NC+의/JC 대한민국 4
## 10 4 대통령/NC+에/JC 대통령 3
## # ... with 686 more rows
1-3. 17대 이명박 대통령 취임사
lee <- scan(file.choose(),sep = "\n",what = "char",comment.char = "",quote="")
lee <- SimplePos22(lee)
df_lee <- lee %>% melt %>% as_tibble()
df_lee <- df_lee %>% select(3,1)
df_lee <- df_lee %>%
mutate(noun=str_match(value,"([가-힣]+)/N")[,2])
df_lee <- df_lee %>% na.omit()
df_lee <- df_lee %>% mutate(length=str_length(noun))
df_lee <- df_lee %>% filter(length>=2)
1-4. 16대 노무현 대통령 취임사
noh <- read_lines("e:/R_Project/노무현.txt")
noh <- extractNoun(noh)
noh <- unlist(noh)
df_noh <- noh %>% melt %>% as_tibble()
df_noh <- df_noh %>% mutate(length=str_length(value))
df_noh <- df_noh %>% filter(length>=2)
df_noh <- rename(df_noh,noun=value)
1-5. 15대 김대중 대통령 취임사
kim <- scan(file.choose(),sep = "\n",what = "char",comment.char = "",quote="")
kim <- SimplePos22(kim)
df_kim <- kim %>% melt %>% as_tibble()
df_kim <- df_kim %>% select(3,1)
df_kim <- df_kim %>%
mutate(noun=str_match(value,"([가-힣]+)/N")[,2])
df_kim <- df_kim %>% na.omit()
df_kim <- df_kim %>% mutate(length=str_length(noun))
df_kim <- df_kim %>% filter(length>=2)
1-6. 14대 김영삼 대통령 취임사
kimy <- scan(file.choose(),sep = "\n",what = "char",comment.char = "",quote="")
kimy <- SimplePos22(kimy)
df_kimy <- kimy %>% melt %>% as_tibble()
df_kimy <- df_kimy %>% select(3,1)
df_kimy <- df_kimy %>%
mutate(noun=str_match(value,"([가-힣]+)/N")[,2])
df_kimy <- df_kimy %>% na.omit()
df_kimy <- df_kimy %>% mutate(length=str_length(noun))
df_kimy <- df_kimy %>% filter(length>=2)
1-7. 13대 노태우 대통령 취임사
noht <- scan(file.choose(),sep = "\n",what = "char",comment.char = "",quote="")
noht <- extractNoun(noht)
noht <- unlist(noht)
df_noht <- noht %>% melt %>% as_tibble()
df_noht <- df_noht %>% mutate(length=str_length(value))
df_noht <- df_noht %>% filter(length>=2)
df_noht <- rename(df_noht,noun=value)
1-8. 11~12대 전두환 대통령 취임사
jeon <- scan(file.choose(),sep = "\n",what = "char",comment.char = "",quote="")
jeon <- extractNoun(jeon)
## Warning in value[[3L]](cond): can't processing '북한주민은 지난 36년간 내부의 종
## 적인 비교만 할 수 있었을 뿐 외부세계와의 횡적인 비교는 할 수 없는 처지에 놓여 있
## 었읍니다. 그들은 최소한의 자유도 맛볼 수 없는 상황에 놓여 있기 때문에 자유를 갈
## 구조차도 못하는, 인간의 존엄성과 가능성이 완전히 박탈된 비극적인 생활을 하고 있
## 읍니다. 즉 정치,경제,사회,문화,인도적인 측면에서 북한주민의 생활의 질은 전세계
## 에서 유례를 찾아보기 어려운 참담한 것으로서 동족인 우리들로서는 이에 대한 무한한
## 동정을 금할 수 없읍니다.'.
jeon <- unlist(jeon)
df_jeon <- jeon %>% melt %>% as_tibble()
df_jeon <- df_jeon %>% mutate(length=str_length(value))
df_jeon <- df_jeon %>% filter(length>=2)
df_jeon <- rename(df_jeon,noun=value)
1-9. 10대 최규하 대통령 취임사
choi <- scan(file.choose(),sep = "\n",what = "char",comment.char = "",quote="")
choi <- SimplePos22(choi)
df_choi <- choi %>% melt %>% as_tibble()
df_choi <- df_choi %>% select(3,1)
df_choi <- df_choi %>%
mutate(noun=str_match(value,"([가-힣]+)/N")[,2])
df_choi <- df_choi %>% na.omit()
df_choi <- df_choi %>% mutate(length=str_length(noun))
df_choi <- df_choi %>% filter(length>=2)
1-10. 5~9대 박정희 대통령 취임사
parkg2 <- scan(file.choose(),sep = "\n",what = "char",comment.char = "",quote="")
parkg2 <- extractNoun(parkg2)
parkg2 <- unlist(parkg2)
df_parkg2 <- parkg2 %>% melt %>% as_tibble()
df_parkg2 <- df_parkg2 %>% mutate(length=str_length(value))
df_parkg2 <- df_parkg2 %>% filter(length>=2)
df_parkg2 <- rename(df_parkg2,noun=value)
1-11. 4대 윤보선 대통령 취임사
yun <- scan(file.choose(),sep = "\n",what = "char",comment.char = "",quote="")
yun <- SimplePos22(yun)
df_yun <- yun %>% melt %>% as_tibble()
df_yun <- df_yun %>% select(3,1)
df_yun <- df_yun %>%
mutate(noun=str_match(value,"([가-힣]+)/N")[,2])
df_yun <- df_yun %>% na.omit()
df_yun <- df_yun %>% mutate(length=str_length(noun))
df_yun <- df_yun %>% filter(length>=2)
1-12. 1~3대 이승만 대통령 취임사
lees <- scan(file.choose(),sep = "\n",what = "char",comment.char = "",quote="")
lees <- SimplePos22(lees)
df_lees <- lees %>% melt %>% as_tibble()
df_lees <- df_lees %>%
mutate(noun=str_match(value,"([가-힣]+)/N")[,2])
df_lees <- df_lees %>% na.omit()
df_lees <- df_lees %>% mutate(length=str_length(noun))
df_lees <- df_lees %>% filter(length>=2)
Data 1. 한국 국민선거 이후 역대 대통령 취임사 단어 분포
df_after <- c(df_park$noun,df_moon$noun,df_lee$noun,df_noh$noun,df_kim$noun,df_kimy$noun,df_noht$noun)
df_after <- df_after[!(df_after %in% c("우리","국민","여러분"))]
df_after2 <- sort(table(df_after),decreasing = T)[1:30]
df_after2 <- df_after2 %>% as_tibble() %>% rename(value=n)
df_after2
## # A tibble: 30 x 2
## df_after value
## <chr> <int>
## 1 정부 60
## 2 대통령 59
## 3 사회 59
## 4 시대 57
## 5 세계 55
## 6 나라 46
## 7 대한민국 44
## 8 오늘 41
## 9 사람 40
## 10 경제 38
## # ... with 20 more rows
데이터에 가장 많이 공통적으로 나온 단어인 {우리,국민,여러분}은 통계에서 제외.
Data 2. 한국 국민선거 이전 역대 대통령 취임사 단어 분포
df_before <- c(df_jeon$noun,df_yun$noun,df_parkg2$noun,df_lees$noun,df_choi$noun)
df_before <- df_before[!(df_before %in% c("우리","국민","여러분"))]
df_before2 <- sort(table(df_before),decreasing = T)[1:30]
df_before2 <- df_before2 %>% as_tibble()
df_before2
## # A tibble: 30 x 2
## df_before n
## <chr> <int>
## 1 민족 66
## 2 역사 65
## 3 본인 61
## 4 사회 60
## 5 정부 48
## 6 오늘 46
## 7 조국 46
## 8 발전 42
## 9 평화 40
## 10 시대 39
## # ... with 20 more rows
데이터에 가장 많이 공통적으로 나온 단어인 {우리,국민,여러분}은 통계에서 제외.
1-1.Data 1 ggplot.
ggplot(df_after2,aes(x=reorder(df_after,value),y=value)) +
geom_bar(stat="identity") +
theme(axis.text.x = element_text(angle = 90)) +
coord_flip() +
labs(x="",y="",title = "국민 선거 이후 대통령 취임사 단어 분포") +
theme(plot.title=element_text(size=18)) +
geom_bar(data=df_after2[df_after2$df_after %in% df_before2$df_before,],aes(x=df_after,y=value),fill="gray",stat="identity") +
geom_text(aes(label=value),size=3,hjust=1.25,color="white")
1-2. Data 2
ggplot(df_before2,aes(x=reorder(df_before,n),y=n)) +
geom_bar(stat="identity") +
theme(axis.text.x = element_text(angle = 90)) +
coord_flip() +
labs(x="",y="",title = "국민 선거 이전 대통령 취임사 단어 분포") +
theme(plot.title=element_text(size=18)) +
geom_bar(data=df_before2[df_before2$df_before %in% df_after2$df_after,],aes(x=df_before,y=n),fill="gray",stat="identity") +
geom_text(aes(label=n),size=3,hjust=1.25,color="white")
Top30 단어에서 Data 1과 Data 2의 중복되는 단어를 회색으로 나타내어 선거 이후와 이전 시대 상의 표현 분포에 대해 알 수 있음. 중복되지 않은 단어로 Data 1에서는 “대한민국”이라는 나라명을 자주 사용했으며 “문화”라는 단어를 사용함. 이는 과거에 비해 경제가 안정화되고 난 후 문화 산업에 투자하는 과정으로 판단됨. Data 2에서는 Data 1과 다르게 나라명보다 “조국”이라는 단어를 사용하였고 대통령 자신을 “본인”이라고 자주 표현함. 그러나 군사 정권 시기가 있었던 한국의 역사의 특성과 다르게 “민주주의”, “자유”라는 단어의 분포가 많아 더 상세히 구분할 필요가 있다고 판단됨.
Data 3
df_mil <- c(df_jeon$noun,df_parkg2$noun)
df_mil <- df_mil[!(df_mil %in% c("우리","국민","여러분"))]
df_mil <- sort(table(df_mil),decreasing = T)[1:30]
df_mil <- df_mil %>% as_tibble()
df_mil
## # A tibble: 30 x 2
## df_mil n
## <chr> <int>
## 1 민족 59
## 2 역사 56
## 3 사회 55
## 4 본인 44
## 5 조국 44
## 6 시대 37
## 7 정치 36
## 8 평화 35
## 9 발전 34
## 10 오늘 34
## # ... with 20 more rows
ggplot(df_mil,aes(x=reorder(df_mil,n),y=n)) +
geom_bar(stat="identity") +
theme(axis.text.x = element_text(angle = 90)) +
coord_flip() +
labs(x="",y="",title = "군사정권 대통령 취임사 단어 분포") +
theme(plot.title=element_text(size=18)) +
geom_bar(data=df_mil[df_mil$df_mil %in% df_before2$df_before,],aes(x=df_mil,y=n),fill="gray",stat="identity") +
geom_text(aes(label=n),size=3,hjust=1.25,color="white")
Data 2와 Data3의 중복되는 부분은 회색으로 표현함. Data 2와 Data 3의 단어가 대부분 일치하는 것으로 보아 이는 군사 정권의 특성 상, 동일 인물의 여러번의 취임사로 인한 것이라 판단됨. 이를 확인하기 위해 군사 정권을 통해 취임한 대통령을 제외하고 다시 데이터를 분류함.
Data 4
df_mil2 <- c(df_choi$noun,df_lees$noun,df_yun$noun)
df_mil2 <- df_mil2[!(df_mil2 %in% c("우리","국민","여러분"))]
df_mil2 <- sort(table(df_mil2),decreasing = T)[1:30]
df_mil2 <- df_mil2 %>% as_tibble()
df_mil2
## # A tibble: 30 x 2
## df_mil2 n
## <chr> <int>
## 1 정부 19
## 2 사람 18
## 3 자유 18
## 4 문제 17
## 5 본인 17
## 6 나라 16
## 7 세계 16
## 8 우리나라 16
## 9 경제 13
## 10 국가 13
## # ... with 20 more rows
ggplot(df_mil2,aes(x=reorder(df_mil2,n),y=n)) +
geom_bar(stat="identity") +
theme(axis.text.x = element_text(angle = 90)) +
coord_flip() +
labs(x="",y="",title = "이승만, 윤보선, 최규하 대통령 취임사 단어 분포") +
theme(plot.title=element_text(size=18)) +
geom_bar(data=df_mil2[df_mil2$df_mil2 %in% df_mil$df_mil,],aes(x=df_mil2,y=n),fill="gray",stat="identity") +
geom_text(aes(label=n),size=3,hjust=1.25,color="white")
Data 3과 Data 4의 중복되는 부분은 회색으로 표현함. Data 3과 Data 4를 비교하면, 앞서 Data2에서 시대 상의 특성과 다르게 많이 나타났던 “자유”라는 단어는 군사 정권이 아닌 시대에 쓰였던 것을 알 수 있음. 또한, 일제 시대 해방 이후의 정부라는 시대의 특성과 맞는 단어인 “전쟁”,“안정”,“국회” 등의 단어가 자주 사용된 것을 확인 할 수 있음. 시대 상 특성 단어는 다음 분석에서 확인할 것임.
df_1 <- df_lees$noun[!(df_lees$noun %in% df_moon$noun)]
df_1 <- df_1 %>% melt %>% as_tibble()
df_1 <- df_1 %>% mutate(length=str_length(value))
df_1 <- df_1 %>% filter(length>=2) %>% count(value,sort=T)
df_1 <- head(df_1,100)
wordcloud2(df_1,size=0.4)
이승만 대통령의 단어 분포에서 문재인 대통령과 중복되는 단어를 제외한 나머지 단어를 wordcloud로 표현함. 전쟁과 관련된 단어인 이북,파괴,생명,일본,자유세계,공산당,원수들 등 적대적인 분위기를 알 수 있음. 또한, 국가 안정을 위한 단어로 직책,정신,복리,국회의원,생산력,농민 등을 확인 할 수 있음. 이렇게 취임사를 통해서 그 시대상의 중점 요소나 분위기를 엿볼 수 있음.
# 문재인 대통령
corpus_moon <- Corpus(VectorSource(df_moon$noun))
corpus_moon2 <- DocumentTermMatrix(corpus_moon)
moon_tokens <- sum(as.matrix(corpus_moon2))
moon_tokens # token 개수 구하기
## [1] 404
moon_types <- length(corpus_moon2$dimnames$Terms)
moon_types #type 개수 구하기
## [1] 252
m <- moon_types/moon_tokens #type-token ratio
m
## [1] 0.6237624
이런 방식으로 각 대통령의 사용 단어 전체의 type-token ratio를 구할 수 있음.
# 박근혜 대통령
corpus_park <- Corpus(VectorSource(df_park$noun))
corpus_park2 <- DocumentTermMatrix(corpus_park)
park_tokens <- sum(as.matrix(corpus_park2))
park_types <- length(corpus_park2$dimnames$Terms)
p <- park_types/park_tokens
p
## [1] 0.5488506
# 이명박 대통령
corpus_lee <- Corpus(VectorSource(df_lee$noun))
corpus_lee2 <- DocumentTermMatrix(corpus_lee)
lee_tokens <- sum(as.matrix(corpus_lee2))
lee_types <- length(corpus_lee2$dimnames$Terms)
l <- lee_types/lee_tokens
l
## [1] 0.6177007
# 노무현 대통령
corpus_noh <- Corpus(VectorSource(df_noh$noun))
corpus_noh2 <- DocumentTermMatrix(corpus_noh)
noh_tokens <- sum(as.matrix(corpus_noh2))
noh_types <- length(corpus_noh2$dimnames$Terms)
n <- noh_types/noh_tokens
n
## [1] 0.5511509
# 김대중 대통령
corpus_kim <- Corpus(VectorSource(df_kim$noun))
corpus_kim2 <- DocumentTermMatrix(corpus_kim)
kim_tokens <- sum(as.matrix(corpus_kim2))
kim_types <- length(corpus_kim2$dimnames$Terms)
k <- kim_types/kim_tokens
k
## [1] 0.6182397
# 김영삼 대통령
corpus_kimy <- Corpus(VectorSource(df_kimy$noun))
corpus_kimy2 <- DocumentTermMatrix(corpus_kimy)
kimy_tokens <- sum(as.matrix(corpus_kimy2))
kimy_types <- length(corpus_kimy2$dimnames$Terms)
k2 <- kimy_types/kimy_tokens
k2
## [1] 0.5750422
# 노태우 대통령
corpus_noht <- Corpus(VectorSource(df_noht$noun))
corpus_noht2 <- DocumentTermMatrix(corpus_noht)
noht_tokens <- sum(as.matrix(corpus_noht2))
noht_types <- length(corpus_noht2$dimnames$Terms)
n2 <- noht_types/noht_tokens
n2
## [1] 0.5645514
# 전두환 대통령
corpus_jeon <- Corpus(VectorSource(df_jeon$noun))
corpus_jeon2 <- DocumentTermMatrix(corpus_jeon)
jeon_tokens <- sum(as.matrix(corpus_jeon2))
jeon_types <- length(corpus_jeon2$dimnames$Terms)
j <- jeon_types/jeon_tokens
j
## [1] 0.4810427
# 최규하 대통령
corpus_choi <- Corpus(VectorSource(df_choi$noun))
corpus_choi2 <- DocumentTermMatrix(corpus_choi)
choi_tokens <- sum(as.matrix(corpus_choi2))
choi_types <- length(corpus_choi2$dimnames$Terms)
c <- choi_types/choi_tokens
c
## [1] 0.6707946
# 박정희 대통령
corpus_parkg2 <- Corpus(VectorSource(df_parkg2$noun))
corpus_parkg22 <- DocumentTermMatrix(corpus_parkg2)
parkg2_tokens <- sum(as.matrix(corpus_parkg22))
parkg2_types <- length(corpus_parkg22$dimnames$Terms)
p2 <- parkg2_types/parkg2_tokens
p2
## [1] 0.4060403
# 윤보선 대통령
corpus_yun <- Corpus(VectorSource(df_yun$noun))
corpus_yun2 <- DocumentTermMatrix(corpus_yun)
yun_tokens <- sum(as.matrix(corpus_yun2))
yun_types <- length(corpus_yun2$dimnames$Terms)
y <- yun_types/yun_tokens
y
## [1] 0.7941176
# 이승만 대통령
corpus_lees <- Corpus(VectorSource(df_lees$noun))
corpus_lees2 <- DocumentTermMatrix(corpus_lees)
lees_tokens <- sum(as.matrix(corpus_lees2))
lees_types <- length(corpus_lees2$dimnames$Terms)
l2 <- lees_types/lees_tokens
l2
## [1] 0.5441576
# TTR 한눈에 보기
name <- c("1.문","2.박","3.이","4.노","5.김","6.김영","7.노","8.전","9.0최","9.1박정","9.2윤","9.3.이승")
figure <- round(c(m,p,l,n,k,k2,n2,j,c,p2,y,l2),2)
graph <- as.data.frame(cbind(name,figure))
ggplot(data=graph,aes(x=name,y=figure)) + geom_col()
이름 옆에 숫자는 한글이 글자순대로 자동정렬되서 순서대로 정렬하기 위해 붙인 것이므로 특별한 의미는 없음. Type-Token Ratio가 가장 높은 즉, 가장 많은 단어를 사용한 대통령은 0.79인 윤보선 대통령이며 가장 적은 단어를 사용한 대통령은 0.41로 박정희 대통령임을 알 수 있음.