Skip to content

Commit c906042

Browse files
committed
MIECS-19915 Added support for fullEntityMatches property
1 parent 931b6d8 commit c906042

File tree

10 files changed

+128
-2
lines changed

10 files changed

+128
-2
lines changed

lib/component/sdk.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,29 @@ const NLPResult = class {
5858
}
5959
}
6060

61+
/**
62+
* Returns full payload matches for the specified entity; may be an empty collection.
63+
* If no entity is specified, returns the full payload map of all entities.
64+
* @param {string} [entity] - name of the entity
65+
* @return {object} The full entity match result.
66+
*/
67+
fullEntityMatches(entity) {
68+
if (!this._nlpresult) {
69+
return entity === undefined ? {} : [];
70+
}
71+
72+
if (entity === undefined) {
73+
// Retrieving fullEntityMatches collection, or an empty collection if none
74+
return this._nlpresult.fullEntityMatches ? this._nlpresult.fullEntityMatches : {};
75+
} else {
76+
if (this._nlpresult.fullEntityMatches) {
77+
return this._nlpresult.fullEntityMatches[entity] ? this._nlpresult.fullEntityMatches[entity] : [];
78+
} else {
79+
return [];
80+
}
81+
}
82+
}
83+
6184
/**
6285
* Returns intent matches if any.
6386
* Intent matches are returned in descending order of score,

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@oracle/bots-node-sdk",
3-
"version": "2.3.4",
3+
"version": "2.4.0",
44
"description": "Oracle Bots SDK for custom component development and webhook integrations",
55
"main": "index.js",
66
"browser": "index-browser.js",

spec/lib/component/largeReq.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@
8686
"appId": "C174E54F-9A5D-4377-A34A-BD79C6DCCFC2",
8787
"botName": "MJ_FinancialBot",
8888
"entityMatches": { "AccountType": ["checking"] },
89+
"fullEntityMatches": {
90+
"AccountType": [
91+
{
92+
"entityName": "AccountType",
93+
"originalString": "checking",
94+
"canonicalName": "checking"
95+
}
96+
]
97+
},
8998
"intentMatches": {
9099
"summary": [{ "intent": "Balances", "score": 1 }],
91100
"detail": {

spec/lib/component/largeReq.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ describe('Component Conversation SDK parsing large request', function() {
3030
expect(sdk.variable('system.invalidUserInput')).not.toBeNull();
3131
expect(sdk.nlpResult()).not.toBeNull();
3232
expect(sdk.nlpResult("iResult").entityMatches('AccountType')[0]).toEqual('checking');
33+
expect(sdk.nlpResult("iResult").fullEntityMatches('AccountType')[0].originalString).toEqual('checking');
3334
expect(sdk.nlpResult("iResult").entityMatches()).toBeTruthy();
3435
expect(sdk.nlpResult("iResult").topIntentMatch().intent).toEqual('Balances');
3536
expect(sdk.nlpResult("iResult").query()).toEqual("what's my balance in checking?");

spec/lib/component/mock.payload.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,22 @@ exports.Mock = function() {
126126
entityMatches: {
127127
PizzaType: ["pepperoni"],
128128
PizzaSize: ["Large"]
129+
},
130+
fullEntityMatches: {
131+
PizzaType: [
132+
{
133+
entityName: "PizzaType",
134+
originalString: "pepperoni",
135+
canonicalName: "pepperoni"
136+
}
137+
],
138+
PizzaSize: [
139+
{
140+
entityName: "PizzaSize",
141+
originalString: "large",
142+
canonicalName: "Large"
143+
}
144+
]
129145
}
130146
},
131147
entity: false
@@ -235,6 +251,22 @@ exports.Mock = function() {
235251
entityMatches: {
236252
PizzaType: ["pepperoni"],
237253
PizzaSize: ["Large"]
254+
},
255+
fullEntityMatches: {
256+
PizzaType: [
257+
{
258+
entityName: "PizzaType",
259+
originalString: "pepperoni",
260+
canonicalName: "pepperoni"
261+
}
262+
],
263+
PizzaSize: [
264+
{
265+
entityName: "PizzaSize",
266+
originalString: "large",
267+
canonicalName: "Large"
268+
}
269+
]
238270
}
239271
},
240272
entity: false

spec/lib/component/sdk.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ describe('Component Conversation SDK', () => {
5454
const nlpResult = sdk.nlpResult();
5555
expect(nlpResult.topIntentMatch().intent).toEqual('OrderPizza');
5656
expect(nlpResult.entityMatches('PizzaType')[0]).toEqual('pepperoni');
57+
expect(nlpResult.fullEntityMatches('PizzaSize')[0].originalString).toEqual('large');
58+
expect(nlpResult.fullEntityMatches('PizzaSize')[0].canonicalName).toEqual('Large');
5759
sdk.variable('name', 'Ken');
5860
expect(sdk.variable('name')).toEqual('Ken');
5961
expect(sdk.response().modifyContext).toEqual(true); // wrote to context

ts/lib/component/sdk.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,29 @@ export class NLPResult {
7070
}
7171
}
7272

73+
/**
74+
* Returns full payload matches for the specified entity; may be an empty collection.
75+
* If no entity is specified, returns the full payload map of all entities.
76+
* @param {string} [entity] - name of the entity
77+
* @return {object} The full entity match result.
78+
*/
79+
fullEntityMatches(entity?: string) {
80+
if (!this._nlpresult) {
81+
return entity === undefined ? {} : [];
82+
}
83+
84+
if (entity === undefined) {
85+
// Retrieving fullEntityMatches collection, or an empty collection if none
86+
return this._nlpresult.fullEntityMatches ? this._nlpresult.fullEntityMatches : {};
87+
} else {
88+
if (this._nlpresult.fullEntityMatches) {
89+
return this._nlpresult.fullEntityMatches[entity] ? this._nlpresult.fullEntityMatches[entity] : [];
90+
} else {
91+
return [];
92+
}
93+
}
94+
}
95+
7396
/**
7497
* Returns intent matches if any.
7598
* Intent matches are returned in descending order of score

ts/spec/lib/conversation/mock.payload.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,23 @@ export const Mock = {
126126
'Large'
127127
]
128128
}
129+
'fullEntityMatches': {
130+
'PizzaType': [
131+
{
132+
'entityName': 'PizzaType',
133+
'originalString': 'pepperoni',
134+
'canonicalName': 'pepperoni'
135+
}
136+
],
137+
'PizzaSize': [
138+
{
139+
'entityName': 'PizzaSize',
140+
'originalString': 'large',
141+
'canonicalName': 'Large'
142+
}
143+
]
144+
}
145+
}
129146
},
130147
'entity': false
131148
},
@@ -238,6 +255,22 @@ export const Mock = {
238255
'PizzaSize': [
239256
'Large'
240257
]
258+
},
259+
'fullEntityMatches': {
260+
'PizzaType': [
261+
{
262+
'entityName': 'PizzaType',
263+
'originalString': 'pepperoni',
264+
'canonicalName': 'pepperoni'
265+
}
266+
],
267+
'PizzaSize': [
268+
{
269+
'entityName': 'PizzaSize',
270+
'originalString': 'large',
271+
'canonicalName': 'Large'
272+
}
273+
]
241274
}
242275
},
243276
'entity': false

ts/spec/lib/conversation/sdk.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ describe('Component Conversation SDK', () => {
4848
expect(nlpResult.topIntentMatch().intent).toEqual('OrderPizza');
4949
expect(nlpResult.entityMatches('PizzaType')[0]).toEqual('pepperoni');
5050

51+
expect(nlpResult.fullEntityMatches('PizzaSize')[0].originalString).toEqual('large');
52+
expect(nlpResult.fullEntityMatches('PizzaSize')[0].canonicalName).toEqual('Large');
53+
5154
sdk.variable('name', 'Ken');
5255
expect(sdk.variable('name')).toEqual('Ken');
5356
expect(sdk.response().modifyContext).toEqual(true); // wrote to context

0 commit comments

Comments
 (0)