
Apply semantic suggestions into a dictionary
Source:R/semantics-helpers.R
apply_semantic_suggestions.RdCopies selected IRIs from a semantic_suggestions tibble into the matching
dictionary fields. Suggestions remain separate by default; this helper gives
you an explicit merge step when you decide the top candidates are good enough.
Arguments
- dict
A dictionary tibble, typically returned by
infer_dictionary()orsuggest_semantics().- suggestions
A suggestions tibble, usually
attr(dict, "semantic_suggestions"). If omitted, the function reads that attribute fromdict.- strategy
Selection strategy per column-role pair.
"top"keeps the original lexical ranking."reviewed"applies only rows whosedecisionis"accepted"(or the equivalent"accept")."llm"applies only candidates marked withllm_selected = TRUEbysuggest_semantics(..., llm_assess = TRUE). When reviewed or LLM-reviewed selections contain multiple constraints for one measurement, their IRIs are deduplicated in first-occurrence order and written toconstraint_irias the SDP-compatible semicolon-separated value. Other roles continue to select one value per column-role pair.- columns
Optional character vector limiting application to specific
column_namevalues.- roles
Optional character vector limiting application to specific suggestion roles:
"variable","property","entity","unit","constraint","statistical_modifier".- min_score
Optional numeric threshold. Only available when
suggestionsincludes ascorecolumn; otherwise the function errors.- min_llm_confidence
Optional numeric threshold for
strategy = "llm". Requiresllm_confidenceinsuggestions.- overwrite
Logical; if
FALSE(default), only missing fields are filled. SetTRUEto intentionally replace existing IRIs.- verbose
Logical; if
TRUE(default), print a short summary.
Details
Matching is done by both column_name and dictionary_role. When the
suggestions tibble also includes dataset_id and table_id, those keys are
honored too. Suggestions that target non-column destinations (for example
codes.csv, tables.csv, or dataset.csv) are ignored by this helper and
remain review-only.
Examples
dict <- infer_dictionary(data.frame(spawner_count = c(12L, 19L)))
# Example-only IRI: replace it with a reviewed term for a real SDP.
reviewed <- tibble::tibble(
column_name = "spawner_count", dictionary_role = "variable",
iri = "https://example.org/terms/spawner-count", score = 3
)
filled <- apply_semantic_suggestions(
dict, suggestions = reviewed, columns = "spawner_count",
min_score = 2, verbose = FALSE
)
filled$term_iri
#> [1] "https://example.org/terms/spawner-count"