Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update metadata #1

Closed
sweinand opened this issue Dec 20, 2023 · 0 comments
Closed

Update metadata #1

sweinand opened this issue Dec 20, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@sweinand
Copy link
Collaborator

  • Update country metadata
  • Add special aggregate compositions
# Title:    Country metadata and EA/EU compositions
# Author:   Sebastian Weinand
# Date:     20 December 2023

# load packages:
library(openxlsx)
library(data.table)

# countries:
countries <- as.data.table(read.xlsx("U:/HICP/R/package/hicp/dev/countries.xlsx", detectDates=TRUE))
vars <- c("is_eu","is_ea","is_efta","is_candidate")
countries[, (vars) := lapply(.SD, as.logical), .SDcols=vars]

countries[, "produces_hicp" := !is.na(index_dec_publ) & is.na(eu_until)]

# EU composition of the reference period:
EU <- list(
  "code"="EU",
  "name_en"="European Union",
  "name_fr"="Union européenne",
  "name_de"="Europäische Union",
  "index_decimals"=2L,
  "composition"=dt[is_eu==TRUE, code])

# euro area composition of the reference period:
EA <- list(
  "code"="EA",
  "name_en"="Euro area",
  "name_fr"="Zone euro",
  "name_de"="Euroraum",
  "index_decimals"=2L,
  "composition"=dt[is_ea==TRUE, code])


# get special aggregates:
library(xml2)
doc <- read_xml("http:https://publications.europa.eu/resource/authority/ed1/ecoicop/B")
sa.urls <- xml_attr(x = xml_find_all(doc, xpath="https://skos:member"), attr="resource")
sa.codes <- sapply(X=strsplit(sa.urls, split="/", fixed=TRUE), FUN=function(z) z[length(z)])

SPECAGGS <- vector(mode="list", length=length(sa.urls))
for(j in seq_along(SPECAGGS)){

  cat("processing url", j, "/", length(SPECAGGS), "\r")

  sa <- read_xml(x=sa.urls[j])

  SPECAGGS[[j]]$code <- sa.codes[j]

  xpath <- paste0("//rdf:Description[contains(@rdf:about, '", sa.codes[j], "')]")

  xml.node <- xml_find_all(sa, xpath=xpath)

  SPECAGGS[[j]]$name_en <- xml_text(xml_find_all(xml.node, xpath="skos:prefLabel[@xml:lang='en']"))
  SPECAGGS[[j]]$name_fr <- xml_text(xml_find_all(xml.node, xpath="skos:prefLabel[@xml:lang='fr']"))
  SPECAGGS[[j]]$name_de <- xml_text(xml_find_all(xml.node, xpath="skos:prefLabel[@xml:lang='de']"))

  comp <- xml_attr(xml_find_all(xml.node, xpath="skos:member"), "resource")
  SPECAGGS[[j]]$composition <- sapply(X=strsplit(comp, split="/", fixed=TRUE), FUN=function(z) z[length(z)])

  Sys.sleep(runif(n=1, min=0.1, max=0.5))

}
@sweinand sweinand added the enhancement New feature or request label Dec 20, 2023
@sweinand sweinand self-assigned this Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant