Genja Introduction
Introduction
Genja's template syntax is based on Jinja. All concepts described in Jinja's documentation work in Genja as well. Genja provides additional functionality to support:
- complex morphology (declension, agreement in gender and number, specific handling of numerals etc.).
- retrieving entity names and other attributes from Geneea Knowledge Base (GKB)
- domain-specific macros and filters to make template writing for given domain easier
To generate text from a template, structured data in JSON format must be provided.
Domains
We use domains to specify the set of filters, pre/post processing and the GKB bucket used. There are two generic domains:
general_en- domain for general English textsgeneral_cs- domain for general Czech texts
In addition, there might be customer-specific domains.
Template Basics
The basic building blocks of a template are:
- Text. Genja ignores anything that is not enclosed in its special marks (
{% ... %},{{ ... }},{# ... #}). The text can be XML/HTML or any text-based format. - Variables and expressions. Using
{{ var }}you can access variablevarfrom the input data. See Referring to JSON data below. Within expressions, you can use filters to transform their input.genja_filtersare delimited by a pipe and can be used in sequences, for example{{ priceDiff|abs|round }}. - Statements using the
{% ... %}syntax. These includeifstatements,forloops, support for alternatives, and macro declarations. Seegenja_statementsfor more information. - Comments using the
{# ... #}syntax. Text inside comments is ignored and serves for documentation purposes.
Referring to JSON data
Let's say we have JSON data looking like this:
"previous_elections": {
"year": 2014,
"type": "regular",
"parties": [ ... ]
}
then this template:
The last election took place in {{previous_elections.year}}.
generates:
"The last election took place in 2014."