Skip to contents

Replaces tokens made by tokenise() - for example in a model's answer - with the values they stand for. Tokens are recognised with any letter case, with spaces inside the brackets ([ pan_1 ]) and without brackets (PAN_1), because models do not always copy them exactly. Tokens the vault does not know are left unchanged.

Usage

restore(text, vault, strict = FALSE)

Arguments

text

A character vector.

vault

The vault used by tokenise().

strict

If TRUE, it is an error when text contains a bracketed token the vault does not know (one the model invented or altered).

Value

A character vector like text.

Examples

vault <- cg_vault()
tokenise("Name: Priya Nair, PAN ABCPE1234F", vault)
#> [1] "Name: [PERSON_NAME_1], PAN [PAN_1]"
restore("[PERSON_NAME_1] holds [pan_1].", vault)
#> [1] "Priya Nair holds ABCPE1234F."