UNPKG

botbuilder-dialogs-adaptive

Version:

Rule system for the Microsoft BotBuilder dialog system.

61 lines 3.1 kB
"use strict"; /** * @module botbuilder-dialogs-adaptive */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TextEntityRecognizer = void 0; const recognizers_text_1 = require("@microsoft/recognizers-text"); const entityRecognizer_1 = require("./entityRecognizer"); const textEntity_1 = require("./textEntity"); /** * TextEntityRecognizer - base class for Text.Recogizers from the text recognizer library. */ class TextEntityRecognizer extends entityRecognizer_1.EntityRecognizer { /** * Recognizes entities from an [Entity](xref:botframework-schema.Entity) list. * * @param {DialogContext} dialogContext The [DialogContext](xref:botbuilder-dialogs.DialogContext) for the current turn of conversation. * @param {string} text Text to recognize. * @param {string} locale Locale to use. * @param {Entity[]} entities The [Entity](xref:botframework-schema.Entity) array to be recognized. * @returns {Promise<Entity[]>} Recognized [Entity](xref:botframework-schema.Entity) list Promise. */ recognizeEntities(dialogContext, text, locale, entities) { return __awaiter(this, void 0, void 0, function* () { const culture = recognizers_text_1.Culture.mapToNearestLanguage(locale !== null && locale !== void 0 ? locale : ''); return entities .filter((e) => e.type == 'text') .map((e) => { const textEntity = new textEntity_1.TextEntity(); return Object.assign(textEntity, e); }) .reduce((entities, textEntity) => { return entities.concat(this._recognize(textEntity.text, culture).map((result) => { const newEntity = Object.assign({ type: result.typeName, }, result); delete newEntity.typeName; // The text recognizer libraries return models with End => array inclusive endIndex. // We want end to be (end-start) = length, length = endIndex - startIndex. newEntity.end += 1; return newEntity; })); }, []); }); } } exports.TextEntityRecognizer = TextEntityRecognizer; //# sourceMappingURL=textEntityRecognizer.js.map