data <- final_tibble |>mutate(author =str_extract(work, "^(.*)\\.\\s"), # Всё до последней точкиauthor =str_remove(author, "\\s$"), # Удаляю лишний пробел в концеtitle =str_extract(work, "(?<=\\.\\s).*") # Всё после последней точки ) |>select(-work)
Downloading udpipe model from https://raw.githubusercontent.com/jwijffels/udpipe.models.ud.2.5/master/inst/udpipe-ud-2.5-191206/russian-gsd-ud-2.5-191206.udpipe to /Users/karinachadaeva/Desktop/HSE/1 year/text analysis/homework/hw9/russian-gsd-ud-2.5-191206.udpipe
- This model has been trained on version 2.5 of data from https://universaldependencies.org
- The model is distributed under the CC-BY-SA-NC license: https://creativecommons.org/licenses/by-nc-sa/4.0
- Visit https://github.com/jwijffels/udpipe.models.ud.2.5 for model license details.
- For a list of all models and their licenses (most models you can download with this package have either a CC-BY-SA or a CC-BY-SA-NC license) read the documentation at ?udpipe_download_model. For building your own models: visit the documentation by typing vignette('udpipe-train', package = 'udpipe')
Downloading finished, model stored at '/Users/karinachadaeva/Desktop/HSE/1 year/text analysis/homework/hw9/russian-gsd-ud-2.5-191206.udpipe'
Я хочу посчитать, какие части речи чаще используются в названиях научных статей и построить соответствующий график
counts <- works_pos |>group_by(upos) |>count() |>arrange(-n)library(ggplot2)counts |>ggplot(aes(x =reorder(upos, -n), y = n, fill = n)) +geom_bar(stat ="identity", show.legend =TRUE) +scale_fill_gradient(low ="lightblue", high ="darkblue") +labs(x ="Часть речи", y ="Количество", title ="Распределение частей речи") +theme_minimal() +theme(axis.text.x =element_text(angle =45, hjust =1))
Как и ожидалось, преобладают имена существительные, имена собственные и имена прилагательные. И в самом деле, даже вместо глаголов в названии научных статей предпочитают использовать отглагольные имена существительные.
Какие имена собственные чаще встречаются в названиях статей?
Отберу самые частотные имена собственные
propns <- works_pos |>filter(upos %in%c("PROPN")) |>count(lemma) |>arrange(-n)# пришлось использовать регулярные выражения, чтобы убрать из вывода одиночные буквы и инициалыpropns_clean <- propns |>filter(!grepl("\\.", lemma) &nchar(lemma) >2)propns_clean
Теперь я хочу узнать, есть ли зависимость длины названия статьи от года публикации
data <- data |>mutate(title_length =str_length(title))average_title_length <- data |>group_by(year) %>%summarise(mean_title_length =mean(title_length, na.rm =TRUE))average_title_length |>ggplot(aes(x = year, y = mean_title_length)) +geom_line(color ="lightblue", linewidth =1) +geom_point(color ="tomato", linewidth =2) +labs(title ="Зависимость средней длины названия статьи от года",x ="Год",y ="Средняя длина названия статьи" ) +theme_minimal()
Видимо, с 2016 по 2018 и с 2021 по 2022 гг. считали, что “краткость - сестра таланта”(Chekhov 1889).
Токенизация и стоп-слова
library(tidytext)library(stopwords)stop_words <-tibble(word =stopwords("ru"))words <- data |>unnest_tokens(word, title)words_tidy <- words |>anti_join(stop_words) |>filter(!str_detect(word, "\\."), nchar(word) >2)
Joining with `by = join_by(word)`
words_tidy
Абсолютная частотность
words_tidy |>count(word, sort =TRUE) |>slice_head(n =15) |>ggplot(aes(reorder(word, n), n, fill = n)) +geom_col(show.legend =FALSE) +scale_fill_gradient(low ="lightblue", high ="blue") +coord_flip() +labs(title ="Топ-15 слов в датасете",x ="Слово",y ="Частота" ) +theme_minimal()
Интересно, что в такой набор базовых филологических терминов попал Гоголь. Мы видим, что на график попали формы слов. Чтобы этого избежать, я возьму токенизированный ранее датасет, в котором есть колонка “леммы”.
words2 |>count(word, sort =TRUE) |>slice_head(n =20) |>ggplot(aes(reorder(word, n), n, fill = n)) +geom_col(show.legend =FALSE) +scale_fill_gradient(low ="lightblue", high ="blue") +coord_flip() +labs(title ="Топ-20 слов в датасете",x ="Слово",y ="Частота" ) +theme_minimal()
Получилось более репрезентативно. Доминируют базовые филологические термины (язык, литература, роман, перевод, произведение и т. п.), некоторые имена собственные (Москва, Гоголь)
использованная литература
Chekhov, Anton. 1889. Краткость — сестра таланта. Moscow: SomePublisher.