EntityRecognizer class
Utility class used to parse & resolve common entities like datetimes received from LUIS.
Methods
expand |
Converts a set of choices into an expanded array. |
find |
Finds all occurrences of a specific entity type within a set. |
find |
Finds all possible matches for a users utterance given a list of choices. |
find |
Finds the best match for a users utterance given a list of choices. |
find |
Searches for the first occurance of a specific entity type within a set. |
parse |
Parses a boolean from a users utterance. |
parse |
Parses a number from either a users text utterance or a set of entities. |
parse |
Parses a date from either a users text utterance or a set of entities. |
recognize |
Recognizes a time from a users utterance. The utterance is parsed using the Chrono library. |
resolve |
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
IEntity[]
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.