node-nlp
Version:
Library for NLU (Natural Language Understanding) done in Node.js
59 lines • 2.49 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* A `BotState` specific implementation of the `StatePropertyAccessor` interface.
*
* @remarks
* Properties can be defined for a given `BotState` instance using `createProperty()`.
*
* ```JavaScript
* const dialogStateProperty = ConversationState.createProperty('dialogState');
* const dialogs = new DialogSet(dialogStateProperty);
* ```
* @param T (Optional) type of property being persisted. Defaults to `any` type.
*/
class BotStatePropertyAccessor {
/**
* Creates a new BotStatePropertyAccessor instance.
* @param state Parent BotState instance.
* @param name Unique name of the property for the parent BotState.
*/
constructor(state, name) {
this.state = state;
this.name = name;
}
delete(context) {
return __awaiter(this, void 0, void 0, function* () {
const obj = yield this.state.load(context);
if (obj.hasOwnProperty(this.name)) {
delete obj[this.name];
}
});
}
get(context, defaultValue) {
return __awaiter(this, void 0, void 0, function* () {
const obj = yield this.state.load(context);
if (!obj.hasOwnProperty(this.name) && defaultValue !== undefined) {
const clone = (typeof defaultValue === 'object' || Array.isArray(defaultValue)) ? JSON.parse(JSON.stringify(defaultValue)) : defaultValue;
obj[this.name] = clone;
}
return obj[this.name];
});
}
set(context, value) {
return __awaiter(this, void 0, void 0, function* () {
const obj = yield this.state.load(context);
obj[this.name] = value;
});
}
}
exports.BotStatePropertyAccessor = BotStatePropertyAccessor;
//# sourceMappingURL=botStatePropertyAccessor.js.map
;