Skip to content

Instantly share code, notes, and snippets.

@mdlincoln
Created March 1, 2018 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdlincoln/74f6db1feadb85f2e1aee8d20ad24330 to your computer and use it in GitHub Desktop.
Save mdlincoln/74f6db1feadb85f2e1aee8d20ad24330 to your computer and use it in GitHub Desktop.
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