Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit ec5bb0e

Browse files
authored
fix (#921)
1 parent 10e144c commit ec5bb0e

File tree

3 files changed

+113
-1
lines changed

3 files changed

+113
-1
lines changed

packages/lu/src/parser/luis/luConverter.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ const parseUtterancesToLu = function(utterances, luisJSON){
9292
if(utterance.entities.length >= 0) {
9393
// update utterance for each entity
9494
let text = utterance.text;
95-
let sortedEntitiesList = objectSortByStartPos(utterance.entities);
95+
// flatten entities
96+
let flatEntities = [];
97+
Object.assign([], utterance.entities).forEach(entity => flattenEntities(entity, flatEntities));
98+
let sortedEntitiesList = objectSortByStartPos(flatEntities);
99+
// remove all children
100+
sortedEntitiesList.forEach(entity => delete entity.children);
96101
let tokenizedText = text.split('');
97102
// handle cases where we have both child as well as cases where more than one entity can have the same start position
98103
// if there are multiple entities in the same start position, then order them by composite, nDepth, regular entity
@@ -108,6 +113,14 @@ const parseUtterancesToLu = function(utterances, luisJSON){
108113
return fileContent
109114
}
110115

116+
const flattenEntities = function(entity, flatEntities)
117+
{
118+
if (entity.children !== undefined && Array.isArray(entity.children) && entity.children.length !== 0) {
119+
entity.children.forEach(child => flattenEntities(child, flatEntities));
120+
}
121+
flatEntities.push(Object.assign({}, entity));
122+
}
123+
111124
const getEntitiesByPositionList = function(entitiesList, tokenizedText) {
112125
(entitiesList || []).forEach(entity => {
113126
// does this entity have child labels?
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
{
2+
"intents": [
3+
{
4+
"name": "None"
5+
}
6+
],
7+
"entities": [
8+
{
9+
"name": "add",
10+
"roles": [],
11+
"children": [
12+
{
13+
"name": "count",
14+
"children": [],
15+
"features": [
16+
{
17+
"modelName": "globalCount",
18+
"isRequired": true
19+
}
20+
]
21+
}
22+
]
23+
},
24+
{
25+
"name": "globalCount",
26+
"roles": [],
27+
"children": [
28+
{
29+
"name": "countNumber",
30+
"children": [],
31+
"features": [
32+
{
33+
"modelName": "number",
34+
"isRequired": true
35+
}
36+
]
37+
}
38+
]
39+
}
40+
],
41+
"composites": [],
42+
"closedLists": [],
43+
"regex_entities": [],
44+
"regex_features": [],
45+
"utterances": [
46+
{
47+
"text": "add two apples",
48+
"intent": "None",
49+
"entities": [
50+
{
51+
"entity": "add",
52+
"startPos": 0,
53+
"endPos": 13,
54+
"children": [
55+
{
56+
"entity": "count",
57+
"startPos": 4,
58+
"endPos": 13
59+
}
60+
]
61+
},
62+
{
63+
"entity": "globalCount",
64+
"startPos": 4,
65+
"endPos": 13,
66+
"children": [
67+
{
68+
"entity": "countNumber",
69+
"startPos": 4,
70+
"endPos": 6
71+
}
72+
]
73+
}
74+
]
75+
}
76+
],
77+
"patterns": [],
78+
"patternAnyEntities": [],
79+
"prebuiltEntities": [
80+
{
81+
"name": "number",
82+
"roles": []
83+
}
84+
],
85+
"luis_schema_version": "7.0.0",
86+
"versionId": "0.1",
87+
"name": "LuTest",
88+
"desc": "",
89+
"culture": "en-us",
90+
"tokenizerVersion": "1.0.0",
91+
"phraselists": []
92+
}

packages/lu/test/parser/luis/luisBuilder.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const LUISBuilder = require('./../../../src/parser/luis/luisBuilder')
22
const LU = require('./../../../src/parser/lu/lu')
33
var chai = require('chai');
4+
const luisobjenum = require('../../../src/parser/utils/enums/luisobjenum');
45
var assert = chai.assert;
56

67
describe('LUISBuilder', function() {
@@ -65,5 +66,11 @@ assert.isTrue(luisObject.validate())
6566
assert.equal(luisObject.content.includes('disabledForAllModels'), true);
6667
})
6768

69+
it('Overlapping entities are converted to LU correctly', async () => {
70+
let testJSON = require('../../fixtures/testcases/overlappingEntities.json');
71+
const luisObject = LUISBuilder.fromJson(testJSON).parseToLU();
72+
assert.equal(luisObject.content.includes(`- {@add=add {@globalCount={@count={@countNumber=two} apples}}}`), true);
73+
})
74+
6875

6976
});

0 commit comments

Comments
 (0)