Templatization Utilities

Impostor.render_templateFunction
render_template(template locale) :: String
render_template(template, reference_dfrow; locale) :: String

Materialize a given pre-defined template by splitting template into tokens; each token may by associated to a generator-function exported by Impostor. Tokens associated to generator-functions are excpected to have the excact same spelling as their generator-function correspondents (e.g. the token "address" is associated to the generator-function address).

For practicality, tokens not exported by Impostor (see example below) are just repeated in the materialized template since it is not possible for Impostor to distinguish between badly spelled generator functions and raw text which should be present in materialized template.

Optionally, provide a reference_dfrow with column names which may be referenced by tokens in template. This is useful in the context of hierarchical data manipulation

Parameters

  • template::String: templaate to be materialized.
  • reference_dfrow::DataFrames.DataFrameRow: Reference values stored in a single-row DataFrame (DataFrameRow); access to values is made through references to column names of reference_dfrow (see examples below).

Examples

String Materialization

julia> template = "firstname surname occupation";

julia> render_template(template; locale="en_US")
"Charles Fraser Anthropologyst"

julia> template = "I know firstname surname, this person is a(n) occupation";

julia> render_template(template; locale="en_US")
"I know Charles Jameson, this person is a(n) Mathematician"

Missing Tokens

julia> template = "firstname lastname"  # not that there is no such 'lastname' function
"firstname lastname"

julia> render_template(template; locale="en_US")
"Kate lastname"

Using DataFrameRows

julia> dfrow = DataFrame(state="California", city="San Francisco")[1, :]
1×2 DataFrame
 Row │ state       city
     │ String      String
─────┼───────────────────────────
   1 │ California  San Francisco

julia> template = "I live in city (state)"

julia> render_template(template, dfrow; locale = "en_US")
"I live in San Francisco (California)"
source
Impostor.render_alphanumericFunction
render_alphanumeric(template::AbstractString; numbers, letters) :: String

Receive an alphanumeric template string (e.g. "^^^-####") and generate a string replacing:

  • '#' chars by random numbers between [0, 9].
  • '^' chars by random uppercase letters between A-Z.
  • '_' chars by random lowercase letters between a-z.
  • '=' chars by random uppercase or lowercase letters between a-z|A-Z.

Optionally, provide numbers to fill the '#' placeholders in template; or letters to fill '^','_' or '=' placeholders. Note that if the length of letters or numbers is smaller than the number of placeholders in each category, the remaining placeholders will be randomly filled according to the character in template.

Examples

julia> render_alphanumeric("####")
"6273"

julia> render_alphanumeric("123-####-AAA")
"123-5509-AAA"

julia> render_alphanumeric("__-^^-==-ZZZ123")
"vw-CX-fA-ZZZ123"

julia> render_alphanumeric("__-^^-==-ZZZ###"; numbers = "12345")
"qu-RT-St-ZZZ123"

julia> render_alphanumeric("__-^^-==-ZZZ###"; letters = "AABBCCDD")
"AA-BB-CC-ZZZ427"

julia> render_alphanumeric("__-^^-==-ZZZ###"; letters = "AABBCCDD", numbers = "12345")
"AA-BB-CC-ZZZ123"

julia> render_alphanumeric("_______"; letters = "abc")
"abcomhd"
source
Impostor.render_alphanumeric_rangeFunction
render_alphanumeric_range(template::AbstractString) :: String

Generate a string containing a number from a numeric range template. Such numeric templates may contain options separated by a ';' caracter. Additionally, options can assume a single template format (e.g. "4##") or specify a range using the ':' character inside the option (e.g. "2##:3##" specifies numbers between 200 and 399).

Example

julia> render_alphanumeric_range("4#####")
"412345"

julia> render_alphanumeric_range("34####;37####")  # selects 34#### or 37####
"349790"

julia> render_alphanumeric_range("51####:55####")
"532489"

julia> render_alphanumeric_range("2221##:2720##;51####:55####")  # selects 2221##:2720## or 51####:55####
"250000"
source