Class: ContextManager

Bravey.ContextManager

new ContextManager()

The Bravey context manager. Contexts are handled as tags for multiple NLP instances. It store user sessions contexts and query the right NLP when asked.
Parameters:
Name Type Attributes Description
extensions.sessionManager SessionManager <optional>
An instance of a session manager. Bravey.SessionManager.InMemorySessionManager is used when not specified.
Source:

Methods

addNlp(nlp, contexttagsopt, methodopt)

Add a NLP instance to the context manager.
Parameters:
Name Type Attributes Default Description
nlp NLP The NLP instance.
contexttags Array.<String> <optional>
["default"] Related contexts tags.
method String <optional>
Method to be used with NLP test. (see Bravey.Nlp.test)
Source:

clearSessionIdData(sessionid) → {boolean}

Empty context data for the specified session ID.
Parameters:
Name Type Description
sessionid string The session ID.
Source:
Returns:
True if sessionid is found and context is set.
Type
boolean

getSessionIdData(sessionid) → {Array.<string>}

Get context data for the specified session ID.
Parameters:
Name Type Description
sessionid string The session ID.
Source:
Returns:
The related data.
Type
Array.<string>

removeContext(contexttag)

Remove a context.
Parameters:
Name Type Description
contexttag Array.<String> Tag to be deleted
Source:

removeNlp(nlp, contexttagsopt)

Remove a NLP instance to the context manager.
Parameters:
Name Type Attributes Default Description
nlp NLP The NLP instance.
contexttags Array.<String> <optional>
all Related contexts tags. Will be removed from all contexts if empty.
Source:

reserveSessionId(id) → {string}

Reserves a new session ID. It also clear expired sessions.
Parameters:
Name Type Description
id string The session ID to be reserved. Generates a new one if not defined.
Source:
Returns:
The new session ID.
Type
string

setSessionIdContext(sessionid, contexttag) → {boolean}

Set the context for a given session ID.
Parameters:
Name Type Description
sessionid String User session ID.
contexttag Array.<String> Tag to be deleted
Source:
Returns:
True if sessionid is found and context is set.
Type
boolean

setSessionIdData(sessionid, data) → {boolean}

Set context data for the specified session ID.
Parameters:
Name Type Description
sessionid string The session ID.
data Object Key/value pair for data to be set.
Source:
Returns:
True if sessionid is found and context is set.
Type
boolean

testByContext(text, textopt) → {ContextManagerResultByContext}

Check if a given sentence matches an intent and extracts its entities using the specified contexts.
Parameters:
Name Type Attributes Default Description
text string The sentence to be processed.
text Array.<string> <optional>
["default"] The context tags.
Source:
Returns:
When an intent is found.
Type
ContextManagerResultByContext

testBySessionId(text, textopt) → {ContextManagerResultBySessionId|false}

Check if a given sentence matches an intent and extracts its entities using the specified user session ID. When not specified, a new session ID is generated.
Parameters:
Name Type Attributes Default Description
text string The sentence to be processed.
text string <optional>
<new session id> The user session id.
Source:
Returns: