Skip to content

dompost

dompost is a scripting module that allows modifying the domain labels in the categorization section of the output.

The methods of this module are:

  • load: loads the category tree, i.e the taxonomy, from file. You have to invoke this method before invoking FORMAT in order for FORMAT to work.
  • FORMAT: modifies the label of the categories in the categorization section of the output.

The load method must be used in the initialize function, because it is the right place for the initialization of objects needed in other event handling functions.

The FORMAT method must be used in the onFinalize function, because it acts on the analysis results available when this function is run.

When in Studio you install the dompost module in your project, Studio modifies the main.jr file to insert this statement at the beginning of the file:

var dompost = require('modules/dompost');

The statement above sets a variable with an instance of the module so that you can use it in all event handling functions.

For example, consider this taxonomy:

1 Animals
    1.1 Dogs
        1.1.1 Labrador
        1.1.2 Pit Bull

If the following rule:

SCOPE SENTENCE
{
    DOMAIN(1.1.2)
    {
        KEYWORD("pit bull")
    }
}

is run against this text:

I have a beautiful Pit Bull whose name is Jerry.

you will get:

With this code:

function initialize(cmdline) {
    dompost.load('../taxonomy.xml');
    return true;
}

function onFinalize(result) {
    var categorization = result.match_info.rules.categorization;
    try {
        dompost.FORMAT(categorization, "%PATHNAME%", "/", false);
    } catch(err){
        CONSOLE.error(err);
    }
    return result;
}

you will get:

The FORMAT method changed the label of the category so that it became the name of the category itself preceded by the path of the category inside the taxonomy, built with the names of all the ascendant nodes of the category starting from the root category, using the slash character (/) as a separator.

The syntax of the load method is:

moduleVariable.load(taxonomyPath)

where:

  • moduleVariable is the variable corresponding to the module and set with require().
  • taxonomyPath is the path of the taxonomy file relative to the folder in which the text intelligence engine runs.

The syntax of the FORMAT method is:

moduleVariable.FORMAT(categorization, format,  separator, root)

where:

  • moduleVariable is the variable corresponding to the module and set with require().
  • categorization corresponds to the categorization section of the results object.
  • format is the format for the new value of the category label in which you can combine strings of characters with one or more of these placeholders:

    • %NAME%: replaced with the category name.
    • %DESCR%: replaced with the category label.
    • %PATHNAME%: replaced with the full path of the category inside the taxonomy, down from the root category, built using the category names and the value of separator as separator of the portions of the path.
    • %PATHDESCR%: replaced with the path—full or partial, based on the value of the root parameter—of the category inside the taxonomy, down from the root category, built using the category labels and the value of separator as separator of the portions of the path.

    For example, this value:

    CAT:%NAME%|%DESCR%
    

    will change the category label to the concatenation of constant CAT: followed by category name, followed by the pipe character (|) and the category label.

  • separator: the single character or string of characters used to separate the category names or labels when computing the replacement value from the %PATHNAME% and %PATHDESCR% placeholders (see the format parameter above).

  • root is a boolean affecting the expansion of the %PATHDESCR% placeholder (see the format parameter above). If true, the path is full and it includes the root category, otherwise the path is partial and starts from the second level ascendant.