options("kableExtra.html.bsTable" = TRUE) # provides nicer looking tables
if (! "icon" %in% rownames(installed.packages()) ) devtools::install_github("ropenscilabs/icon")
library(kableExtra)

Subcorpora and Partitions {.smaller}

Required installations and initialization {.smaller}

The collection of slides is using the polmineR package and the UNGA corpus. The installation was explained in more detail in an earlier set of slides.

library(polmineR)
use("UNGA")

Please note: The functionalities explained here are only available in polmineR version r as.package_version("0.7.10") or above. Install the correct version of the package accordingly.

For the following examples we additionally use the magrittr package.

library(magrittr)

Creating a partition: Basics {.smaller}

s_attributes("UNGA", s_attribute = "year")
unga_2008 <- partition("UNGA", year = "2008")

Creating a partition: Next Steps {.smaller}

unga_2008 <- partition("UNGA", year = 2008) # identical
unga_2009_ff <- partition("UNGA", year = 2009:2013)

Creating a partition: Next Steps {.smaller}

s_attributes(unga_2008, s_attribute = "role")
unga_2008_min <- partition("UNGA", year = 2008, role = "head of state")

Creating a partition: "Zooming" {.smaller}

a <- partition("UNGA", year = 2008)
b <- partition(a, role = "head of state")
size(unga_2008_min) == size(b)

The partition() method in a Pipe {.smaller}

unga_2008_min <- "UNGA" %>% 
  partition(year = 2008) %>%
  partition(role = "head of state")
"UNGA" %>% partition(year = 2008) %>% count(query = '"financial" "crisis"', cqp = TRUE)

Creating a partition: "Regular Expressions" {.smaller}

uk <- partition("UNGA", state_organization = "United Kingdom", regex = TRUE)
s_attributes(uk, "state_organization")

Scenario: Speeches of United Kingdom Representatives after 2008 {.smaller}

uk_2008_ff <- partition("UNGA", state_organization = "United Kingdom", year = 2008:2009)
for (day in s_attributes(uk_2008_ff, s_attribute = "date")){
  dt <- partition(uk_2008_ff, date = day) %>% count(query = '"financial" "crisis"', cqp = TRUE)
  cat(sprintf("%s -> N Crisis = %s\n", day, dt[["count"]]))
}

Back to the full text: Reading {.smaller}

uk_fcrisis <- partition(uk_2008_ff, date = "2008-09-26")
uk_fcrisis <- partition(uk_2008_ff, date = "2008-09-26")
read(uk_fcrisis)
writeLines(text = as.character(read(uk_fcrisis)), con = "uk_fcrisis.html")

Date specific time slice {.smaller}

pre_nineeleven <- as.Date("2000-09-11")
nineten <- as.Date("2001-09-10")
nineeleven <- as.Date("2001-09-11")
post_nineeleven <- as.Date("2002-09-11")
pre <- partition("UNGA", date = seq.Date(from = pre_nineeleven, to = nineten, by = "day"))
post <- partition("UNGA", date = seq.Date(from = nineeleven, to = post_nineeleven, by = "day"))

count(pre, "terrorism")
count(post, "terrorism")

Creating a partition_bundle {.smaller}

uk_2009 <- partition(uk_2008_ff, year = 2009)
uk_2009_days <- partition_bundle(uk_2009, s_attribute = "date")
summary(uk_2009_days)

Counting based on partition_bundle {.smaller}

count(uk_2009_days, query = c("crisis", "bank", "financial")) %>% show()

With as.speeches() to partition_bundle {.smaller}

Summary and Perspective {.smaller}

References



PolMine/UCSSR documentation built on June 13, 2022, 10:23 p.m.