Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get ULAN prefName for a given ID from the Getty Vocabularies SPARQL endpoint
library(tidyverse)
library(httr)
get_prefname <- function(id) {
message(id)
endpoint <- "http://vocab.getty.edu/sparql.csv?query="
query <- URLencode(str_interp("SELECT ?prefName WHERE {
?person dc:identifier '${id}';
xl:prefLabel [xl:literalForm ?prefName ] .
} LIMIT 1"))
try_ulan <- possibly(function(ep, qu) {
read_csv(str_interp("${ep}${qu}"), col_types = "c")
}, otherwise = data.frame())
Sys.sleep(0.3)
res <- try_ulan(endpoint, query)
if (nrow(res) == 1) {
return(res[[1,1]])
} else {
return(NA_character_)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment