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 invokingFORMAT
in order forFORMAT
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.
Warning
For security reasons, the dompost load
method restricts loading files from locations outside the rules folder. To utilize the module, you must ensure that your taxonomy.xml
file is placed within the rules directory or a subfolder inside it.
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:
Category | Label |
---|---|
1.1.2 | Pit Bull |
With this code (after the taxonomy file has been copied into the rules folder):
function initialize(cmdline) {
dompost.load('taxonomy.xml');
return true;
}
function onFinalize(result) {
var categorization = result.match_info.rules.categorization;
try {
domPostMod.FORMAT(categorization, {
format: "%PATHNAME%",
separator: "/",
root: false
});
} catch(err){
CONSOLE.error(err);
}
return result;
}
you will get:
Category | Label |
---|---|
1.1.2 | 1/1.1/1.1.2 |
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 withrequire()
.taxonomyPath
is the path of the taxonomy file relative to the rules folder.
The syntax of the FORMAT
method is:
moduleVariable.FORMAT(categorization, arguments)
where:
moduleVariable
is the variable corresponding to the module and set withrequire()
.categorization
corresponds to the categorization section of the results object.-
arguments
is an object containing the parameters to be used Such parameters are:-
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 ofseparator
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 theformat
parameter above). If undeclared, it will be defaulted to an empty string. root
(optional property) is a boolean affecting the expansion of the %PATHDESCR% placeholder (see theformat
parameter above). If declared with a value oftrue
, the path is full and it includes the root category, otherwise the path is partial and starts from the second level ascendant.
-
The method also supports a parametric syntax, that is:
moduleVariable.FORMAT(categorization, format, separator, root)