Skip to content

Count text subdivisions

The DIS object provides methods to count the text subdivisions that disambiguation identified.

These methods are listed in the following table.

Subdivision type Method
Section getSectionsCount
Paragraph getParagraphsCount
Sentence getSentencesCount
Clause getClausesCount
Phrase getPhrasesCount
Token getTokensCount

For example, considering this input text:

If you are a whiskey lover, you will know that it is a spirit produced from fermented grain and aged in the wood.
And a spirit is an alcoholic beverage in which the alcohol content has been increased by distillation.

this statement:

var sentenceCount = DIS.getSentencesCount();

sets the sentenceCount variable to 2, since the disambiguation found two sentences in the text.
This other statement:

var tokenCount = DIS.getTokensCount();

sets the tokenCount variable to 44 that is the number of detected tokens. Remember that also atoms are counted as tokens.

The syntax is similar for all the methods, they have no arguments and return an integer number.

Knowing the number of subdivisions of a given type is necessary to refer to a particular subdivision using its zero-based index with the other methods of the DIS object.