From 47462a438e77576cf2a3bf8ef258158438dcd1df Mon Sep 17 00:00:00 2001 From: Linsberger Christian Date: Thu, 2 Sep 2021 09:01:18 +0200 Subject: [PATCH] First Gitea Version of sparql.R --- sparql.R | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 sparql.R diff --git a/sparql.R b/sparql.R new file mode 100644 index 0000000..21fb851 --- /dev/null +++ b/sparql.R @@ -0,0 +1,56 @@ +library("SPARQL") +library("stringi") + +### Gets the bibliographicCitations which are currently in the db ################## + +read_current_geoera_lit_db <- function() { + + ## http verwenden - https funktioniert nicht ## + endpoint = "http://resource.geolba.ac.at/PoolParty/sparql/geoera" + + query = + "PREFIX skos: +PREFIX dcterms: +select * +where { +?uri a skos:Concept; skos:prefLabel ?L; dcterms:bibliographicCitation ?citation . +filter(regex(str(?uri),\"/ref/\")) filter(lang(?L)=\"en\") +optional {?uri dcterms:source ?downloadLink} +} +order by ?L +" + + +qd <- SPARQL(endpoint,query) +inDB <- qd$results + +for(j in 1:length(inDB[1,])){ + + for(i in 1:length(inDB[,j])){ + Encoding(inDB[i,j]) = "UTF-8" + } +} + + +pfad = paste("inDB-",format(Sys.Date(), "%Y_%m_%d"),".xlsx", sep="") + +write_xlsx(inDB, pfad) + +} + + +get_current_geoera_lit_db <- function() { + + pfad = paste("inDB-",format(Sys.Date(), "%Y_%m_%d"),".xlsx", sep="") + + if(file.exists(pfad)){ + inDB = read_excel(pfad) + return(inDB) + } + else { + read_current_geoera_lit_db() + + get_current_geoera_lit_db() + } + +} \ No newline at end of file