Emimunoz/ludown 1 3 4 (#1308)
* Fix for #1250 * Fixes * Increasing package json version * Removing missing lines from merge
This commit is contained in:
Родитель
f87a6df0e3
Коммит
4094c5b1bb
|
@ -549,7 +549,7 @@ const parseAndHandleEntity = function (parsedContent, chunkSplitByLine, locale,
|
|||
let parsedRoleAndType = helpers.getRolesAndType(entityType);
|
||||
let entityRoles = parsedRoleAndType.roles;
|
||||
entityType = parsedRoleAndType.entityType;
|
||||
let pEntityName = (entityName === 'PREBUILT') ? entityType : entityName;
|
||||
let pEntityName = (entityName.toLowerCase() === 'prebuilt') ? entityType : entityName;
|
||||
// see if we already have this as Pattern.Any entity
|
||||
// see if we already have this in patternAny entity collection; if so, remove it but remember the roles (if any)
|
||||
for (let i in parsedContent.LUISJsonStructure.patternAnyEntities) {
|
||||
|
@ -570,7 +570,7 @@ const parseAndHandleEntity = function (parsedContent, chunkSplitByLine, locale,
|
|||
try {
|
||||
let rolesImport = VerifyAndUpdateSimpleEntityCollection(parsedContent, entityType, entityName);
|
||||
if (rolesImport.length !== 0) {
|
||||
rolesImport.forEach(role => entityRoles.push(role));
|
||||
rolesImport.forEach(role => !entityRoles.includes(role) ? entityRoles.push(role) : undefined);
|
||||
}
|
||||
} catch (err) {
|
||||
throw (err);
|
||||
|
@ -600,7 +600,7 @@ const parseAndHandleEntity = function (parsedContent, chunkSplitByLine, locale,
|
|||
try {
|
||||
let rolesImport = VerifyAndUpdateSimpleEntityCollection(parsedContent, entityName, 'RegEx');
|
||||
if (rolesImport.length !== 0) {
|
||||
rolesImport.forEach(role => entityRoles.push(role));
|
||||
rolesImport.forEach(role => !entityRoles.includes(role) ? entityRoles.push(role) : undefined);
|
||||
}
|
||||
} catch (err) {
|
||||
throw (err);
|
||||
|
@ -651,7 +651,7 @@ const parseAndHandleEntity = function (parsedContent, chunkSplitByLine, locale,
|
|||
try {
|
||||
let rolesImport = VerifyAndUpdateSimpleEntityCollection(parsedContent, entityName, 'Phrase List');
|
||||
if (rolesImport.length !== 0) {
|
||||
rolesImport.forEach(role => entityRoles.push(role));
|
||||
rolesImport.forEach(role => !entityRoles.includes(role) ? entityRoles.push(role) : undefined);
|
||||
}
|
||||
} catch (err) {
|
||||
throw (err);
|
||||
|
@ -755,9 +755,7 @@ const VerifyAndUpdateSimpleEntityCollection = function (parsedContent, entityNam
|
|||
let simpleEntityExists = (parsedContent.LUISJsonStructure.entities || []).find(item => item.name == entityName);
|
||||
if (simpleEntityExists !== undefined) {
|
||||
// take and add any roles into the roles list
|
||||
(simpleEntityExists.roles || []).forEach(role => {
|
||||
if (!entityRoles.includes(role)) entityRoles.push(role)
|
||||
});
|
||||
(simpleEntityExists.roles || []).forEach(role => !entityRoles.includes(role) ? entityRoles.push(role) : undefined);
|
||||
// remove this simple entity definition
|
||||
// Fix for #1137.
|
||||
// Current behavior does not allow for simple and phrase list entities to have the same name.
|
||||
|
@ -833,11 +831,7 @@ const parseAndHandleListEntity = function (parsedContent, chunkSplitByLine, enti
|
|||
let entityName = entityDef.split(':')[0].trim();
|
||||
let parsedEntityTypeAndRole = helpers.getRolesAndType(entityType);
|
||||
entityType = parsedEntityTypeAndRole.entityType;
|
||||
(parsedEntityTypeAndRole.roles || []).forEach(role => {
|
||||
if (!entityRoles.includes(role)) {
|
||||
entityRoles.push(role)
|
||||
}
|
||||
});
|
||||
(parsedEntityTypeAndRole.roles || []).forEach(role => !entityRoles.includes(role) ? entityRoles.push(role) : undefined);
|
||||
// check if this list entity is already labelled in an utterance and or added as a simple entity. if so, throw an error.
|
||||
try {
|
||||
let rolesImport = VerifyAndUpdateSimpleEntityCollection(parsedContent, entityName, 'List');
|
||||
|
@ -1001,11 +995,6 @@ const parseAndHandleIntent = function (parsedContent, chunkSplitByLine) {
|
|||
}
|
||||
});
|
||||
|
||||
// if this intent does not have any utterances, push this pattern as an utterance as well.
|
||||
let intentInUtterance = helpers.filterMatch(parsedContent.LUISJsonStructure.utterances, 'intent', intentName);
|
||||
if (intentInUtterance.length === 0) {
|
||||
parsedContent.LUISJsonStructure.utterances.push(new helperClass.uttereances(utteranceWithoutEntityLabel, intentName, []));
|
||||
}
|
||||
} else {
|
||||
|
||||
// add entities
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "ludown",
|
||||
"version": "1.3.3",
|
||||
"version": "1.3.4",
|
||||
"description": "Command line tool to convert .lu files to LUIS JSON and QnA maker JSON files",
|
||||
"main": "lib/exports.js",
|
||||
"scripts": {
|
||||
|
|
|
@ -519,10 +519,6 @@ describe('parseFile correctly parses utterances', function () {
|
|||
- I want {foodType}`;
|
||||
parseFile.parseFile(testLUFile, false)
|
||||
.then(res => {
|
||||
assert.equal(res.LUISJsonStructure.utterances.length, 1);
|
||||
assert.equal(res.LUISJsonStructure.utterances[0].text, "I want {foodType}");
|
||||
assert.equal(res.LUISJsonStructure.patterns.length, 1);
|
||||
assert.equal(res.LUISJsonStructure.patterns[0].pattern, "I want {foodType}");
|
||||
assert.equal(res.LUISJsonStructure.patternAnyEntities.length, 1);
|
||||
assert.equal(res.LUISJsonStructure.patternAnyEntities[0].name, "foodType");
|
||||
done();
|
||||
|
@ -571,10 +567,6 @@ describe('parseFile correctly parses utterances', function () {
|
|||
- I want {foodType} and {foodType}`;
|
||||
parseFile.parseFile(testLUFile, false)
|
||||
.then(res => {
|
||||
assert.equal(res.LUISJsonStructure.utterances.length, 1);
|
||||
assert.equal(res.LUISJsonStructure.utterances[0].text, "I want {foodType} and {foodType}");
|
||||
assert.equal(res.LUISJsonStructure.patterns.length, 1);
|
||||
assert.equal(res.LUISJsonStructure.patterns[0].pattern, "I want {foodType} and {foodType}");
|
||||
assert.equal(res.LUISJsonStructure.patternAnyEntities.length, 1);
|
||||
assert.equal(res.LUISJsonStructure.patternAnyEntities[0].name, "foodType");
|
||||
done();
|
||||
|
@ -619,10 +611,6 @@ describe('parseFile correctly parses utterances', function () {
|
|||
- {userName}`;
|
||||
parseFile.parseFile(testLUFile, false)
|
||||
.then(res => {
|
||||
assert.equal(res.LUISJsonStructure.utterances.length, 1);
|
||||
assert.equal(res.LUISJsonStructure.utterances[0].text, "{userName}");
|
||||
assert.equal(res.LUISJsonStructure.patterns.length, 1);
|
||||
assert.equal(res.LUISJsonStructure.patterns[0].pattern, "{userName}");
|
||||
assert.equal(res.LUISJsonStructure.patternAnyEntities.length, 1);
|
||||
assert.equal(res.LUISJsonStructure.patternAnyEntities[0].name, "userName");
|
||||
done();
|
||||
|
|
|
@ -900,4 +900,81 @@ $test:[fromTime]`;
|
|||
|
||||
})
|
||||
|
||||
it ('prebuilt entities with inline as well as explicit role definition is handled correctly', function(done){
|
||||
let testLU = `> # Intent definitions
|
||||
|
||||
## Intent
|
||||
- holiday request to {datetimeV2:to=next day}
|
||||
- holiday request vacation from {datetimeV2:from=today}
|
||||
- i want vacation from {datetimeV2:from} until {datetimeV2:to}
|
||||
|
||||
> # Entity definitions
|
||||
|
||||
> # PREBUILT Entity definitions
|
||||
|
||||
$PREBUILT:datetimeV2 Roles=to, from`;
|
||||
parser.parseFile(testLU, false, null)
|
||||
.then (res => {
|
||||
let LUISJSon = res.LUISJsonStructure;
|
||||
assert(LUISJSon.prebuiltEntities.length, 1);
|
||||
assert(LUISJSon.prebuiltEntities[0].roles.length, 2);
|
||||
assert.deepEqual(LUISJSon.prebuiltEntities[0].roles, ['from', 'to']);
|
||||
done();
|
||||
})
|
||||
.catch (err => done(`Test failed - ${JSON.stringify(err)}`))
|
||||
|
||||
})
|
||||
|
||||
it ('regex entities with inline as well as explicit role definition is handled correctly', function(done){
|
||||
let testLU = `> # Intent definitions
|
||||
|
||||
## Intent
|
||||
- holiday request to {regex1:to=32}
|
||||
- holiday request vacation from {regex1:from=today}
|
||||
- i want vacation from {regex1:from} until {regex1:to}
|
||||
|
||||
> # Entity definitions
|
||||
|
||||
> # PREBUILT Entity definitions
|
||||
|
||||
$regex1:/[0-9]/ Roles=to, from`;
|
||||
parser.parseFile(testLU, false, null)
|
||||
.then (res => {
|
||||
let LUISJSon = res.LUISJsonStructure;
|
||||
assert(LUISJSon.regex_entities.length, 1);
|
||||
assert(LUISJSon.regex_entities[0].roles.length, 2);
|
||||
assert.deepEqual(LUISJSon.regex_entities[0].roles, ['from', 'to']);
|
||||
done();
|
||||
})
|
||||
.catch (err => done(`Test failed - ${JSON.stringify(err)}`))
|
||||
|
||||
})
|
||||
|
||||
it ('closed list entities with inline as well as explicit role definition is handled correctly', function(done){
|
||||
let testLU = `> # Intent definitions
|
||||
|
||||
## Intent
|
||||
- holiday request to {list1:to=32}
|
||||
- holiday request vacation from {list1:from=today}
|
||||
- i want vacation from {list1:from} until {list1:to}
|
||||
|
||||
> # Entity definitions
|
||||
|
||||
> # PREBUILT Entity definitions
|
||||
|
||||
$list1: a = Roles = to, from
|
||||
- 32
|
||||
`;
|
||||
parser.parseFile(testLU, false, null)
|
||||
.then (res => {
|
||||
let LUISJSon = res.LUISJsonStructure;
|
||||
assert(LUISJSon.closedLists.length, 1);
|
||||
assert(LUISJSon.closedLists[0].roles.length, 2);
|
||||
assert.deepEqual(LUISJSon.closedLists[0].roles, ['from', 'to']);
|
||||
done();
|
||||
})
|
||||
.catch (err => done(`Test failed - ${JSON.stringify(err)}`))
|
||||
|
||||
})
|
||||
|
||||
});
|
|
@ -180,11 +180,6 @@
|
|||
"intent": "CreateAlarm",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "delete the {alarmTime} alarm",
|
||||
"intent": "DeleteAlarm",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "set phone call as my communication preference",
|
||||
"intent": "CommunicationPreference",
|
||||
|
|
|
@ -143,11 +143,6 @@
|
|||
"text": "set an alarm for 7AM next thursday",
|
||||
"intent": "CreateAlarm",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "delete the {alarmTime} alarm",
|
||||
"intent": "DeleteAlarm",
|
||||
"entities": []
|
||||
}
|
||||
],
|
||||
"patterns": [
|
||||
|
|
|
@ -174,11 +174,6 @@
|
|||
"intent": "CreateAlarm",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "delete the {alarmTime} alarm",
|
||||
"intent": "DeleteAlarm",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "set phone call as my communication preference",
|
||||
"intent": "CommunicationPreference",
|
||||
|
|
|
@ -174,11 +174,6 @@
|
|||
"intent": "CreateAlarm",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "delete the {alarmTime} alarm",
|
||||
"intent": "DeleteAlarm",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "set phone call as my communication preference",
|
||||
"intent": "CommunicationPreference",
|
||||
|
|
|
@ -200,11 +200,6 @@
|
|||
"intent": "CreateAlarm",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "delete the {alarmTime} alarm",
|
||||
"intent": "DeleteAlarm",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "set phone call as my communication preference",
|
||||
"intent": "CommunicationPreference",
|
||||
|
|
|
@ -31,8 +31,8 @@
|
|||
|
||||
|
||||
## DeleteAlarm
|
||||
- delete the {alarmTime} alarm
|
||||
- delete alarm
|
||||
- delete the {alarmTime} alarm
|
||||
- remove the {alarmTime} alarm
|
||||
|
||||
|
||||
|
|
|
@ -226,11 +226,6 @@
|
|||
"intent": "CreateAlarm",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "delete the {alarmTime} alarm",
|
||||
"intent": "DeleteAlarm",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "set phone call as my communication preference",
|
||||
"intent": "CommunicationPreference",
|
||||
|
@ -291,11 +286,6 @@
|
|||
"intent": "AskForUserName",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "set {commPreference} as my communication preference",
|
||||
"intent": "CommunicationPreference",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "can I get some m&m",
|
||||
"intent": "Buy chocolate",
|
||||
|
|
|
@ -125,11 +125,6 @@
|
|||
"intent": "CreateAlarm",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "delete the {alarmTime} alarm",
|
||||
"intent": "DeleteAlarm",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "set phone call as my communication preference",
|
||||
"intent": "CommunicationPreference",
|
||||
|
@ -256,11 +251,6 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"text": "set {commPreference} as my communication preference",
|
||||
"intent": "CommunicationPreference",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "can I get some m&m",
|
||||
"intent": "Buy chocolate",
|
||||
|
|
|
@ -90,16 +90,6 @@
|
|||
"text": "set an alarm for 7AM next thursday",
|
||||
"intent": "All",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "delete the {alarmTime} alarm",
|
||||
"intent": "All",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "set {commPreference} as my communication preference",
|
||||
"intent": "All",
|
||||
"entities": []
|
||||
}
|
||||
],
|
||||
"patterns": [],
|
||||
|
|
|
@ -90,26 +90,6 @@
|
|||
"text": "set an alarm for 7AM next thursday",
|
||||
"intent": "All",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "delete the {alarmTime} alarm",
|
||||
"intent": "All",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "set {commPreference} as my communication preference",
|
||||
"intent": "All",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "delete the {alarmTime} alarm",
|
||||
"intent": "All",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "set {commPreference} as my communication preference",
|
||||
"intent": "All",
|
||||
"entities": []
|
||||
}
|
||||
],
|
||||
"patterns": [],
|
||||
|
|
|
@ -177,11 +177,6 @@
|
|||
"intent": "CreateAlarm",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "delete the {alarmTime} alarm",
|
||||
"intent": "DeleteAlarm",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "set phone call as my communication preference",
|
||||
"intent": "CommunicationPreference",
|
||||
|
|
|
@ -174,11 +174,6 @@
|
|||
"intent": "CreateAlarm",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "delete the {alarmTime} alarm",
|
||||
"intent": "DeleteAlarm",
|
||||
"entities": []
|
||||
},
|
||||
{
|
||||
"text": "set phone call as my communication preference",
|
||||
"intent": "CommunicationPreference",
|
||||
|
|
Загрузка…
Ссылка в новой задаче