Skip to content

Commit b837cfd

Browse files
authored
Merge pull request #176 from enerammer/main
Rimelig færdig med frekvensanalyse
2 parents bd104db + 1ff0337 commit b837cfd

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

episodes/frequency-analysis.Rmd

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,28 +126,40 @@ articles_filtered |>
126126
127127
```
128128

129-
<!-- The analyses just made can easily be adjusted. For instance, if we want look at the words by `pillar_name` instead of by `president`, we simply replace `president` with `pillar_name` in the code.
129+
<!-- The analyses just made can easily be adjusted. For instance, if we want look at the words by `pillar_name` instead of by `president`, we simply replace `president` with `pillar_name` in the code. -->
130130

131-
```{r vis_per_pillar}
132-
articles_filtered |>
131+
<!-- ```{r vis_per_pillar} -->
132+
<!-- articles_filtered |>
133133
count(date, word, sort = TRUE) |>
134134
group_by(date) |>
135135
slice(1:10) |>
136136
ggplot(mapping = aes(x = n, y = word, colour = date, shape = date)) +
137-
geom_point()
138-
``` -->
137+
geom_point() -->
138+
<!-- ``` -->
139+
140+
141+
Interesting that numbers occurs in the Sports section. Lets have a look at where it occurs. In order to do so we have to go back to our original object `articles` where we have the full text of articles. It would be nice to see the context in wich for instance 1 occurs.
139142

140-
Interesting that numbers occurs in the Sports section. Lets have a look at where it occurs. In order to do so we have to go back to our original object `articles` where we have the full text of articles.
143+
In order to do this we need to use a `package` named `quanteda`, so lets install the package, and load it in to memory.
141144

145+
```{r, eval = FALSE}
146+
install.packages("quanteda")
147+
library(quanteda)
148+
```
149+
150+
In order to get the context we will use the function `kwic`
142151
```{r}
143152
articles |>
144153
filter(section == "Sport") |>
145-
filter(str_detect(text, "\\b1\\b")) |>
146-
select(text) |>
147-
head()
154+
# filter(str_detect(text, "\\b1\\b")) |>
155+
# slice(1) |>
156+
pull(text) |>
157+
tokens() |>
158+
kwic(pattern = "1", window = 10)
159+
148160
```
149161

150-
<!-- SNAK MED CHRISTIAN ANG at få ordet i kontekst, så 10 ord før og 10 ord efter -->
162+
So what we are doing is looking for at keyword in context, and that is exactly what the function `kwic` does. It locates the string we write in the argument `pattern` and takes the amout of words before and after the keyword given in the argument `window`.
151163

152164

153165

episodes/getting-ready.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ knitr::opts_chunk$set(echo = TRUE)
3030
## Getting started
3131
When performing text analysis in R, the built-in functions in R are not sufficient. It is therefore necessary to install some additional packages. In this course we will be using the packages `tidyverse` and `tidytext`.
3232

33-
```{r library, include = FALSE, message = F, warning = F}
33+
```{r library, include = FALSE, message = FALSE, warning = FALSE}
3434
library(tidyverse)
3535
library(tidytext)
3636
library(tm)

episodes/sentiment.Rmd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ knitr::opts_chunk$set(warning = FALSE)
2929
library(tidyverse)
3030
library(tidytext)
3131
library(tm)
32+
library(textdata)
3233
3334
articles_filtered <- read_csv("data/articles_filtered.csv", na = c("NA", "NULL", ""))
3435
articles <- read_csv("data/guardianArticles.csv", na = c("NA", "NULL", ""))
@@ -136,7 +137,7 @@ library(textdata)
136137

137138
In order to use the `AFINN`-lexicon, we have to save it.
138139

139-
```{r get_sentiment_afinn, eval = FALSE}
140+
```{r get_sentiment_afinn}
140141
afinn <- get_sentiments("afinn")
141142
```
142143

0 commit comments

Comments
 (0)