1. Genja Introduction

1.1. 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.

1.1.1. 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 texts

  • general_cs - domain for general Czech texts

In addition, there might be customer-specific domains.

1.2. 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 variable var from the input data. See Referring to JSON data below. Within expressions, you can use filters to transform their input. Filters are delimited by a pipe and can be used in sequences, for example {{ priceDiff|abs|round }}.

  • Statements using the {% ... %} syntax. These include if statements, for loops, support for alternatives, and macro declarations. See Statements for more information.

  • Comments using the {# ... #} syntax. Text inside comments is ignored and serves for documentation purposes.

1.3. 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.