---
title: "Terminology"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Terminology}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

These terms describe form models, reference catalogues and catalogue mappings.

## Main concepts

| Term       | Meaning                                                                                           |
|------------|---------------------------------------------------------------------------------------------------|
| Form       | An Excel workbook used to collect data.                                                           |
| Form model | A versioned YAML definition of a form’s sheets, fields, layout and constraints.                   |
| Consumer   | A package, tool or application using a form model to import, export, validate or transform forms. |

## Form model definition

### Structure

| Term   | Meaning                                                                              |
|--------|--------------------------------------------------------------------------------------|
| Sheet  | A worksheet within a form, containing fixed cells or repeated records.               |
| Field  | A named item of data with a declared type and a position in the form.                |
| Record | One row of related field values in a sheet with a table layout.                      |
| Layout | The arrangement of fields in fixed cells or table columns, with declared dimensions. |

### Validation declarations

| Term        | Meaning                                                                                 |
|-------------|-----------------------------------------------------------------------------------------|
| Field type  | The kind of value a field accepts, such as text, an integer, a date or a boolean.       |
| Constraint  | A requirement on a field or record, such as requiredness, allowed values or uniqueness. |
| Primary key | One or more fields whose combined values identify a record within a sheet.              |
| Parent key  | Fields that connect a record to the primary key of a record in another sheet.           |

### Reference declarations

| Term                | Meaning                                                                             |
|---------------------|-------------------------------------------------------------------------------------|
| Reference catalogue | A named collection of reference tables available from a configured source.          |
| Reference table     | A table of reference records, such as countries, stations or contacts.              |
| Lookup              | A named way to find rows in a reference table using a column and matching settings. |
| Reference binding   | A field’s declaration of the catalogue, table and lookup used to check its value.   |

## Reference preparation

| Term                 | Meaning                                                               |
|----------------------|-----------------------------------------------------------------------|
| Reference source     | The location, cache and credentials used to retrieve a catalogue.     |
| Lookup index         | Prepared data and matching settings used to find reference rows.      |
| Alias                | An alternative value that resolves to a canonical reference value.    |
| Reference cache      | Local files retained after catalogue and checksum verification.       |
| Reference snapshot   | Reference data and lookup settings retained for reuse.                 |
| Checksum             | A content fingerprint used to verify a file against its catalogue.    |

## Catalogue mapping

| Term                  | Meaning                                                                             |
|-----------------------|-------------------------------------------------------------------------------------|
| Mapping               | A correspondence between source and target reference tables.                        |
| Mapping configuration | The versioned YAML declaring the two catalogues and their mappings.                 |
| Source catalogue      | The catalogue whose reference values are being translated.                          |
| Target catalogue      | The catalogue in which the required reference values are resolved.                  |
| Correspondence        | The link from a source value to a value submitted to the target lookup.             |
| Correspondence file   | A CSV containing explicit `source_value` and `target_value` pairs.                  |
| DIRECT mapping        | A target lookup using the input or its CSV correspondence, without a source lookup. |
| REBOUND mapping       | A source lookup that reads another property and submits it to the target lookup.    |
| Mapping alternative   | One selectable correspondence for a target table; alternatives are not fallbacks.   |
| Mapping references    | Loaded catalogue data, lookup indexes and CSV correspondences used for resolution.  |
| Mapping result        | One row per input, containing its target value, status and resolution stage.        |
| Unresolved result     | A missing input, missing source record or property, absent match, or ambiguity.     |
| Provenance            | The selected mapping, configuration checksum, catalogue revisions and CSV checksum. |

Mappings are keyed by the target table; values are translated from source to target.

Catalogue aliases belong to individual lookups; correspondences belong to the mapping between catalogues.

DIRECT and REBOUND describe the resolution behaviour; the YAML has no `mode` field.

See the [mapping guide](mapping.html) for the configuration and runnable survey examples.

## R object classes

The package uses these classes for checked form models, references and mappings.

| S3 class                  | Role                                                        |
|---------------------------|-------------------------------------------------------------|
| `form_model`              | Checked form model and its original definition.             |
| `form_model_check`        | Diagnostics from checking a form model definition.         |
| `reference_configuration` | Catalogue sources and declared lookup policies.             |
| `reference_source`        | Retrieval settings, authentication and cache location.      |
| `reference_index`         | Reference rows and reusable matching indexes.               |
| `mapping_configuration`   | Validated correspondences between two catalogues.           |
| `mapping_references`      | Prepared catalogue indexes, correspondences and provenance. |
| `reference_env`           | Internal marker for a YAML `!env` value, consumed on read.  |

See `read_form_model()` and `check_form_model()` for form model classes.
Reference and mapping classes have help pages named `<class>-class`.

```{r class-help, eval=FALSE}
# Open the help page for prepared mapping reference objects.
help("mapping_references-class", package = "form.model")
```

`map_reference_values()` returns a data frame with provenance.
