EntityRecognizer class

Utility class used to parse & resolve common entities like datetimes received from LUIS.

Methods

expandChoices(string | Object | string[])

Converts a set of choices into an expanded array.

findAllEntities(IEntity[], string)

Finds all occurrences of a specific entity type within a set.

findAllMatches(string | Object | string[], string, number)

Finds all possible matches for a users utterance given a list of choices.

findBestMatch(string | Object | string[], string, number)

Finds the best match for a users utterance given a list of choices.

findEntity(IEntity[], string)

Searches for the first occurance of a specific entity type within a set.

parseBoolean(string)

Parses a boolean from a users utterance.

parseNumber(string | IEntity[])

Parses a number from either a users text utterance or a set of entities.

parseTime(string | IEntity[])

Parses a date from either a users text utterance or a set of entities.

recognizeTime(string, Date)

Recognizes a time from a users utterance. The utterance is parsed using the Chrono library.

resolveTime(IEntity[])

Calculates a Date from a set of datetime entities.

Method Details

expandChoices(string | Object | string[])

Converts a set of choices into an expanded array.

static function expandChoices(choices: string | Object | string[])

Parameters

choices

string | Object | string[]

  • choices: {string} - Pipe ('|') delimited list of values.
  • choices: {Object} - Object used to generate the list of choices. The objects field names will be used to build the list of choices.
  • choices: {string[]} - Array of strings. This will just be echoed back as the output.

Returns

string[]

findAllEntities(IEntity[], string)

Finds all occurrences of a specific entity type within a set.

static function findAllEntities(entities: IEntity[], type: string)

Parameters

entities

IEntity[]

Set of entities to search over.

type

string

Type of entity to find.

Returns

findAllMatches(string | Object | string[], string, number)

Finds all possible matches for a users utterance given a list of choices.

static function findAllMatches(choices: string | Object | string[], utterance: string, threshold?: number)

Parameters

choices

string | Object | string[]

  • choices: {string} - Pipe ('|') delimited list of values to compare against the users utterance.
  • choices: {Object} - Object used to generate the list of choices. The objects field names will be used to build the list of choices.
  • choices: {string[]} - Array of strings to compare against the users utterance.
utterance

string

Text utterance to parse.

threshold

number

(Optional) minimum score needed for a match to be considered. The default value is 0.6.

Returns

findBestMatch(string | Object | string[], string, number)

Finds the best match for a users utterance given a list of choices.

static function findBestMatch(choices: string | Object | string[], utterance: string, threshold?: number)

Parameters

choices

string | Object | string[]

  • choices: {string} - Pipe ('|') delimited list of values to compare against the users utterance.
  • choices: {Object} - Object used to generate the list of choices. The objects field names will be used to build the list of choices.
  • choices: {string[]} - Array of strings to compare against the users utterance.
utterance

string

Text utterance to parse.

threshold

number

(Optional) minimum score needed for a match to be considered. The default value is 0.6.

Returns

findEntity(IEntity[], string)

Searches for the first occurance of a specific entity type within a set.

static function findEntity(entities: IEntity[], type: string)

Parameters

entities

IEntity[]

Set of entities to search over.

type

string

Type of entity to find.

Returns

parseBoolean(string)

Parses a boolean from a users utterance.

static function parseBoolean(value: string)

Parameters

value

string

Text utterance to parse.

Returns

boolean

A valid boolean otherwise undefined.

parseNumber(string | IEntity[])

Parses a number from either a users text utterance or a set of entities.

static function parseNumber(value: string | IEntity[])

Parameters

value

string | IEntity[]

  • value: {string} - Text utterance to parse.
  • value: {IEntity[]} - Set of entities to resolve.

Returns

number

A valid number otherwise Number.NaN.

parseTime(string | IEntity[])

Parses a date from either a users text utterance or a set of entities.

static function parseTime(value: string | IEntity[])

Parameters

value

string | IEntity[]

  • value: {string} - Text utterance to parse. The utterance is parsed using the Chrono library.
  • value: {IEntity[]} - Set of entities to resolve.

Returns

Date

A valid Date object if the user spoke a time otherwise null.

recognizeTime(string, Date)

Recognizes a time from a users utterance. The utterance is parsed using the Chrono library.

static function recognizeTime(utterance: string, refDate?: Date)

Parameters

utterance

string

Text utterance to parse.

refDate

Date

(Optional) reference date used to calculate the final date.

Returns

An entity containing the resolved date if successful or null if a date couldn't be determined.

resolveTime(IEntity[])

Calculates a Date from a set of datetime entities.

static function resolveTime(entities: IEntity[])

Parameters

entities

IEntity[]

List of entities to extract date from.

Returns

Date

The successfully calculated Date or null if a date couldn't be determined.