## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")

## ----setup--------------------------------------------------------------------
library(krt)

## -----------------------------------------------------------------------------
krt_plugin_api()

## -----------------------------------------------------------------------------
validate_plugin_contract("validator", function(x, ctx) list())

## -----------------------------------------------------------------------------
license_rule <- function(x, ctx) {
  out <- list()
  for (r in x$resources) {
    if (identical(r$resource_type, "Dataset") && is.null(r$license)) {
      out <- c(out, list(list(message = "Dataset has no license.",
                              resource_id = r$resource_id, field = "license")))
    }
  }
  out
}
register_validator("inst-dataset-license", license_rule,
                   layer = "semantic", severity = "warning")

k <- add_resource(new_krt("Demo"), "Dataset", "D",
                  doi = "10.5281/zenodo.1", new_or_reuse = "new")
"inst-dataset-license" %in% as.data.frame(validate_krt(k))$rule_id

## ----eval = FALSE-------------------------------------------------------------
# register_profile(name = "my-institute", path = "path/to/profile/dir")
# export_krt(k, file.path(tempdir(), "out.csv"), profile = "my-institute")

## ----eval = FALSE-------------------------------------------------------------
# register_resolver("myscheme", function(id, resolve = TRUE, ...) {
#   list(input = id, normalized = id, resolved = FALSE, source = "mine")
# })
# 
# register_suggest_source("mysource", function(query, n) {
#   data.frame(label = query, id = "X:1", authority = "mine",
#              score = 1, uri = NA_character_, stringsAsFactors = FALSE)
# })

