UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

69 lines 2.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EntityAssignmentComparer = void 0; /** * @module adaptive-expressions */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ const adaptiveEvents_1 = require("./adaptiveEvents"); /** * Compare two entity assignments to determine their relative priority. * * @remarks * Compare by event: assignEntity, chooseProperty, chooseEntity * Then by operations in order from schema (usually within assignEntity). * Then by unexpected before expected. * Then by oldest turn first. * Then by minimum position in utterance. */ class EntityAssignmentComparer { /** * Initializes a new instance of the [EntityAssignmentComparer](xref:botbuilder-dialogs-adaptive.EntityAssignmentComparer) class. * * @param operationPreference Preference on operations. */ constructor(operationPreference) { this.operationPreference = operationPreference; } /** * Compares [EntityAssignment](xref:botbuilder-dialogs-adaptive.EntityAssignment) x against y to determine its relative priority. * * @param x First entity assigment to compare. * @param y Second entity assigment to compare. * @returns Numerical value representing x's relative priority. */ compare(x, y) { var _a, _b; // Order by event. let comparison = EntityAssignmentComparer.eventPreference.indexOf(x.event) - EntityAssignmentComparer.eventPreference.indexOf(y.event); if (comparison === 0) { // Order by operations. comparison = this.operationPreference.indexOf(x.operation) - this.operationPreference.indexOf(y.operation); if (comparison === 0) { // Unexpected before expected. if (x.isExpected === y.isExpected) { comparison = 0; } else { comparison = x.isExpected ? -1 : 1; } if (comparison === 0) { // Order by position in utterance. comparison = ((_a = x.value) === null || _a === void 0 ? void 0 : _a.start) - ((_b = y.value) === null || _b === void 0 ? void 0 : _b.start); } } } return comparison; } } exports.EntityAssignmentComparer = EntityAssignmentComparer; EntityAssignmentComparer.eventPreference = [ adaptiveEvents_1.AdaptiveEvents.assignEntity, adaptiveEvents_1.AdaptiveEvents.chooseProperty, adaptiveEvents_1.AdaptiveEvents.chooseEntity, ]; //# sourceMappingURL=entityAssignmentComparer.js.map