Skip to content

CTX

Introduction

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.

getOptions

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"
}

where:

  • 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:

CTX.getOptions()

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
}

getTemplates

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:

CTX.getTemplates()

getTaxonomy

The getTaxonomy method returns an array of objects containing the taxonomy first level nodes.

Each node contains the name and label originally assigned to the taxonomy node.

In case of sub-nodes, the father node contains another array of objects with the same structure described above called domains.

The syntax is:

CTX.getTaxonomy()

getAttributeMatch

The getAttributeMatch method returns an object with two keys, tokenBegin and tokenEnd, containing the extremes of the range of tokens extracted by the operand of the rule condition. For the method to properly work, it must be used in a function called with the SCRIPT attribute.

As example, if this function:

function testAttributeMatch(index, params) {
    var match = CTX.getAttributeMatch();
    printOBJ(match);
    return true;
}

is called by the SCRIPT attribute in this extraction rule:

SCOPE SENTENCE
{
    IDENTIFY(PROVERBS)
    {
        @APPLE_SAYING[KEYWORD("an apple a day keeps the doctor away")+SCRIPT("testAttributeMatch")]
    }
}

applied to this text:

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

you will get this object printed in the Console tool window:

{
    "tokenBegin": "5",
    "tokenEnd": "12"
}

The syntax of the method is:

CTX.getAttributeMatch()