forked from cezary-rosinski/Institute-of-Literary-Research
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimr_grant.Rmd
91 lines (73 loc) · 2.18 KB
/
vimr_grant.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
---
title: "R Notebook"
output: html_notebook
---
```{r}
#API VIAF
library(httr)
library(jsonlite)
library(lubridate)
options(stringsAsFactors = FALSE)
library(tidyverse)
library(viafr)
library(XML)
url <- "http://www.viaf.org"
path <- "eurlex/directory_code"
test <- viafr::viaf_search(personalNames = "balzac honore de")
test <- as.character(viafr::viaf_suggest("balzac") %>% `[[`(1) %>% select(1) %>% slice(1))
test <- viafr::viaf_get(test)
tt_GET <- function(path, ...){
if (is.null(path))
stop("Nothing to parse")
uri <- "http://www.viaf.org/"
# call api
req <- httr::GET(uri, path = path, ...)
# check for http status
tt_check(req)
req
}
tt_check <- function(req) {
if (req$status_code < 400)
return(invisible())
stop("HTTP failure: ", req$status_code, "\n", call. = FALSE)
}
tt_parse_js <- function(req) {
text <- httr::content(req, as = "text")
if (identical(text, ""))
stop("Not output to parse", call. = FALSE)
jsonlite::fromJSON(text)
}
viaf_get <- function(viaf = NULL) {
if(is.null(viaf))
stop("No viaf provided")
tt_GET(path = paste0("viaf/", viaf), httr::add_headers(Accept = "application/json+links")) %>%
tt_parse_js()
}
viaf_suggest <- function(query = NULL){
if(is.null(query))
stop ("No query provided")
tt_GET(path = "viaf/AutoSuggest", query = list(query = query)) %>%
tt_parse_js()
}
kundera <- viaf_get("51691735")
test <- viaf_suggest("balzac honore de")
test <- data.frame(test)
```
```{r}
options(java.parameters = "-Xmx32000m")
options(scipen = 999)
pacman::p_load(googlesheets4,zoo,openxlsx,stringr,splitstackshape,plyr,dplyr,sqldf,stringdist,fuzzyjoin,data.table,svMisc,tidyverse,RJDBC,xlsx,magrittr,jsonlite)
pbl_viaf <- sheets_read(ss = "1cEz73dGN2r2-TTc702yne9tKfH9PQ6UyAJ2zBSV6Jb0")
viaf_value <- pbl_viaf %>%
mutate(viaf_id = str_extract(viaf,"\\d+")) %>%
select(viaf_id) %>%
filter(!is.na(viaf_id)) %>%
unique()
x <- 1:length(viaf_value$viaf_id)
data_frame <- data.frame(stringsAsFactors = TRUE)
for (i in x) {
progress(match(i,x), max.value = length(x))
iteration <- data.frame(test = paste(viaf_get(as.character(viaf_value$viaf_id[i])),collapse = "|"))
data_frame <- rbind(data_frame,iteration)
}
```