For my third blog I have finally started actually coding and its become more challenging than I had anticipated. To start I am using the NYT API. I started by making a query of all articles that have prison policy in them. I followed the basic instructions for API tutorial for my specific query but I want to take my time and completely understand exactly what I am doing. Now that I have done this with my own code I need to ask some questions and figure out where I am at and where to go from here. This was my first step in collecting my data and now I need to figure out where to go from here. I am realizing I may have been able to run the code in practice but I am not exactly sure what I am really doing.

library(httr)
library(jsonlite)
## Warning: package 'jsonlite' was built under R version 4.1.2
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.2     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   2.0.1     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter()  masks stats::filter()
## x purrr::flatten() masks jsonlite::flatten()
## x dplyr::lag()     masks stats::lag()
prison <- GET('https://api.nytimes.com/svc/search/v2/articlesearch.json?q=prison&policy&api-key=ywg9nsFaF2uXhMA43C409CUYglWMxpMY')

prison_r <- fromJSON(rawToChar(prison$content))
names(prison_r)
## [1] "status"    "copyright" "response"
prison_t <- as.tibble(cbind(
  date=prison_r$response$docs$pub_date,
  abstract=prison_r$response$docs$abstract,
  lead=prison_r$response$docs$lead_paragraph)
)
## Warning: `as.tibble()` was deprecated in tibble 2.0.0.
## Please use `as_tibble()` instead.
## The signature and semantics have changed, see `?as_tibble`.
prison_t
## # A tibble: 10 x 3
##    date         abstract                          lead                          
##    <chr>        <chr>                             <chr>                         
##  1 2022-03-03T… The jail’s system for reporting … Good morning. It’s Thursday. …
##  2 2022-03-02T… One man was paralyzed from the n… When a man was beaten on Rike…
##  3 2022-03-02T… The so-called “Less Is More Act”… When Kathy Hochul signed her …
##  4 2022-03-01T… “We’re not dealing with a grass-… “We’re not dealing with a gra…
##  5 2022-02-04T… Michael Taylor got frostbite in … After fleeing criminal charge…
##  6 2022-02-15T… Aleksei A. Navalny, the jailed R… Aleksei A. Navalny, the most …
##  7 2022-02-14T… Dennis Hope, who has been held i… WASHINGTON — Dennis Hope has …
##  8 2022-02-01T… The Bureau of Prisons’ unusual s… WASHINGTON — The federal pris…
##  9 2022-01-31T… The bodies of at least two boys … HASAKA, Syria — The boy had d…
## 10 2022-02-11T… With concerts and a new album, m… Keith LaMar has spent 33 year…
library(cleanNLP)
cnlp_init_udpipe()
annotated <- cnlp_annotate(prison_t$lead)
## Processed document 10 of 10
annotated
## $token
## # A tibble: 412 x 11
##    doc_id   sid tid   token  token_with_ws lemma upos  xpos  feats    tid_source
##  *  <int> <int> <chr> <chr>  <chr>         <chr> <chr> <chr> <chr>    <chr>     
##  1      1     1 1     Good   "Good "       good  ADJ   JJ    Degree=… 2         
##  2      1     1 2     morni… "morning"     morn… NOUN  NN    Number=… 0         
##  3      1     1 3     .      ". "          .     PUNCT .     <NA>     2         
##  4      1     2 1     It     "It"          it    PRON  PRP   Case=No… 3         
##  5      1     2 2     ’s     "’s "         be    AUX   VBZ   Mood=In… 3         
##  6      1     2 3     Thurs… "Thursday"    Thur… PROPN NNP   Number=… 0         
##  7      1     2 4     .      ". "          .     PUNCT .     <NA>     3         
##  8      1     3 1     We     "We"          we    PRON  PRP   Case=No… 3         
##  9      1     3 2     ’ll    "’ll "        ’ll   AUX   MD    VerbFor… 3         
## 10      1     3 3     look   "look "       look  VERB  VB    VerbFor… 0         
## # … with 402 more rows, and 1 more variable: relation <chr>
## 
## $document
##    doc_id
## 1       1
## 2       2
## 3       3
## 4       4
## 5       5
## 6       6
## 7       7
## 8       8
## 9       9
## 10     10
## 
## attr(,"class")
## [1] "cnlp_annotation" "list"