Variables in sentences (and later also in custom types) are specified via {name:type}
. In
parser.defineSentence(
"Apply Gaussian blurring with a standard deviation of {stddev:float} pixel(s).", ...);
there is one variable; a floating point number called stddev
.
Next to float
, a number of built-in types exist (see below).
Variable names can consist of any character but :
, {
and }
.
type
must be a valid type, i.e. either a built-in type or a custom type. Type names must start with a letter or underscore and they must end with either a letter, a digit or an underscore. They may contains hyphens (-
). (The regular expression for type names is [A-Za-z_] ([A-Za-z0-9-_]* [A-Za-z0-9_])?
).
Variable specifications may contain a quantifier: {name:type:quantifier}
. A quantifier specifies how often the type
is matched. For example, {pin:digit:4}
would match a 4-digit number called 'pin'. Valid quantifiers:
{pin:digit:4}
matches a number consisting of four digits.{pin:digit:3-5}
matches a number consisting of 3 to 5 digits.{pin:digit:*}
matches a number consisting of 0 to infinity digits.{pin:digit:+}
matches a number consisting of 1 to infinity digits.{pin:digit:?}
matches a number consisting of 0 to 1 digits.If a quantifier is used, the variable evaluates to java.lang.Object[]
, where the actual type of each array entry corresponds to type
(here: digit
). See also the paragraph "Evaluating the parsed text".
Variables can also be specified without type and quantifier, like {literal}
. In this case, it matches the constant string 'literal'.
In summary, these options exist:
Specification | Meaning |
---|---|
{name:type} |
a variable of type type called name |
{name:type:quantifier} |
a variable of type type called name , repeated according to quantifier |
{literal} |
a variable of type type called name |