Recognizer Class

  • java.lang.Object
    • com.microsoft.bot.dialogs.Recognizer

public class Recognizer

Recognizer base class.

Recognizers operate in a DialogContext environment to recognize user input into Intents and Entities.

This class models 3 virtual methods around * Pure DialogContext (where the recognition happens against current state dialogcontext * Activity (where the recognition is from an Activity) * Text/Locale (where the recognition is from text/locale)

The default implementation of DialogContext method is to use Context.Activity and call the activity method. The default implementation of Activity method is to filter to Message activities and pull out text/locale and call the text/locale method.

Field Summary

Modifier and Type Field and Description
static final java.lang.String CHOOSE_INTENT

Intent name that will be produced by this recognizer if the child recognizers do not have consensus for intents.

static final java.lang.String NONE_INTENT

Standard none intent that means none of the recognizers recognize the intent.

Constructor Summary

Constructor Description
Recognizer()

Initializes a new Recognizer.

Method Summary

Modifier and Type Method and Description
java.util.concurrent.CompletableFuture<T> <T>recognize(DialogContext dialogContext, Activity activity, Map<String,String> telemetryProperties, Map<String,Double> telemetryMetrics, Class<T> c)

Runs current DialogContext.TurnContext.Activity through a recognizer and returns a strongly-typed recognizer result using RecognizerConvert.

protected static RecognizerResult createChooseIntentResult(Map<String,RecognizerResult> recognizerResults)

Returns ChooseIntent between multiple recognizer results.

protected java.util.Map<java.lang.String,java.lang.String> fillRecognizerResultTelemetryProperties(RecognizerResult recognizerResult, Map<String,String> telemetryProperties, DialogContext dialogContext)

Uses the RecognizerResult to create a list of propeties to be included when tracking the result in telemetry.

java.lang.String getId()

Gets id of the recognizer.

BotTelemetryClient getTelemetryClient()

Gets the currently configured BotTelemetryClient that logs the RecognizerResult event.

java.util.concurrent.CompletableFuture<RecognizerResult> recognize(DialogContext dialogContext, Activity activity)

Runs current DialogContext.TurnContext.Activity through a recognizer and returns a generic recognizer result.

java.util.concurrent.CompletableFuture<RecognizerResult> recognize(DialogContext dialogContext, Activity activity, Map<String,String> telemetryProperties, Map<String,Double> telemetryMetrics)

Runs current DialogContext.TurnContext.Activity through a recognizer and returns a generic recognizer result.

void setId(String withId)

Sets id of the recognizer.

void setTelemetryClient(BotTelemetryClient withTelemetryClient)

Sets the currently configured BotTelemetryClient that logs the RecognizerResult event.

protected void trackRecognizerResult(DialogContext dialogContext, String eventName, Map<String,String> telemetryProperties, Map<String,Double> telemetryMetrics)

Tracks an event with the event name provided using the TelemetryClient attaching the properties / metrics.

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Field Details

CHOOSE_INTENT

public static final String CHOOSE_INTENT

Intent name that will be produced by this recognizer if the child recognizers do not have consensus for intents.

NONE_INTENT

public static final String NONE_INTENT

Standard none intent that means none of the recognizers recognize the intent. If each recognizer returns no intents or None intents, then this recognizer will return None intent.

Constructor Details

Recognizer

public Recognizer()

Initializes a new Recognizer.

Method Details

<T>recognize

public CompletableFuture recognize(DialogContext dialogContext, Activity activity, Map telemetryProperties, Map telemetryMetrics, Class c)

Runs current DialogContext.TurnContext.Activity through a recognizer and returns a strongly-typed recognizer result using RecognizerConvert.

Parameters:

dialogContext - Dialog Context.
activity - activity to recognize.
telemetryProperties - The properties to be included as part of the event tracking.
telemetryMetrics - The metrics to be included as part of the event tracking.
c - Class of type T.

Returns:

Analysis of utterance.

createChooseIntentResult

protected static RecognizerResult createChooseIntentResult(Map recognizerResults)

Returns ChooseIntent between multiple recognizer results.

Parameters:

recognizerResults - recognizer Id to recognizer results map.

Returns:

recognizerResult which is ChooseIntent.

fillRecognizerResultTelemetryProperties

protected Map fillRecognizerResultTelemetryProperties(RecognizerResult recognizerResult, Map telemetryProperties, DialogContext dialogContext)

Uses the RecognizerResult to create a list of propeties to be included when tracking the result in telemetry.

Parameters:

recognizerResult - Recognizer Result.
telemetryProperties - A list of properties to append or override the properties created using the RecognizerResult.
dialogContext - Dialog Context.

Returns:

A dictionary that can be included when calling the TrackEvent method on the TelemetryClient.

getId

public String getId()

Gets id of the recognizer.

Returns:

id of the recognizer

getTelemetryClient

public BotTelemetryClient getTelemetryClient()

Gets the currently configured BotTelemetryClient that logs the RecognizerResult event.

Returns:

BotTelemetryClient

recognize

public CompletableFuture recognize(DialogContext dialogContext, Activity activity)

Runs current DialogContext.TurnContext.Activity through a recognizer and returns a generic recognizer result.

Parameters:

dialogContext - Dialog Context.
activity - activity to recognize.

Returns:

Analysis of utterance.

recognize

public CompletableFuture recognize(DialogContext dialogContext, Activity activity, Map telemetryProperties, Map telemetryMetrics)

Runs current DialogContext.TurnContext.Activity through a recognizer and returns a generic recognizer result.

Parameters:

dialogContext - Dialog Context.
activity - activity to recognize.
telemetryProperties - The properties to be included as part of the event tracking.
telemetryMetrics - The metrics to be included as part of the event tracking.

Returns:

Analysis of utterance.

setId

public void setId(String withId)

Sets id of the recognizer.

Parameters:

withId - id of the recognizer

setTelemetryClient

public void setTelemetryClient(BotTelemetryClient withTelemetryClient)

Sets the currently configured BotTelemetryClient that logs the RecognizerResult event.

Parameters:

withTelemetryClient - BotTelemetryClient

trackRecognizerResult

protected void trackRecognizerResult(DialogContext dialogContext, String eventName, Map telemetryProperties, Map telemetryMetrics)

Tracks an event with the event name provided using the TelemetryClient attaching the properties / metrics.

Parameters:

dialogContext - Dialog Context.
eventName - The name of the event to track.
telemetryProperties - The properties to be included as part of the event tracking.
telemetryMetrics - The metrics to be included as part of the event tracking.

Applies to