Created
March 1, 2018 23:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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