Skip to content

Additional metadata in attribute definition #17

Description

@ashiklom

Per the discussion today, were we looking for something like this? The general idea is that attributeDefinition has the format [variable_type]{Variable definition...}.

library(magrittr, include.only = "%>%")

attributes <- tibble::tribble(
  ~attributeName,     ~attributeDefinition,                      ~unit,                  ~formatString, ~numberType, ~definition,
  "time",              "[dimension]{time}",                                    "year",                "YYYY-MM-DD",  "numberType", NA,
  "depth",             "[dimension]{depth in reservior}",                      "meter",                NA,           "real",       NA,
  "ensemble",          "[dimension]{index of ensemble member}",                "dimensionless",        NA,           "integer",    NA,
  "species_1",         "[statevariable]{Population density of species 1}",         "numberPerMeterSquared", NA,          "real",       NA,
  "species_2",         "[statevariable]{Population density of species 2}",         "numberPerMeterSquared", NA,          "real",       NA,
  "data_assimilation", "[flag]{Flag whether time step assimilated data}", "dimensionless",        NA,           "integer",    NA
)
attributes
#> # A tibble: 6 x 6
#>   attributeName  attributeDefinition  unit    formatString numberType definition
#>   <chr>          <chr>                <chr>   <chr>        <chr>      <lgl>     
#> 1 time           [dimension]{time}    year    YYYY-MM-DD   numberType NA        
#> 2 depth          [dimension]{depth i… meter   <NA>         real       NA        
#> 3 ensemble       [dimension]{index o… dimens… <NA>         integer    NA        
#> 4 species_1      [statevariable]{Pop… number… <NA>         real       NA        
#> 5 species_2      [statevariable]{Pop… number… <NA>         real       NA        
#> 6 data_assimila… [flag]{Flag whether… dimens… <NA>         integer    NA

parse_attribute_definition <- function(string) {
  regex <- "\\[(.*?)\\]\\{(.*?)\\}"
  m <- regexec(regex, string)
  result <- regmatches(string, m)
  output <- do.call(rbind, result)[,-1]
  colnames(output) <- c("variable_type", "variable_definition")
  output
}

parse_attribute_definition(attributes$attributeDefinition)
#>      variable_type   variable_definition                      
#> [1,] "dimension"     "time"                                   
#> [2,] "dimension"     "depth in reservior"                     
#> [3,] "dimension"     "index of ensemble member"               
#> [4,] "statevariable" "Population density of species 1"        
#> [5,] "statevariable" "Population density of species 2"        
#> [6,] "flag"          "Flag whether time step assimilated data"

Created on 2020-09-15 by the reprex package (v0.3.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions