Skip to content



The CTX pre-defined object returns information about the options influencing the analysis or the definitions of the extraction templates.

The methods of the object are described below.


The getOptions method returns an object whose properties represent the options affecting or reflecting the analysis.
When used in the Studio IDE, the options are those set in Studio project settings plus others related to the analysis. For example, the JSON corresponding to the returned object could be like this:

    "enhanced_output": "false",
    "debugger": "true",
    "debugger_port": "9091",
    "explain_rule": "-1",
    "all_categories": "true",
    "filename": "Doc185672.xml.txt"


  • enhanced_output: the current value of the Enable Advanced Disambiguation Info configuration property.
  • debugger: if true, the Studio IDE debugger is on.
  • debugger_port: the current value of the Debugger Port configuration property.
  • all_categories: corresponds to the Show All Categories configuration property.
  • filename: the name of the file being analyzed.

When using the text intelligence engine via the Studio Local Deployment Agent API or when uploading a model to Platform and then publishing the model to NL Flow, putting it in a workflow and using it via NL Flow API, the options are those specified in the input JSON under the options key. For example:

"options": {
    "custom": {
        "doSomethingSpecial": true

The custom key in the input JSON corresponds to the custom_options property of the object returned by the method.

The syntax is:


For example, this code can access the doSomethingSpecial option of the example above and takes it into account:

var options = CTX.getOptions();

if( options.hasOwnProperty('custom') &&
    options.custom.hasOwnProperty('doSomethingSpecial') ) {
    // Do something special


The getTemplates method returns an array containing the definition of the extraction templates with their fields and fields' attributes.

For example, the JSON corresponding to the array could be something like this:

        "template": "TEMPLATE01",
        "fields": [
                "field": "FIELD01",
                "cardinal": "false",
                "solitary": "false"
                "field": "FIELD02",
                "cardinal": "false",
                "solitary": "false"

where cardinal and solitary are field attributes.

The syntax is:



The getTaxonomy method returns an array of objects containing the project taxonomy.

Each item of the array represent a node of the taxonomy—a domain—with its descendants and has this structure:

    "name": domainName,
    "label": domainLabel[,
    "domains": array]

where domainName is the name of the domain, domainLabel is the optional label of the domain and domains, which is present only for non-leaf nodes, is an array each item of which represents a child node and as the same structure as above.

The syntax is:



The getAttributeMatch method must be used in functions invoked via the SCRIPT attribute used in a plus (+) combination with another attribute, for example:

KEYWORD("an apple a day keeps the doctor away") + SCRIPT(function)

The method returns the range of tokens matched by the previous attribute.
For example, given a rule with a condition containing the operand above, if the analyzed text is:

As the saying goes, an apple a day keeps the doctor away.

and the function specified as an argument to the SCRIPT attribute is like this:

function testAttributeMatch(index, params) {
    var match = CTX.getAttributeMatch();

during the analysis the match variable is an object like this:

    "tokenBegin": "5",
    "tokenEnd": "12"

tokenBegin is the number of the first token of the range matched by the KEYWORD attribute (an), tokenEnd is the number of the last token of the range (away).

Depending on the values of tokenBegin and tokenEnd and other variables, the function code can return true (the SCRIPT attribute is matched) or false (the SCRIPT attribute is not matched), in order to make true or false the combination with the previous attribute, i.e. the entire operand of the condition.

The syntax of the method is: