From 3a8c75d7a829b0f1a4970cc53ba4043a403bf5ee Mon Sep 17 00:00:00 2001 From: alwx Date: Mon, 2 Nov 2020 16:00:48 +0100 Subject: [PATCH 01/15] Updated DialogFlow project --- data/examples/dialogflow/agent.json | 30 +++- .../examples/dialogflow/entities/cuisine.json | 4 +- .../dialogflow/entities/flightNumber.json | 9 + .../entities/flightNumber_entries_en.json | 8 + .../dialogflow/entities/location.json | 4 +- .../intents/Default Fallback Intent.json | 21 ++- data/examples/dialogflow/intents/affirm.json | 28 ++- .../intents/affirm_usersays_en.json | 7 + .../intents/affirm_usersays_es.json | 21 ++- data/examples/dialogflow/intents/goodbye.json | 26 ++- .../intents/goodbye_usersays_en.json | 5 + .../intents/goodbye_usersays_es.json | 15 +- data/examples/dialogflow/intents/hi.json | 72 ++------ .../dialogflow/intents/hi_usersays_en.json | 103 +++++++++-- .../dialogflow/intents/hi_usersays_es.json | 101 +++++++++-- data/examples/dialogflow/intents/inform.json | 165 ++++-------------- .../intents/inform_usersays_en.json | 19 +- .../intents/inform_usersays_es.json | 33 ++-- 18 files changed, 402 insertions(+), 269 deletions(-) create mode 100644 data/examples/dialogflow/entities/flightNumber.json create mode 100644 data/examples/dialogflow/entities/flightNumber_entries_en.json diff --git a/data/examples/dialogflow/agent.json b/data/examples/dialogflow/agent.json index 4c6d05a36360..c4e89bc85b46 100644 --- a/data/examples/dialogflow/agent.json +++ b/data/examples/dialogflow/agent.json @@ -1,6 +1,11 @@ { "description": "", "language": "en", + "shortDescription": "", + "examples": "", + "linkToDocs": "", + "disableInteractionLogs": false, + "disableStackdriverLogs": true, "googleAssistant": { "googleAssistantCompatible": false, "project": "rasanlu-development", @@ -10,23 +15,40 @@ "endIntentIds": [], "oAuthLinking": { "required": false, + "providerId": "", + "authorizationUrl": "", + "tokenUrl": "", + "scopes": "", + "privacyPolicyUrl": "", "grantType": "AUTH_CODE_GRANT" }, "voiceType": "MALE_1", "capabilities": [], - "protocolVersion": "V2" + "env": "", + "protocolVersion": "V2", + "autoPreviewEnabled": false, + "isDeviceAgent": false }, "defaultTimezone": "Asia/Hong_Kong", "webhook": { + "url": "", + "username": "", + "headers": {}, "available": false, "useForDomains": false, "cloudFunctionsEnabled": false, "cloudFunctionsInitialized": false }, "isPrivate": true, - "customClassifierMode": "use.after", "mlMinConfidence": 0.3, "supportedLanguages": [ "es" - ] -} \ No newline at end of file + ], + "enableOnePlatformApi": true, + "onePlatformApiVersion": "v2", + "analyzeQueryTextSentiment": false, + "enabledKnowledgeBaseNames": [], + "knowledgeServiceConfidenceAdjustment": 0.0, + "dialogBuilderMode": false, + "baseActionPackagesUrl": "" +} diff --git a/data/examples/dialogflow/entities/cuisine.json b/data/examples/dialogflow/entities/cuisine.json index 0985a4491258..00368e9820e8 100644 --- a/data/examples/dialogflow/entities/cuisine.json +++ b/data/examples/dialogflow/entities/cuisine.json @@ -3,5 +3,7 @@ "name": "cuisine", "isOverridable": true, "isEnum": false, - "automatedExpansion": false + "isRegexp": false, + "automatedExpansion": false, + "allowFuzzyExtraction": false } \ No newline at end of file diff --git a/data/examples/dialogflow/entities/flightNumber.json b/data/examples/dialogflow/entities/flightNumber.json new file mode 100644 index 000000000000..1ca9c7be4b9a --- /dev/null +++ b/data/examples/dialogflow/entities/flightNumber.json @@ -0,0 +1,9 @@ +{ + "id": "fc93d510-e240-4b71-bafe-7dd7a3303e79", + "name": "flightNumber", + "isOverridable": true, + "isEnum": true, + "isRegexp": false, + "automatedExpansion": false, + "allowFuzzyExtraction": false +} \ No newline at end of file diff --git a/data/examples/dialogflow/entities/flightNumber_entries_en.json b/data/examples/dialogflow/entities/flightNumber_entries_en.json new file mode 100644 index 000000000000..6979eeba5414 --- /dev/null +++ b/data/examples/dialogflow/entities/flightNumber_entries_en.json @@ -0,0 +1,8 @@ +[ + { + "value": "flight [A-Z]{2} [0-9]{4}", + "synonyms": [ + "flight [A-Z]{2} [0-9]{4}" + ] + } +] \ No newline at end of file diff --git a/data/examples/dialogflow/entities/location.json b/data/examples/dialogflow/entities/location.json index 10a5d548cce2..4a1e504a5510 100644 --- a/data/examples/dialogflow/entities/location.json +++ b/data/examples/dialogflow/entities/location.json @@ -3,5 +3,7 @@ "name": "location", "isOverridable": true, "isEnum": false, - "automatedExpansion": false + "isRegexp": false, + "automatedExpansion": false, + "allowFuzzyExtraction": false } \ No newline at end of file diff --git a/data/examples/dialogflow/intents/Default Fallback Intent.json b/data/examples/dialogflow/intents/Default Fallback Intent.json index ea4a696d3b4a..b3b72d9d999a 100644 --- a/data/examples/dialogflow/intents/Default Fallback Intent.json +++ b/data/examples/dialogflow/intents/Default Fallback Intent.json @@ -11,7 +11,9 @@ "parameters": [], "messages": [ { - "type": 0, + "type": "0", + "title": "", + "textToSpeech": "", "lang": "es", "speech": [ "Ups, no he entendido a que te refieres.", @@ -19,10 +21,13 @@ "¿Disculpa?", "¿Decías?", "¿Cómo?" - ] + ], + "condition": "" }, { - "type": 0, + "type": "0", + "title": "", + "textToSpeech": "", "lang": "en", "speech": [ "I didn\u0027t get that. Can you say it again?", @@ -37,17 +42,19 @@ "Say that again?", "I didn\u0027t get that.", "I missed that." - ] + ], + "condition": "" } ], - "defaultResponsePlatforms": {}, "speech": [] } ], "priority": 500000, "webhookUsed": false, "webhookForSlotFilling": false, - "lastUpdate": 1507539905, "fallbackIntent": true, - "events": [] + "events": [], + "conditionalResponses": [], + "condition": "", + "conditionalFollowupEvents": [] } \ No newline at end of file diff --git a/data/examples/dialogflow/intents/affirm.json b/data/examples/dialogflow/intents/affirm.json index b4be30f4cb62..879bd0e83ef1 100644 --- a/data/examples/dialogflow/intents/affirm.json +++ b/data/examples/dialogflow/intents/affirm.json @@ -6,28 +6,40 @@ "responses": [ { "resetContexts": false, + "action": "", "affectedContexts": [], "parameters": [], "messages": [ { - "type": 0, + "type": "0", + "title": "", + "textToSpeech": "", "lang": "es", - "speech": "Me alegro de ayudarte, compañero :)" + "speech": [ + "Me alegro de ayudarte, compañero :)" + ], + "condition": "" }, { - "type": 0, + "type": "0", + "title": "", + "textToSpeech": "", "lang": "en", - "speech": "Glad I help you, mate :)" + "speech": [ + "Glad I help you, mate :)" + ], + "condition": "" } ], - "defaultResponsePlatforms": {}, "speech": [] } ], "priority": 500000, "webhookUsed": false, "webhookForSlotFilling": false, - "lastUpdate": 1507540481, "fallbackIntent": false, - "events": [] -} \ No newline at end of file + "events": [], + "conditionalResponses": [], + "condition": "", + "conditionalFollowupEvents": [] +} diff --git a/data/examples/dialogflow/intents/affirm_usersays_en.json b/data/examples/dialogflow/intents/affirm_usersays_en.json index 6478b9fd6696..69a1cd7c988c 100644 --- a/data/examples/dialogflow/intents/affirm_usersays_en.json +++ b/data/examples/dialogflow/intents/affirm_usersays_en.json @@ -9,6 +9,7 @@ ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { @@ -21,6 +22,7 @@ ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { @@ -33,6 +35,7 @@ ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { @@ -45,6 +48,7 @@ ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { @@ -57,6 +61,7 @@ ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { @@ -69,6 +74,7 @@ ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { @@ -81,6 +87,7 @@ ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 } ] \ No newline at end of file diff --git a/data/examples/dialogflow/intents/affirm_usersays_es.json b/data/examples/dialogflow/intents/affirm_usersays_es.json index 25be9c534b69..c904158e5f7b 100644 --- a/data/examples/dialogflow/intents/affirm_usersays_es.json +++ b/data/examples/dialogflow/intents/affirm_usersays_es.json @@ -9,7 +9,8 @@ ], "isTemplate": false, "count": 0, - "updated": 1507540481 + "lang": "es", + "updated": 0 }, { "id": "9dg52d2a-dbf2-44e7-bc55-0eee5a6a8a14", @@ -21,7 +22,8 @@ ], "isTemplate": false, "count": 0, - "updated": 1507540481 + "lang": "es", + "updated": 0 }, { "id": "9dg52d2a-dbf2-44e7-bc55-0eee5a6a8a24", @@ -33,7 +35,8 @@ ], "isTemplate": false, "count": 0, - "updated": 1507540481 + "lang": "es", + "updated": 0 }, { "id": "7a11df78-3b06-48c3-9aa4-9f779c23fb0b", @@ -45,7 +48,8 @@ ], "isTemplate": false, "count": 0, - "updated": 1507540481 + "lang": "es", + "updated": 0 }, { "id": "e6238a3e-3dcd-4932-9034-1a05f037d4e3", @@ -57,7 +61,8 @@ ], "isTemplate": false, "count": 0, - "updated": 1507540481 + "lang": "es", + "updated": 0 }, { "id": "64cc393a-f9c9-4521-9052-543f99fcd97e", @@ -69,7 +74,8 @@ ], "isTemplate": false, "count": 0, - "updated": 1507540481 + "lang": "es", + "updated": 0 }, { "id": "0f4a932a-c929-47d4-8cb2-5095882f40a0", @@ -81,6 +87,7 @@ ], "isTemplate": false, "count": 0, - "updated": 1507540481 + "lang": "es", + "updated": 0 } ] \ No newline at end of file diff --git a/data/examples/dialogflow/intents/goodbye.json b/data/examples/dialogflow/intents/goodbye.json index a10977966b53..d87084462059 100644 --- a/data/examples/dialogflow/intents/goodbye.json +++ b/data/examples/dialogflow/intents/goodbye.json @@ -6,28 +6,40 @@ "responses": [ { "resetContexts": false, + "action": "", "affectedContexts": [], "parameters": [], "messages": [ { - "type": 0, + "type": "0", + "title": "", + "textToSpeech": "", "lang": "es", - "speech": "¡Nos vemos! Disfrutar" + "speech": [ + "¡Nos vemos! Disfrutar" + ], + "condition": "" }, { - "type": 0, + "type": "0", + "title": "", + "textToSpeech": "", "lang": "en", - "speech": "See ya! Enjoy" + "speech": [ + "See ya! Enjoy" + ], + "condition": "" } ], - "defaultResponsePlatforms": {}, "speech": [] } ], "priority": 500000, "webhookUsed": false, "webhookForSlotFilling": false, - "lastUpdate": 1507540635, "fallbackIntent": false, - "events": [] + "events": [], + "conditionalResponses": [], + "condition": "", + "conditionalFollowupEvents": [] } \ No newline at end of file diff --git a/data/examples/dialogflow/intents/goodbye_usersays_en.json b/data/examples/dialogflow/intents/goodbye_usersays_en.json index fd10363fb123..721c17036c32 100644 --- a/data/examples/dialogflow/intents/goodbye_usersays_en.json +++ b/data/examples/dialogflow/intents/goodbye_usersays_en.json @@ -9,6 +9,7 @@ ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { @@ -21,6 +22,7 @@ ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { @@ -33,6 +35,7 @@ ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { @@ -45,6 +48,7 @@ ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { @@ -57,6 +61,7 @@ ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 } ] \ No newline at end of file diff --git a/data/examples/dialogflow/intents/goodbye_usersays_es.json b/data/examples/dialogflow/intents/goodbye_usersays_es.json index 4a78e70af081..d877b3125861 100644 --- a/data/examples/dialogflow/intents/goodbye_usersays_es.json +++ b/data/examples/dialogflow/intents/goodbye_usersays_es.json @@ -9,7 +9,8 @@ ], "isTemplate": false, "count": 0, - "updated": 1507540635 + "lang": "es", + "updated": 0 }, { "id": "86811b69-cee1-4ae0-8944-ace8eb4badc2", @@ -21,7 +22,8 @@ ], "isTemplate": false, "count": 0, - "updated": 1507540635 + "lang": "es", + "updated": 0 }, { "id": "78bbd720-b50b-4cb9-9dce-eee0fef5aa74", @@ -33,7 +35,8 @@ ], "isTemplate": false, "count": 0, - "updated": 1507540635 + "lang": "es", + "updated": 0 }, { "id": "74597c31-b649-49cc-bd3b-9a4ed3487070", @@ -45,7 +48,8 @@ ], "isTemplate": false, "count": 0, - "updated": 1507540635 + "lang": "es", + "updated": 0 }, { "id": "7b42db30-d815-46fd-a7f5-79b9180c7c6b", @@ -57,6 +61,7 @@ ], "isTemplate": false, "count": 0, - "updated": 1507540635 + "lang": "es", + "updated": 0 } ] \ No newline at end of file diff --git a/data/examples/dialogflow/intents/hi.json b/data/examples/dialogflow/intents/hi.json index 2c14587ee55e..468e33058a0e 100644 --- a/data/examples/dialogflow/intents/hi.json +++ b/data/examples/dialogflow/intents/hi.json @@ -3,58 +3,6 @@ "name": "hi", "auto": true, "contexts": [], - "userSays": [ - { - "id": "6a29da7f-3926-4b68-aa6d-dbbfe1c6b79d", - "data": [ - { - "text": "hi" - } - ], - "isTemplate": false, - "count": 0 - }, - { - "id": "a83ef752-c2fe-4d45-abd4-35bc381f6d96", - "data": [ - { - "text": "hello" - } - ], - "isTemplate": false, - "count": 0 - }, - { - "id": "91c4267d-5e30-4d45-9ce3-d0b21836c372", - "data": [ - { - "text": "hey there" - } - ], - "isTemplate": false, - "count": 0 - }, - { - "id": "4b41d389-8bf7-4976-97ea-3b39a3e883ab", - "data": [ - { - "text": "howdy" - } - ], - "isTemplate": false, - "count": 0 - }, - { - "id": "d819385a-a9c8-4dd0-9787-9a47c53156f3", - "data": [ - { - "text": "hey" - } - ], - "isTemplate": false, - "count": 0 - } - ], "responses": [ { "resetContexts": false, @@ -63,13 +11,25 @@ "parameters": [], "messages": [ { - "type": 0, - "speech": "hey! how can I help you?" + "type": "0", + "title": "", + "textToSpeech": "", + "lang": "en", + "speech": [ + "hey! how can I help you?" + ], + "condition": "" } - ] + ], + "speech": [] } ], "priority": 500000, "webhookUsed": false, - "fallbackIntent": false + "webhookForSlotFilling": false, + "fallbackIntent": false, + "events": [], + "conditionalResponses": [], + "condition": "", + "conditionalFollowupEvents": [] } \ No newline at end of file diff --git a/data/examples/dialogflow/intents/hi_usersays_en.json b/data/examples/dialogflow/intents/hi_usersays_en.json index a4f42c7b3c32..bee317d509a0 100644 --- a/data/examples/dialogflow/intents/hi_usersays_en.json +++ b/data/examples/dialogflow/intents/hi_usersays_en.json @@ -1,62 +1,145 @@ [ { - "id": "462fb0f5-d97a-4a95-96ab-91f49f289676", + "id": "e623ff79-8f24-40bf-a6ed-5a885d9af6c8", "data": [ { - "text": "hey", + "text": "i\u0027m looking for a place to eat", "userDefined": false } ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { - "id": "651c6730-61e8-467b-a174-aca4e0ed66af", + "id": "a3e1901a-6c84-402c-a5a4-e2ec05307aa9", "data": [ { - "text": "howdy", + "text": "i\u0027m looking for a place in the ", + "userDefined": false + }, + { + "text": "north", + "meta": "@location", + "alias": "location", + "userDefined": false + }, + { + "text": " of", + "userDefined": false + } + ], + "isTemplate": false, + "count": 0, + "lang": "en", + "updated": 0 + }, + { + "id": "fbf1e1b3-da86-4bbf-98b4-85e09f14c7b2", + "data": [ + { + "text": "show me ", + "userDefined": false + }, + { + "text": "chinese", + "meta": "@cuisine", + "alias": "cuisine", + "userDefined": false + }, + { + "text": " restaurants", + "userDefined": false + } + ], + "isTemplate": false, + "count": 0, + "lang": "en", + "updated": 0 + }, + { + "id": "860619cb-6c78-41b9-882d-d105a51e4377", + "data": [ + { + "text": "i am looking for an ", + "userDefined": false + }, + { + "text": "indian", + "meta": "@cuisine", + "alias": "cuisine", + "userDefined": false + }, + { + "text": " spot", "userDefined": false } ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { - "id": "bab1998d-d54f-4a5f-9ed2-c7e8b24f37fc", + "id": "a8b9fa75-19db-49ef-963b-50d316a14aa2", "data": [ { - "text": "hey there", + "text": "search for restaurants", "userDefined": false } ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { - "id": "9dfc509d-4f0e-4723-af4a-10ceef2fbf91", + "id": "c91a0223-e109-4d32-aab0-4008fb0a9f35", "data": [ { - "text": "hello", + "text": "anywhere in the ", + "userDefined": false + }, + { + "text": "west", + "meta": "@location", + "alias": "location", "userDefined": false } ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { - "id": "a2271775-488e-4223-9ff4-458cfe4d2ba8", + "id": "34c28215-f492-44d6-88a9-779ff59cb301", "data": [ { - "text": "hi", + "text": "central", + "meta": "@location", + "alias": "location", + "userDefined": false + }, + { + "text": " ", + "userDefined": false + }, + { + "text": "indian", + "meta": "@cuisine", + "alias": "cuisine", + "userDefined": false + }, + { + "text": " restaurant", "userDefined": false } ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 } ] \ No newline at end of file diff --git a/data/examples/dialogflow/intents/hi_usersays_es.json b/data/examples/dialogflow/intents/hi_usersays_es.json index 453a2874ebd3..6a7ba5aada32 100644 --- a/data/examples/dialogflow/intents/hi_usersays_es.json +++ b/data/examples/dialogflow/intents/hi_usersays_es.json @@ -1,62 +1,133 @@ [ { - "id": "40c60a12-1079-4e2c-a7c3-3498ab00de30", + "id": "b3ecd39d-4eec-435d-a0fe-6cfd29412ad7", "data": [ { - "text": "hello", + "text": "estoy buscando un lugar para comer", "userDefined": false } ], "isTemplate": false, "count": 0, - "updated": 1507540781 + "lang": "es", + "updated": 0 }, { - "id": "96019dea-5810-4ce0-9f69-16c2ce012603", + "id": "5a25e429-a00a-4418-a48b-7d019eca3ac6", "data": [ { - "text": "Hola amigo", + "text": "busco un lugar en el ", + "userDefined": false + }, + { + "text": "norte", + "meta": "@location", + "alias": "location", + "userDefined": false + } + ], + "isTemplate": false, + "count": 0, + "lang": "es", + "updated": 0 + }, + { + "id": "8b6fcd21-8e95-46ff-a841-54c59c650571", + "data": [ + { + "text": "muéstrame los restaurantes ", + "userDefined": false + }, + { + "text": "chinos", + "meta": "@cuisine", + "alias": "cuisine", + "userDefined": true + } + ], + "isTemplate": false, + "count": 1, + "lang": "es", + "updated": 0 + }, + { + "id": "86992625-d848-47de-8220-f9a7d5ddf63b", + "data": [ + { + "text": "estoy buscando un lugar ", + "userDefined": false + }, + { + "text": "indio", + "meta": "@cuisine", + "alias": "cuisine", "userDefined": false } ], "isTemplate": false, "count": 0, - "updated": 1507540781 + "lang": "es", + "updated": 0 }, { - "id": "298a54d1-c80c-4542-b41f-2cb549db814c", + "id": "2c5ce034-f89b-4570-a7eb-7bee714902df", "data": [ { - "text": "Bueno", + "text": "buscar restaurantes", "userDefined": false } ], "isTemplate": false, "count": 0, - "updated": 1507540781 + "lang": "es", + "updated": 0 }, { - "id": "0f490459-85df-4865-abd0-70f87f62890e", + "id": "93ce3697-b53f-4e96-bea1-9de96b098ec4", "data": [ { - "text": "Caramba", + "text": "en cualquier parte del ", + "userDefined": false + }, + { + "text": "oeste", + "meta": "@location", + "alias": "location", "userDefined": false } ], "isTemplate": false, "count": 0, - "updated": 1507540781 + "lang": "es", + "updated": 0 }, { - "id": "1bf90b9b-fe34-42ae-96ea-21beaa3fca4f", + "id": "6190aae9-a23f-4d8a-9a50-84a9d971d3f0", "data": [ { - "text": "Hola", + "text": "restaurante ", + "userDefined": false + }, + { + "text": "central", + "meta": "@location", + "alias": "location", + "userDefined": false + }, + { + "text": " de la ", + "userDefined": false + }, + { + "text": "India", + "meta": "@cuisine", + "alias": "cuisine", "userDefined": false } ], "isTemplate": false, "count": 0, - "updated": 1507540781 + "lang": "es", + "updated": 0 } ] \ No newline at end of file diff --git a/data/examples/dialogflow/intents/inform.json b/data/examples/dialogflow/intents/inform.json index 80c215c77746..02f94ea55e0f 100644 --- a/data/examples/dialogflow/intents/inform.json +++ b/data/examples/dialogflow/intents/inform.json @@ -3,153 +3,60 @@ "name": "inform", "auto": true, "contexts": [], - "userSays": [ - { - "id": "d5562a99-f039-4bc7-a1bd-53d6cc811206", - "data": [ - { - "text": "central", - "alias": "location", - "meta": "@location", - "userDefined": false - }, - { - "text": " " - }, - { - "text": "indian", - "alias": "cuisine", - "meta": "@cuisine", - "userDefined": true - }, - { - "text": " restaurant" - } - ], - "isTemplate": false, - "count": 0 - }, - { - "id": "5e043d29-a4ce-4642-a191-e287d397b02f", - "data": [ - { - "text": "anywhere in the " - }, - { - "text": "west", - "alias": "location", - "meta": "@location", - "userDefined": false - } - ], - "isTemplate": false, - "count": 0 - }, - { - "id": "540cbb16-4c62-4bc7-b3f2-8f1107e65471", - "data": [ - { - "text": "search for restaurants" - } - ], - "isTemplate": false, - "count": 0 - }, - { - "id": "cb096268-a8e5-49d5-8771-60bb1a511151", - "data": [ - { - "text": "i am looking for an " - }, - { - "text": "indian", - "alias": "cuisine", - "meta": "@cuisine", - "userDefined": true - }, - { - "text": " spot" - } - ], - "isTemplate": false, - "count": 0 - }, - { - "id": "2cf1b035-62f1-40cd-867c-af92cbbaf5c7", - "data": [ - { - "text": "show me " - }, - { - "text": "chinese", - "alias": "cuisine", - "meta": "@cuisine", - "userDefined": true - }, - { - "text": " restaurants" - } - ], - "isTemplate": false, - "count": 0 - }, - { - "id": "51f618be-e5a9-4007-a0d5-d6f12475a9b1", - "data": [ - { - "text": "i\u0027m looking for a place in the " - }, - { - "text": "north", - "alias": "location", - "meta": "@location", - "userDefined": true - }, - { - "text": " of " - } - ], - "isTemplate": false, - "count": 0 - }, - { - "id": "20a723ce-1efc-4c03-84ec-ee17c3219329", - "data": [ - { - "text": "i\u0027m looking for a place to eat" - } - ], - "isTemplate": false, - "count": 0 - } - ], "responses": [ { "resetContexts": false, + "action": "", "affectedContexts": [], "parameters": [ { - "dataType": "@location", "name": "location", + "required": false, + "dataType": "@location", "value": "$location", - "isList": true + "defaultValue": "", + "isList": true, + "prompts": [], + "promptMessages": [], + "noMatchPromptMessages": [], + "noInputPromptMessages": [], + "outputDialogContexts": [] }, { - "dataType": "@cuisine", "name": "cuisine", + "required": false, + "dataType": "@cuisine", "value": "$cuisine", - "isList": false + "defaultValue": "", + "isList": false, + "prompts": [], + "promptMessages": [], + "noMatchPromptMessages": [], + "noInputPromptMessages": [], + "outputDialogContexts": [] } ], "messages": [ { - "type": 0, - "speech": "Here is a great spot I am sure you\u0027ll like, pal!" + "type": "0", + "title": "", + "textToSpeech": "", + "lang": "en", + "speech": [ + "Here is a great spot I am sure you\u0027ll like, pal!" + ], + "condition": "" } - ] + ], + "speech": [] } ], "priority": 500000, "webhookUsed": false, - "fallbackIntent": false -} + "webhookForSlotFilling": false, + "fallbackIntent": false, + "events": [], + "conditionalResponses": [], + "condition": "", + "conditionalFollowupEvents": [] +} \ No newline at end of file diff --git a/data/examples/dialogflow/intents/inform_usersays_en.json b/data/examples/dialogflow/intents/inform_usersays_en.json index a07d59d5bc77..bee317d509a0 100644 --- a/data/examples/dialogflow/intents/inform_usersays_en.json +++ b/data/examples/dialogflow/intents/inform_usersays_en.json @@ -9,6 +9,7 @@ ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { @@ -20,8 +21,8 @@ }, { "text": "north", - "alias": "location", "meta": "@location", + "alias": "location", "userDefined": false }, { @@ -31,6 +32,7 @@ ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { @@ -42,8 +44,8 @@ }, { "text": "chinese", - "alias": "cuisine", "meta": "@cuisine", + "alias": "cuisine", "userDefined": false }, { @@ -53,6 +55,7 @@ ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { @@ -64,8 +67,8 @@ }, { "text": "indian", - "alias": "cuisine", "meta": "@cuisine", + "alias": "cuisine", "userDefined": false }, { @@ -75,6 +78,7 @@ ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { @@ -87,6 +91,7 @@ ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { @@ -98,13 +103,14 @@ }, { "text": "west", - "alias": "location", "meta": "@location", + "alias": "location", "userDefined": false } ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 }, { @@ -112,8 +118,8 @@ "data": [ { "text": "central", - "alias": "location", "meta": "@location", + "alias": "location", "userDefined": false }, { @@ -122,8 +128,8 @@ }, { "text": "indian", - "alias": "cuisine", "meta": "@cuisine", + "alias": "cuisine", "userDefined": false }, { @@ -133,6 +139,7 @@ ], "isTemplate": false, "count": 0, + "lang": "en", "updated": 0 } ] \ No newline at end of file diff --git a/data/examples/dialogflow/intents/inform_usersays_es.json b/data/examples/dialogflow/intents/inform_usersays_es.json index af9ea6b36a81..6a7ba5aada32 100644 --- a/data/examples/dialogflow/intents/inform_usersays_es.json +++ b/data/examples/dialogflow/intents/inform_usersays_es.json @@ -9,7 +9,8 @@ ], "isTemplate": false, "count": 0, - "updated": 1507541018 + "lang": "es", + "updated": 0 }, { "id": "5a25e429-a00a-4418-a48b-7d019eca3ac6", @@ -20,14 +21,15 @@ }, { "text": "norte", - "alias": "location", "meta": "@location", + "alias": "location", "userDefined": false } ], "isTemplate": false, "count": 0, - "updated": 1507541018 + "lang": "es", + "updated": 0 }, { "id": "8b6fcd21-8e95-46ff-a841-54c59c650571", @@ -38,14 +40,15 @@ }, { "text": "chinos", - "alias": "cuisine", "meta": "@cuisine", + "alias": "cuisine", "userDefined": true } ], "isTemplate": false, "count": 1, - "updated": 1507541018 + "lang": "es", + "updated": 0 }, { "id": "86992625-d848-47de-8220-f9a7d5ddf63b", @@ -56,14 +59,15 @@ }, { "text": "indio", - "alias": "cuisine", "meta": "@cuisine", + "alias": "cuisine", "userDefined": false } ], "isTemplate": false, "count": 0, - "updated": 1507541018 + "lang": "es", + "updated": 0 }, { "id": "2c5ce034-f89b-4570-a7eb-7bee714902df", @@ -75,7 +79,8 @@ ], "isTemplate": false, "count": 0, - "updated": 1507540897 + "lang": "es", + "updated": 0 }, { "id": "93ce3697-b53f-4e96-bea1-9de96b098ec4", @@ -86,14 +91,15 @@ }, { "text": "oeste", - "alias": "location", "meta": "@location", + "alias": "location", "userDefined": false } ], "isTemplate": false, "count": 0, - "updated": 1507540897 + "lang": "es", + "updated": 0 }, { "id": "6190aae9-a23f-4d8a-9a50-84a9d971d3f0", @@ -104,8 +110,8 @@ }, { "text": "central", - "alias": "location", "meta": "@location", + "alias": "location", "userDefined": false }, { @@ -114,13 +120,14 @@ }, { "text": "India", - "alias": "cuisine", "meta": "@cuisine", + "alias": "cuisine", "userDefined": false } ], "isTemplate": false, "count": 0, - "updated": 1507540897 + "lang": "es", + "updated": 0 } ] \ No newline at end of file From 28b7ebfd574b03142f4edd5cd6bce19523616f37 Mon Sep 17 00:00:00 2001 From: alwx Date: Mon, 2 Nov 2020 16:14:37 +0100 Subject: [PATCH 02/15] Updated regex entity --- data/examples/dialogflow/entities/flightNumber.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/examples/dialogflow/entities/flightNumber.json b/data/examples/dialogflow/entities/flightNumber.json index 1ca9c7be4b9a..5493d52270ea 100644 --- a/data/examples/dialogflow/entities/flightNumber.json +++ b/data/examples/dialogflow/entities/flightNumber.json @@ -2,7 +2,7 @@ "id": "fc93d510-e240-4b71-bafe-7dd7a3303e79", "name": "flightNumber", "isOverridable": true, - "isEnum": true, + "isEnum": false, "isRegexp": false, "automatedExpansion": false, "allowFuzzyExtraction": false From dc8a28911a880945c9f978fb36153937e3cbae9c Mon Sep 17 00:00:00 2001 From: alwx Date: Mon, 2 Nov 2020 16:29:35 +0100 Subject: [PATCH 03/15] Regex features (1) --- data/examples/old_affirm.json | 33 ++++ data/examples/old_inform.json | 155 ++++++++++++++++++ .../nlu/training_data/formats/dialogflow.py | 5 +- 3 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 data/examples/old_affirm.json create mode 100644 data/examples/old_inform.json diff --git a/data/examples/old_affirm.json b/data/examples/old_affirm.json new file mode 100644 index 000000000000..b4be30f4cb62 --- /dev/null +++ b/data/examples/old_affirm.json @@ -0,0 +1,33 @@ +{ + "id": "c2e82a05-3980-4f74-b0d5-7ee0e1297284", + "name": "affirm", + "auto": true, + "contexts": [], + "responses": [ + { + "resetContexts": false, + "affectedContexts": [], + "parameters": [], + "messages": [ + { + "type": 0, + "lang": "es", + "speech": "Me alegro de ayudarte, compañero :)" + }, + { + "type": 0, + "lang": "en", + "speech": "Glad I help you, mate :)" + } + ], + "defaultResponsePlatforms": {}, + "speech": [] + } + ], + "priority": 500000, + "webhookUsed": false, + "webhookForSlotFilling": false, + "lastUpdate": 1507540481, + "fallbackIntent": false, + "events": [] +} \ No newline at end of file diff --git a/data/examples/old_inform.json b/data/examples/old_inform.json new file mode 100644 index 000000000000..80c215c77746 --- /dev/null +++ b/data/examples/old_inform.json @@ -0,0 +1,155 @@ +{ + "id": "fd566317-b15d-4685-9158-63028b6fb5bf", + "name": "inform", + "auto": true, + "contexts": [], + "userSays": [ + { + "id": "d5562a99-f039-4bc7-a1bd-53d6cc811206", + "data": [ + { + "text": "central", + "alias": "location", + "meta": "@location", + "userDefined": false + }, + { + "text": " " + }, + { + "text": "indian", + "alias": "cuisine", + "meta": "@cuisine", + "userDefined": true + }, + { + "text": " restaurant" + } + ], + "isTemplate": false, + "count": 0 + }, + { + "id": "5e043d29-a4ce-4642-a191-e287d397b02f", + "data": [ + { + "text": "anywhere in the " + }, + { + "text": "west", + "alias": "location", + "meta": "@location", + "userDefined": false + } + ], + "isTemplate": false, + "count": 0 + }, + { + "id": "540cbb16-4c62-4bc7-b3f2-8f1107e65471", + "data": [ + { + "text": "search for restaurants" + } + ], + "isTemplate": false, + "count": 0 + }, + { + "id": "cb096268-a8e5-49d5-8771-60bb1a511151", + "data": [ + { + "text": "i am looking for an " + }, + { + "text": "indian", + "alias": "cuisine", + "meta": "@cuisine", + "userDefined": true + }, + { + "text": " spot" + } + ], + "isTemplate": false, + "count": 0 + }, + { + "id": "2cf1b035-62f1-40cd-867c-af92cbbaf5c7", + "data": [ + { + "text": "show me " + }, + { + "text": "chinese", + "alias": "cuisine", + "meta": "@cuisine", + "userDefined": true + }, + { + "text": " restaurants" + } + ], + "isTemplate": false, + "count": 0 + }, + { + "id": "51f618be-e5a9-4007-a0d5-d6f12475a9b1", + "data": [ + { + "text": "i\u0027m looking for a place in the " + }, + { + "text": "north", + "alias": "location", + "meta": "@location", + "userDefined": true + }, + { + "text": " of " + } + ], + "isTemplate": false, + "count": 0 + }, + { + "id": "20a723ce-1efc-4c03-84ec-ee17c3219329", + "data": [ + { + "text": "i\u0027m looking for a place to eat" + } + ], + "isTemplate": false, + "count": 0 + } + ], + "responses": [ + { + "resetContexts": false, + "affectedContexts": [], + "parameters": [ + { + "dataType": "@location", + "name": "location", + "value": "$location", + "isList": true + }, + { + "dataType": "@cuisine", + "name": "cuisine", + "value": "$cuisine", + "isList": false + } + ], + "messages": [ + { + "type": 0, + "speech": "Here is a great spot I am sure you\u0027ll like, pal!" + } + ] + } + ], + "priority": 500000, + "webhookUsed": false, + "fallbackIntent": false +} diff --git a/rasa/shared/nlu/training_data/formats/dialogflow.py b/rasa/shared/nlu/training_data/formats/dialogflow.py index 84704ccb138f..671cb63316a0 100644 --- a/rasa/shared/nlu/training_data/formats/dialogflow.py +++ b/rasa/shared/nlu/training_data/formats/dialogflow.py @@ -116,10 +116,13 @@ def _extract_lookup_tables( @staticmethod def _read_entities(entity_js, examples_js) -> "TrainingData": entity_synonyms = transform_entity_synonyms(examples_js) + regex_features = [] + # TODO: regex features + # TODO: remove old_affirm.json & old_inform.json name = entity_js.get("name") lookup_tables = DialogflowReader._extract_lookup_tables(name, examples_js) - return TrainingData([], entity_synonyms, [], lookup_tables) + return TrainingData([], entity_synonyms, regex_features, lookup_tables,) @staticmethod def _read_examples_js(fn: Text, language: Text, fformat: Text) -> Any: From a8a280043863d7627a1a48c7b62a63a4d41ad6a6 Mon Sep 17 00:00:00 2001 From: alwx Date: Mon, 2 Nov 2020 16:57:10 +0100 Subject: [PATCH 04/15] Training data logic, regex support --- .../dialogflow/entities/flightNumber.json | 2 +- data/examples/dialogflow/intents/affirm.json | 2 +- .../dialogflow/intents/hi_usersays_en.json | 98 ++----------------- .../dialogflow/intents/hi_usersays_es.json | 86 ++-------------- .../nlu/training_data/formats/dialogflow.py | 29 ++++-- .../nlu/training_data/test_training_data.py | 1 + 6 files changed, 42 insertions(+), 176 deletions(-) diff --git a/data/examples/dialogflow/entities/flightNumber.json b/data/examples/dialogflow/entities/flightNumber.json index 5493d52270ea..8551dedb58d6 100644 --- a/data/examples/dialogflow/entities/flightNumber.json +++ b/data/examples/dialogflow/entities/flightNumber.json @@ -3,7 +3,7 @@ "name": "flightNumber", "isOverridable": true, "isEnum": false, - "isRegexp": false, + "isRegexp": true, "automatedExpansion": false, "allowFuzzyExtraction": false } \ No newline at end of file diff --git a/data/examples/dialogflow/intents/affirm.json b/data/examples/dialogflow/intents/affirm.json index 879bd0e83ef1..bf039d1f573e 100644 --- a/data/examples/dialogflow/intents/affirm.json +++ b/data/examples/dialogflow/intents/affirm.json @@ -42,4 +42,4 @@ "conditionalResponses": [], "condition": "", "conditionalFollowupEvents": [] -} +} \ No newline at end of file diff --git a/data/examples/dialogflow/intents/hi_usersays_en.json b/data/examples/dialogflow/intents/hi_usersays_en.json index bee317d509a0..261a08b97bc5 100644 --- a/data/examples/dialogflow/intents/hi_usersays_en.json +++ b/data/examples/dialogflow/intents/hi_usersays_en.json @@ -1,9 +1,9 @@ [ { - "id": "e623ff79-8f24-40bf-a6ed-5a885d9af6c8", + "id": "462fb0f5-d97a-4a95-96ab-91f49f289676", "data": [ { - "text": "i\u0027m looking for a place to eat", + "text": "hey", "userDefined": false } ], @@ -13,66 +13,10 @@ "updated": 0 }, { - "id": "a3e1901a-6c84-402c-a5a4-e2ec05307aa9", + "id": "651c6730-61e8-467b-a174-aca4e0ed66af", "data": [ { - "text": "i\u0027m looking for a place in the ", - "userDefined": false - }, - { - "text": "north", - "meta": "@location", - "alias": "location", - "userDefined": false - }, - { - "text": " of", - "userDefined": false - } - ], - "isTemplate": false, - "count": 0, - "lang": "en", - "updated": 0 - }, - { - "id": "fbf1e1b3-da86-4bbf-98b4-85e09f14c7b2", - "data": [ - { - "text": "show me ", - "userDefined": false - }, - { - "text": "chinese", - "meta": "@cuisine", - "alias": "cuisine", - "userDefined": false - }, - { - "text": " restaurants", - "userDefined": false - } - ], - "isTemplate": false, - "count": 0, - "lang": "en", - "updated": 0 - }, - { - "id": "860619cb-6c78-41b9-882d-d105a51e4377", - "data": [ - { - "text": "i am looking for an ", - "userDefined": false - }, - { - "text": "indian", - "meta": "@cuisine", - "alias": "cuisine", - "userDefined": false - }, - { - "text": " spot", + "text": "howdy", "userDefined": false } ], @@ -82,10 +26,10 @@ "updated": 0 }, { - "id": "a8b9fa75-19db-49ef-963b-50d316a14aa2", + "id": "bab1998d-d54f-4a5f-9ed2-c7e8b24f37fc", "data": [ { - "text": "search for restaurants", + "text": "hey there", "userDefined": false } ], @@ -95,16 +39,10 @@ "updated": 0 }, { - "id": "c91a0223-e109-4d32-aab0-4008fb0a9f35", + "id": "9dfc509d-4f0e-4723-af4a-10ceef2fbf91", "data": [ { - "text": "anywhere in the ", - "userDefined": false - }, - { - "text": "west", - "meta": "@location", - "alias": "location", + "text": "hello", "userDefined": false } ], @@ -114,26 +52,10 @@ "updated": 0 }, { - "id": "34c28215-f492-44d6-88a9-779ff59cb301", + "id": "a2271775-488e-4223-9ff4-458cfe4d2ba8", "data": [ { - "text": "central", - "meta": "@location", - "alias": "location", - "userDefined": false - }, - { - "text": " ", - "userDefined": false - }, - { - "text": "indian", - "meta": "@cuisine", - "alias": "cuisine", - "userDefined": false - }, - { - "text": " restaurant", + "text": "hi", "userDefined": false } ], diff --git a/data/examples/dialogflow/intents/hi_usersays_es.json b/data/examples/dialogflow/intents/hi_usersays_es.json index 6a7ba5aada32..2ad50578f92e 100644 --- a/data/examples/dialogflow/intents/hi_usersays_es.json +++ b/data/examples/dialogflow/intents/hi_usersays_es.json @@ -1,9 +1,9 @@ [ { - "id": "b3ecd39d-4eec-435d-a0fe-6cfd29412ad7", + "id": "40c60a12-1079-4e2c-a7c3-3498ab00de30", "data": [ { - "text": "estoy buscando un lugar para comer", + "text": "hello", "userDefined": false } ], @@ -13,54 +13,10 @@ "updated": 0 }, { - "id": "5a25e429-a00a-4418-a48b-7d019eca3ac6", + "id": "96019dea-5810-4ce0-9f69-16c2ce012603", "data": [ { - "text": "busco un lugar en el ", - "userDefined": false - }, - { - "text": "norte", - "meta": "@location", - "alias": "location", - "userDefined": false - } - ], - "isTemplate": false, - "count": 0, - "lang": "es", - "updated": 0 - }, - { - "id": "8b6fcd21-8e95-46ff-a841-54c59c650571", - "data": [ - { - "text": "muéstrame los restaurantes ", - "userDefined": false - }, - { - "text": "chinos", - "meta": "@cuisine", - "alias": "cuisine", - "userDefined": true - } - ], - "isTemplate": false, - "count": 1, - "lang": "es", - "updated": 0 - }, - { - "id": "86992625-d848-47de-8220-f9a7d5ddf63b", - "data": [ - { - "text": "estoy buscando un lugar ", - "userDefined": false - }, - { - "text": "indio", - "meta": "@cuisine", - "alias": "cuisine", + "text": "Hola amigo", "userDefined": false } ], @@ -70,10 +26,10 @@ "updated": 0 }, { - "id": "2c5ce034-f89b-4570-a7eb-7bee714902df", + "id": "298a54d1-c80c-4542-b41f-2cb549db814c", "data": [ { - "text": "buscar restaurantes", + "text": "Bueno", "userDefined": false } ], @@ -83,16 +39,10 @@ "updated": 0 }, { - "id": "93ce3697-b53f-4e96-bea1-9de96b098ec4", + "id": "0f490459-85df-4865-abd0-70f87f62890e", "data": [ { - "text": "en cualquier parte del ", - "userDefined": false - }, - { - "text": "oeste", - "meta": "@location", - "alias": "location", + "text": "Caramba", "userDefined": false } ], @@ -102,26 +52,10 @@ "updated": 0 }, { - "id": "6190aae9-a23f-4d8a-9a50-84a9d971d3f0", + "id": "1bf90b9b-fe34-42ae-96ea-21beaa3fca4f", "data": [ { - "text": "restaurante ", - "userDefined": false - }, - { - "text": "central", - "meta": "@location", - "alias": "location", - "userDefined": false - }, - { - "text": " de la ", - "userDefined": false - }, - { - "text": "India", - "meta": "@cuisine", - "alias": "cuisine", + "text": "Hola", "userDefined": false } ], diff --git a/rasa/shared/nlu/training_data/formats/dialogflow.py b/rasa/shared/nlu/training_data/formats/dialogflow.py index 671cb63316a0..f864aae4284e 100644 --- a/rasa/shared/nlu/training_data/formats/dialogflow.py +++ b/rasa/shared/nlu/training_data/formats/dialogflow.py @@ -102,27 +102,36 @@ def _flatten(list_of_lists: List[List[Any]]) -> List[Any]: @staticmethod def _extract_lookup_tables( - name: Text, examples: List[Dict[Text, Any]] + entity_js: Dict[Text, Any], examples_js: List[Dict[Text, Any]] ) -> Optional[List[Dict[Text, Any]]]: """Extract the lookup table from the entity synonyms""" - synonyms = [e["synonyms"] for e in examples if "synonyms" in e] + synonyms = [e["synonyms"] for e in examples_js if "synonyms" in e] synonyms = DialogflowReader._flatten(synonyms) elements = [synonym for synonym in synonyms if "@" not in synonym] if len(elements) == 0: return None - return [{"name": name, "elements": elements}] + return [{"name": entity_js.get("name"), "elements": elements}] @staticmethod - def _read_entities(entity_js, examples_js) -> "TrainingData": + def _extract_regex_features( + entity_js: Dict[Text, Any], examples_js: List[Dict[Text, Any]] + ) -> Optional[List[Dict[Text, Any]]]: + """Extract the regex features from the entity synonyms""" + synonyms = [e["synonyms"] for e in examples_js if "synonyms" in e] + synonyms = DialogflowReader._flatten(synonyms) + return [{"name": entity_js.get("name"), "pattern": synonym} for synonym in synonyms] + + @staticmethod + def _read_entities(entity_js: Dict[Text, Any], examples_js: List[Dict[Text, Any]]) -> "TrainingData": entity_synonyms = transform_entity_synonyms(examples_js) - regex_features = [] - # TODO: regex features - # TODO: remove old_affirm.json & old_inform.json - name = entity_js.get("name") - lookup_tables = DialogflowReader._extract_lookup_tables(name, examples_js) - return TrainingData([], entity_synonyms, regex_features, lookup_tables,) + if entity_js["isRegexp"]: + regex_features = DialogflowReader._extract_regex_features(entity_js, examples_js) + return TrainingData([], entity_synonyms, regex_features, [],) + else: + lookup_tables = DialogflowReader._extract_lookup_tables(entity_js, examples_js) + return TrainingData([], entity_synonyms, [], lookup_tables,) @staticmethod def _read_examples_js(fn: Text, language: Text, fformat: Text) -> Any: diff --git a/tests/shared/nlu/training_data/test_training_data.py b/tests/shared/nlu/training_data/test_training_data.py index 46b4bd4a22e2..3d4872d7f26b 100644 --- a/tests/shared/nlu/training_data/test_training_data.py +++ b/tests/shared/nlu/training_data/test_training_data.py @@ -57,6 +57,7 @@ def test_dialogflow_data(): assert len(td.entity_examples) == 5 assert len(td.intent_examples) == 24 assert len(td.training_examples) == 24 + assert len(td.regex_features) == 1 assert len(td.lookup_tables) == 2 assert td.intents == {"affirm", "goodbye", "hi", "inform"} assert td.entities == {"cuisine", "location"} From 71e2aa4d97b1194cfd020bb8c8e51e8d625169c5 Mon Sep 17 00:00:00 2001 From: alwx Date: Mon, 2 Nov 2020 17:19:46 +0100 Subject: [PATCH 05/15] Emulator updates --- rasa/nlu/emulators/dialogflow.py | 26 ++++++++++++------- .../nlu/training_data/formats/dialogflow.py | 6 ++--- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/rasa/nlu/emulators/dialogflow.py b/rasa/nlu/emulators/dialogflow.py index b05f76c6c99e..30a131fdf409 100644 --- a/rasa/nlu/emulators/dialogflow.py +++ b/rasa/nlu/emulators/dialogflow.py @@ -7,11 +7,21 @@ class DialogflowEmulator(Emulator): - """Emulates DialogFlow responses.""" + """Emulates the response format of the DialogFlow projects.agent.environments.users.sessions.detectIntent + + https://cloud.google.com/dialogflow/es/docs/reference/rest/v2/projects.agent.environments.users.sessions/detectIntent + https://cloud.google.com/dialogflow/es/docs/reference/rest/v2/DetectIntentResponse + """ def normalise_response_json(self, data: Dict[Text, Any]) -> Dict[Text, Any]: - """Transform data to Dialogflow format.""" - # populate entities dict + """"Transform response JSON to DialogFlow format. + + Args: + data: input JSON data as a dictionary. + + Returns: + The transformed input data. + """ entities = { entity_type: [] for entity_type in {x["entity"] for x in data["entities"]} } @@ -20,10 +30,8 @@ def normalise_response_json(self, data: Dict[Text, Any]) -> Dict[Text, Any]: entities[entity["entity"]].append(entity["value"]) return { - "id": str(uuid.uuid1()), - "timestamp": datetime.now().isoformat(), - "result": { - "source": "agent", + "responseId": str(uuid.uuid1()), + "queryResult": { "resolvedQuery": data["text"], "action": data["intent"][INTENT_NAME_KEY], "actionIncomplete": False, @@ -36,7 +44,5 @@ def normalise_response_json(self, data: Dict[Text, Any]) -> Dict[Text, Any]: }, "fulfillment": {}, "score": data["intent"]["confidence"], - }, - "status": {"code": 200, "errorType": "success"}, - "sessionId": str(uuid.uuid1()), + } } diff --git a/rasa/shared/nlu/training_data/formats/dialogflow.py b/rasa/shared/nlu/training_data/formats/dialogflow.py index f864aae4284e..c6573045a90d 100644 --- a/rasa/shared/nlu/training_data/formats/dialogflow.py +++ b/rasa/shared/nlu/training_data/formats/dialogflow.py @@ -66,7 +66,6 @@ def _join_text_chunks( self, chunks: List[Dict[Text, Any]] ) -> Tuple[Text, List[Dict[Text, Any]]]: """Combines text chunks and extracts entities.""" - utterance = "" entities = [] for chunk in chunks: @@ -82,7 +81,6 @@ def _extract_entity( chunk: Dict[Text, Any], current_offset: int ) -> Optional[Dict[Text, Any]]: """Extract an entity from a chunk if present.""" - entity = None if "meta" in chunk or "alias" in chunk: start = current_offset @@ -104,7 +102,7 @@ def _flatten(list_of_lists: List[List[Any]]) -> List[Any]: def _extract_lookup_tables( entity_js: Dict[Text, Any], examples_js: List[Dict[Text, Any]] ) -> Optional[List[Dict[Text, Any]]]: - """Extract the lookup table from the entity synonyms""" + """Extract the lookup table from the entity synonyms.""" synonyms = [e["synonyms"] for e in examples_js if "synonyms" in e] synonyms = DialogflowReader._flatten(synonyms) elements = [synonym for synonym in synonyms if "@" not in synonym] @@ -117,7 +115,7 @@ def _extract_lookup_tables( def _extract_regex_features( entity_js: Dict[Text, Any], examples_js: List[Dict[Text, Any]] ) -> Optional[List[Dict[Text, Any]]]: - """Extract the regex features from the entity synonyms""" + """Extract the regex features from the entity synonyms.""" synonyms = [e["synonyms"] for e in examples_js if "synonyms" in e] synonyms = DialogflowReader._flatten(synonyms) return [{"name": entity_js.get("name"), "pattern": synonym} for synonym in synonyms] From 6239a593e910284c7bd38b97dd5d6e8a6b618a9a Mon Sep 17 00:00:00 2001 From: alwx Date: Mon, 2 Nov 2020 18:38:06 +0100 Subject: [PATCH 06/15] Code style updates --- rasa/nlu/emulators/dialogflow.py | 2 +- .../nlu/training_data/formats/dialogflow.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/rasa/nlu/emulators/dialogflow.py b/rasa/nlu/emulators/dialogflow.py index 30a131fdf409..64baeac4d1ff 100644 --- a/rasa/nlu/emulators/dialogflow.py +++ b/rasa/nlu/emulators/dialogflow.py @@ -44,5 +44,5 @@ def normalise_response_json(self, data: Dict[Text, Any]) -> Dict[Text, Any]: }, "fulfillment": {}, "score": data["intent"]["confidence"], - } + }, } diff --git a/rasa/shared/nlu/training_data/formats/dialogflow.py b/rasa/shared/nlu/training_data/formats/dialogflow.py index c6573045a90d..72a102c6ab5d 100644 --- a/rasa/shared/nlu/training_data/formats/dialogflow.py +++ b/rasa/shared/nlu/training_data/formats/dialogflow.py @@ -118,17 +118,25 @@ def _extract_regex_features( """Extract the regex features from the entity synonyms.""" synonyms = [e["synonyms"] for e in examples_js if "synonyms" in e] synonyms = DialogflowReader._flatten(synonyms) - return [{"name": entity_js.get("name"), "pattern": synonym} for synonym in synonyms] + return [ + {"name": entity_js.get("name"), "pattern": synonym} for synonym in synonyms + ] @staticmethod - def _read_entities(entity_js: Dict[Text, Any], examples_js: List[Dict[Text, Any]]) -> "TrainingData": + def _read_entities( + entity_js: Dict[Text, Any], examples_js: List[Dict[Text, Any]] + ) -> "TrainingData": entity_synonyms = transform_entity_synonyms(examples_js) if entity_js["isRegexp"]: - regex_features = DialogflowReader._extract_regex_features(entity_js, examples_js) + regex_features = DialogflowReader._extract_regex_features( + entity_js, examples_js + ) return TrainingData([], entity_synonyms, regex_features, [],) else: - lookup_tables = DialogflowReader._extract_lookup_tables(entity_js, examples_js) + lookup_tables = DialogflowReader._extract_lookup_tables( + entity_js, examples_js + ) return TrainingData([], entity_synonyms, [], lookup_tables,) @staticmethod From b7567775dd65633ab2b04751d551966bc084fb6b Mon Sep 17 00:00:00 2001 From: alwx Date: Mon, 2 Nov 2020 18:54:38 +0100 Subject: [PATCH 07/15] Dialogflow emulator + tests for it --- data/examples/old_affirm.json | 33 ------ data/examples/old_inform.json | 155 ------------------------- rasa/nlu/emulators/dialogflow.py | 38 +++--- tests/nlu/emulators/test_dialogflow.py | 24 ++-- tests/shared/test_data.py | 2 + 5 files changed, 32 insertions(+), 220 deletions(-) delete mode 100644 data/examples/old_affirm.json delete mode 100644 data/examples/old_inform.json diff --git a/data/examples/old_affirm.json b/data/examples/old_affirm.json deleted file mode 100644 index b4be30f4cb62..000000000000 --- a/data/examples/old_affirm.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "id": "c2e82a05-3980-4f74-b0d5-7ee0e1297284", - "name": "affirm", - "auto": true, - "contexts": [], - "responses": [ - { - "resetContexts": false, - "affectedContexts": [], - "parameters": [], - "messages": [ - { - "type": 0, - "lang": "es", - "speech": "Me alegro de ayudarte, compañero :)" - }, - { - "type": 0, - "lang": "en", - "speech": "Glad I help you, mate :)" - } - ], - "defaultResponsePlatforms": {}, - "speech": [] - } - ], - "priority": 500000, - "webhookUsed": false, - "webhookForSlotFilling": false, - "lastUpdate": 1507540481, - "fallbackIntent": false, - "events": [] -} \ No newline at end of file diff --git a/data/examples/old_inform.json b/data/examples/old_inform.json deleted file mode 100644 index 80c215c77746..000000000000 --- a/data/examples/old_inform.json +++ /dev/null @@ -1,155 +0,0 @@ -{ - "id": "fd566317-b15d-4685-9158-63028b6fb5bf", - "name": "inform", - "auto": true, - "contexts": [], - "userSays": [ - { - "id": "d5562a99-f039-4bc7-a1bd-53d6cc811206", - "data": [ - { - "text": "central", - "alias": "location", - "meta": "@location", - "userDefined": false - }, - { - "text": " " - }, - { - "text": "indian", - "alias": "cuisine", - "meta": "@cuisine", - "userDefined": true - }, - { - "text": " restaurant" - } - ], - "isTemplate": false, - "count": 0 - }, - { - "id": "5e043d29-a4ce-4642-a191-e287d397b02f", - "data": [ - { - "text": "anywhere in the " - }, - { - "text": "west", - "alias": "location", - "meta": "@location", - "userDefined": false - } - ], - "isTemplate": false, - "count": 0 - }, - { - "id": "540cbb16-4c62-4bc7-b3f2-8f1107e65471", - "data": [ - { - "text": "search for restaurants" - } - ], - "isTemplate": false, - "count": 0 - }, - { - "id": "cb096268-a8e5-49d5-8771-60bb1a511151", - "data": [ - { - "text": "i am looking for an " - }, - { - "text": "indian", - "alias": "cuisine", - "meta": "@cuisine", - "userDefined": true - }, - { - "text": " spot" - } - ], - "isTemplate": false, - "count": 0 - }, - { - "id": "2cf1b035-62f1-40cd-867c-af92cbbaf5c7", - "data": [ - { - "text": "show me " - }, - { - "text": "chinese", - "alias": "cuisine", - "meta": "@cuisine", - "userDefined": true - }, - { - "text": " restaurants" - } - ], - "isTemplate": false, - "count": 0 - }, - { - "id": "51f618be-e5a9-4007-a0d5-d6f12475a9b1", - "data": [ - { - "text": "i\u0027m looking for a place in the " - }, - { - "text": "north", - "alias": "location", - "meta": "@location", - "userDefined": true - }, - { - "text": " of " - } - ], - "isTemplate": false, - "count": 0 - }, - { - "id": "20a723ce-1efc-4c03-84ec-ee17c3219329", - "data": [ - { - "text": "i\u0027m looking for a place to eat" - } - ], - "isTemplate": false, - "count": 0 - } - ], - "responses": [ - { - "resetContexts": false, - "affectedContexts": [], - "parameters": [ - { - "dataType": "@location", - "name": "location", - "value": "$location", - "isList": true - }, - { - "dataType": "@cuisine", - "name": "cuisine", - "value": "$cuisine", - "isList": false - } - ], - "messages": [ - { - "type": 0, - "speech": "Here is a great spot I am sure you\u0027ll like, pal!" - } - ] - } - ], - "priority": 500000, - "webhookUsed": false, - "fallbackIntent": false -} diff --git a/rasa/nlu/emulators/dialogflow.py b/rasa/nlu/emulators/dialogflow.py index 64baeac4d1ff..51b3498bff1f 100644 --- a/rasa/nlu/emulators/dialogflow.py +++ b/rasa/nlu/emulators/dialogflow.py @@ -1,8 +1,15 @@ import uuid -from datetime import datetime from typing import Any, Dict, Text -from rasa.shared.nlu.constants import INTENT_NAME_KEY +from rasa.shared.nlu.constants import ( + INTENT_NAME_KEY, + ENTITIES, + ENTITY_ATTRIBUTE_TYPE, + ENTITY_ATTRIBUTE_VALUE, + INTENT, + TEXT, + PREDICTED_CONFIDENCE_KEY, +) from rasa.nlu.emulators.emulator import Emulator @@ -23,26 +30,25 @@ def normalise_response_json(self, data: Dict[Text, Any]) -> Dict[Text, Any]: The transformed input data. """ entities = { - entity_type: [] for entity_type in {x["entity"] for x in data["entities"]} + entity_type: [] + for entity_type in {x[ENTITY_ATTRIBUTE_TYPE] for x in data[ENTITIES]} } - for entity in data["entities"]: - entities[entity["entity"]].append(entity["value"]) + for entity in data[ENTITIES]: + entities[entity[ENTITY_ATTRIBUTE_TYPE]].append( + entity[ENTITY_ATTRIBUTE_VALUE] + ) return { "responseId": str(uuid.uuid1()), "queryResult": { - "resolvedQuery": data["text"], - "action": data["intent"][INTENT_NAME_KEY], - "actionIncomplete": False, - "parameters": entities, + "resolvedQuery": data[TEXT], + "action": data[INTENT][INTENT_NAME_KEY], "contexts": [], - "metadata": { - "intentId": str(uuid.uuid1()), - "webhookUsed": "false", - "intentName": data["intent"]["name"], - }, - "fulfillment": {}, - "score": data["intent"]["confidence"], + "parameters": entities, + "fulfillmentText": "", + "fulfillmentMessages": [], + "outputContexts": [], + "intentDetectionConfidence": data[INTENT][PREDICTED_CONFIDENCE_KEY] }, } diff --git a/tests/nlu/emulators/test_dialogflow.py b/tests/nlu/emulators/test_dialogflow.py index 76abc0ee0080..64bbb3ff5813 100644 --- a/tests/nlu/emulators/test_dialogflow.py +++ b/tests/nlu/emulators/test_dialogflow.py @@ -18,23 +18,15 @@ def test_dialogflow_response(): norm = em.normalise_response_json(data) assert norm == { - "id": norm["id"], - "result": { + "responseId": norm["responseId"], + "queryResult": { + "resolvedQuery": data["text"], "action": data["intent"]["name"], - "actionIncomplete": False, "contexts": [], - "fulfillment": {}, - "metadata": { - "intentId": norm["result"]["metadata"]["intentId"], - "intentName": data["intent"]["name"], - "webhookUsed": "false", - }, "parameters": {"cuisine": ["italian"]}, - "resolvedQuery": data["text"], - "score": data["intent"]["confidence"], - "source": "agent", - }, - "sessionId": norm["sessionId"], - "status": {"code": 200, "errorType": "success"}, - "timestamp": norm["timestamp"], + "fulfillmentText": "", + "fulfillmentMessages": [], + "outputContexts": [], + "intentDetectionConfidence": data["intent"]["confidence"] + } } diff --git a/tests/shared/test_data.py b/tests/shared/test_data.py index 0a0ef4d8d1a0..a06baf4d2c69 100644 --- a/tests/shared/test_data.py +++ b/tests/shared/test_data.py @@ -254,6 +254,8 @@ def test_same_file_names_get_resolved(tmp_path): "data/examples/dialogflow/entities/cuisine.json", "data/examples/dialogflow/entities/cuisine_entries_en.json", "data/examples/dialogflow/entities/cuisine_entries_es.json", + "data/examples/dialogflow/entities/flightNumber.json", + "data/examples/dialogflow/entities/flightNumber_entries_en.json", "data/examples/dialogflow/entities/location.json", "data/examples/dialogflow/entities/location_entries_en.json", "data/examples/dialogflow/entities/location_entries_es.json", From d42e88de9578674a1009645ec99e288f850fe686 Mon Sep 17 00:00:00 2001 From: alwx Date: Tue, 3 Nov 2020 10:09:12 +0100 Subject: [PATCH 08/15] Changelog entry --- changelog/7160.improvement.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 changelog/7160.improvement.md diff --git a/changelog/7160.improvement.md b/changelog/7160.improvement.md new file mode 100644 index 000000000000..b66b30b99845 --- /dev/null +++ b/changelog/7160.improvement.md @@ -0,0 +1,3 @@ +Adapt the training data reader and emulator for DialogFlow to +[their latest format](https://cloud.google.com/dialogflow/es/docs/reference/rest/v2/DetectIntentResponse) +and add support for regex entities. \ No newline at end of file From a0b5782feae01511732f4951cad60cfdaef3c2c5 Mon Sep 17 00:00:00 2001 From: alwx Date: Tue, 3 Nov 2020 10:11:45 +0100 Subject: [PATCH 09/15] Line endings --- data/examples/dialogflow/entities/cuisine.json | 2 +- data/examples/dialogflow/entities/cuisine_entries_en.json | 2 +- data/examples/dialogflow/entities/cuisine_entries_es.json | 2 +- data/examples/dialogflow/entities/flightNumber.json | 2 +- data/examples/dialogflow/entities/flightNumber_entries_en.json | 2 +- data/examples/dialogflow/entities/location.json | 2 +- data/examples/dialogflow/entities/location_entries_en.json | 2 +- data/examples/dialogflow/entities/location_entries_es.json | 2 +- data/examples/dialogflow/intents/Default Fallback Intent.json | 2 +- data/examples/dialogflow/intents/affirm.json | 2 +- data/examples/dialogflow/intents/affirm_usersays_en.json | 2 +- data/examples/dialogflow/intents/affirm_usersays_es.json | 2 +- data/examples/dialogflow/intents/goodbye.json | 2 +- data/examples/dialogflow/intents/goodbye_usersays_en.json | 2 +- data/examples/dialogflow/intents/goodbye_usersays_es.json | 2 +- data/examples/dialogflow/intents/hi.json | 2 +- data/examples/dialogflow/intents/hi_usersays_en.json | 2 +- data/examples/dialogflow/intents/hi_usersays_es.json | 2 +- data/examples/dialogflow/intents/inform.json | 2 +- data/examples/dialogflow/intents/inform_usersays_en.json | 2 +- data/examples/dialogflow/intents/inform_usersays_es.json | 2 +- data/examples/dialogflow/package.json | 2 +- 22 files changed, 22 insertions(+), 22 deletions(-) diff --git a/data/examples/dialogflow/entities/cuisine.json b/data/examples/dialogflow/entities/cuisine.json index 00368e9820e8..866f5daa62a9 100644 --- a/data/examples/dialogflow/entities/cuisine.json +++ b/data/examples/dialogflow/entities/cuisine.json @@ -6,4 +6,4 @@ "isRegexp": false, "automatedExpansion": false, "allowFuzzyExtraction": false -} \ No newline at end of file +} diff --git a/data/examples/dialogflow/entities/cuisine_entries_en.json b/data/examples/dialogflow/entities/cuisine_entries_en.json index f0622cba47fb..eecec9d430ef 100644 --- a/data/examples/dialogflow/entities/cuisine_entries_en.json +++ b/data/examples/dialogflow/entities/cuisine_entries_en.json @@ -20,4 +20,4 @@ "india" ] } -] \ No newline at end of file +] diff --git a/data/examples/dialogflow/entities/cuisine_entries_es.json b/data/examples/dialogflow/entities/cuisine_entries_es.json index baa99bf052d5..1c6256fee5f8 100644 --- a/data/examples/dialogflow/entities/cuisine_entries_es.json +++ b/data/examples/dialogflow/entities/cuisine_entries_es.json @@ -22,4 +22,4 @@ "india" ] } -] \ No newline at end of file +] diff --git a/data/examples/dialogflow/entities/flightNumber.json b/data/examples/dialogflow/entities/flightNumber.json index 8551dedb58d6..d261f1dbcfd1 100644 --- a/data/examples/dialogflow/entities/flightNumber.json +++ b/data/examples/dialogflow/entities/flightNumber.json @@ -6,4 +6,4 @@ "isRegexp": true, "automatedExpansion": false, "allowFuzzyExtraction": false -} \ No newline at end of file +} diff --git a/data/examples/dialogflow/entities/flightNumber_entries_en.json b/data/examples/dialogflow/entities/flightNumber_entries_en.json index 6979eeba5414..9cefd8a825ea 100644 --- a/data/examples/dialogflow/entities/flightNumber_entries_en.json +++ b/data/examples/dialogflow/entities/flightNumber_entries_en.json @@ -5,4 +5,4 @@ "flight [A-Z]{2} [0-9]{4}" ] } -] \ No newline at end of file +] diff --git a/data/examples/dialogflow/entities/location.json b/data/examples/dialogflow/entities/location.json index 4a1e504a5510..d9036d7712de 100644 --- a/data/examples/dialogflow/entities/location.json +++ b/data/examples/dialogflow/entities/location.json @@ -6,4 +6,4 @@ "isRegexp": false, "automatedExpansion": false, "allowFuzzyExtraction": false -} \ No newline at end of file +} diff --git a/data/examples/dialogflow/entities/location_entries_en.json b/data/examples/dialogflow/entities/location_entries_en.json index ac741cb40ee0..98d05daea420 100644 --- a/data/examples/dialogflow/entities/location_entries_en.json +++ b/data/examples/dialogflow/entities/location_entries_en.json @@ -23,4 +23,4 @@ "north" ] } -] \ No newline at end of file +] diff --git a/data/examples/dialogflow/entities/location_entries_es.json b/data/examples/dialogflow/entities/location_entries_es.json index ac6b9589203a..e30f8b545b32 100644 --- a/data/examples/dialogflow/entities/location_entries_es.json +++ b/data/examples/dialogflow/entities/location_entries_es.json @@ -26,4 +26,4 @@ "norte" ] } -] \ No newline at end of file +] diff --git a/data/examples/dialogflow/intents/Default Fallback Intent.json b/data/examples/dialogflow/intents/Default Fallback Intent.json index b3b72d9d999a..2b4ecd230fa4 100644 --- a/data/examples/dialogflow/intents/Default Fallback Intent.json +++ b/data/examples/dialogflow/intents/Default Fallback Intent.json @@ -57,4 +57,4 @@ "conditionalResponses": [], "condition": "", "conditionalFollowupEvents": [] -} \ No newline at end of file +} diff --git a/data/examples/dialogflow/intents/affirm.json b/data/examples/dialogflow/intents/affirm.json index bf039d1f573e..879bd0e83ef1 100644 --- a/data/examples/dialogflow/intents/affirm.json +++ b/data/examples/dialogflow/intents/affirm.json @@ -42,4 +42,4 @@ "conditionalResponses": [], "condition": "", "conditionalFollowupEvents": [] -} \ No newline at end of file +} diff --git a/data/examples/dialogflow/intents/affirm_usersays_en.json b/data/examples/dialogflow/intents/affirm_usersays_en.json index 69a1cd7c988c..554e48da0174 100644 --- a/data/examples/dialogflow/intents/affirm_usersays_en.json +++ b/data/examples/dialogflow/intents/affirm_usersays_en.json @@ -90,4 +90,4 @@ "lang": "en", "updated": 0 } -] \ No newline at end of file +] diff --git a/data/examples/dialogflow/intents/affirm_usersays_es.json b/data/examples/dialogflow/intents/affirm_usersays_es.json index c904158e5f7b..46ccf1a8df33 100644 --- a/data/examples/dialogflow/intents/affirm_usersays_es.json +++ b/data/examples/dialogflow/intents/affirm_usersays_es.json @@ -90,4 +90,4 @@ "lang": "es", "updated": 0 } -] \ No newline at end of file +] diff --git a/data/examples/dialogflow/intents/goodbye.json b/data/examples/dialogflow/intents/goodbye.json index d87084462059..a0369f85b7b1 100644 --- a/data/examples/dialogflow/intents/goodbye.json +++ b/data/examples/dialogflow/intents/goodbye.json @@ -42,4 +42,4 @@ "conditionalResponses": [], "condition": "", "conditionalFollowupEvents": [] -} \ No newline at end of file +} diff --git a/data/examples/dialogflow/intents/goodbye_usersays_en.json b/data/examples/dialogflow/intents/goodbye_usersays_en.json index 721c17036c32..8e179d93ddd0 100644 --- a/data/examples/dialogflow/intents/goodbye_usersays_en.json +++ b/data/examples/dialogflow/intents/goodbye_usersays_en.json @@ -64,4 +64,4 @@ "lang": "en", "updated": 0 } -] \ No newline at end of file +] diff --git a/data/examples/dialogflow/intents/goodbye_usersays_es.json b/data/examples/dialogflow/intents/goodbye_usersays_es.json index d877b3125861..390c284e8115 100644 --- a/data/examples/dialogflow/intents/goodbye_usersays_es.json +++ b/data/examples/dialogflow/intents/goodbye_usersays_es.json @@ -64,4 +64,4 @@ "lang": "es", "updated": 0 } -] \ No newline at end of file +] diff --git a/data/examples/dialogflow/intents/hi.json b/data/examples/dialogflow/intents/hi.json index 468e33058a0e..767ae35cdf90 100644 --- a/data/examples/dialogflow/intents/hi.json +++ b/data/examples/dialogflow/intents/hi.json @@ -32,4 +32,4 @@ "conditionalResponses": [], "condition": "", "conditionalFollowupEvents": [] -} \ No newline at end of file +} diff --git a/data/examples/dialogflow/intents/hi_usersays_en.json b/data/examples/dialogflow/intents/hi_usersays_en.json index 261a08b97bc5..b8dde45b67ec 100644 --- a/data/examples/dialogflow/intents/hi_usersays_en.json +++ b/data/examples/dialogflow/intents/hi_usersays_en.json @@ -64,4 +64,4 @@ "lang": "en", "updated": 0 } -] \ No newline at end of file +] diff --git a/data/examples/dialogflow/intents/hi_usersays_es.json b/data/examples/dialogflow/intents/hi_usersays_es.json index 2ad50578f92e..14da51507811 100644 --- a/data/examples/dialogflow/intents/hi_usersays_es.json +++ b/data/examples/dialogflow/intents/hi_usersays_es.json @@ -64,4 +64,4 @@ "lang": "es", "updated": 0 } -] \ No newline at end of file +] diff --git a/data/examples/dialogflow/intents/inform.json b/data/examples/dialogflow/intents/inform.json index 02f94ea55e0f..fcfc6c8b8049 100644 --- a/data/examples/dialogflow/intents/inform.json +++ b/data/examples/dialogflow/intents/inform.json @@ -59,4 +59,4 @@ "conditionalResponses": [], "condition": "", "conditionalFollowupEvents": [] -} \ No newline at end of file +} diff --git a/data/examples/dialogflow/intents/inform_usersays_en.json b/data/examples/dialogflow/intents/inform_usersays_en.json index bee317d509a0..778974ad8ade 100644 --- a/data/examples/dialogflow/intents/inform_usersays_en.json +++ b/data/examples/dialogflow/intents/inform_usersays_en.json @@ -142,4 +142,4 @@ "lang": "en", "updated": 0 } -] \ No newline at end of file +] diff --git a/data/examples/dialogflow/intents/inform_usersays_es.json b/data/examples/dialogflow/intents/inform_usersays_es.json index 6a7ba5aada32..38347ee97a41 100644 --- a/data/examples/dialogflow/intents/inform_usersays_es.json +++ b/data/examples/dialogflow/intents/inform_usersays_es.json @@ -130,4 +130,4 @@ "lang": "es", "updated": 0 } -] \ No newline at end of file +] diff --git a/data/examples/dialogflow/package.json b/data/examples/dialogflow/package.json index 688e939808b0..1587a669681c 100644 --- a/data/examples/dialogflow/package.json +++ b/data/examples/dialogflow/package.json @@ -1,3 +1,3 @@ { "version": "1.0.0" -} \ No newline at end of file +} From b7e57305951ff53fd29ca0348f10de87f936073b Mon Sep 17 00:00:00 2001 From: alwx Date: Tue, 3 Nov 2020 16:59:55 +0100 Subject: [PATCH 10/15] Updates --- .../google-dialogflow-to-rasa.mdx | 5 +- rasa/nlu/emulators/dialogflow.py | 6 ++- .../nlu/training_data/formats/dialogflow.py | 50 +++++++++---------- tests/nlu/emulators/test_dialogflow.py | 4 +- 4 files changed, 33 insertions(+), 32 deletions(-) diff --git a/docs/docs/migrate-from/google-dialogflow-to-rasa.mdx b/docs/docs/migrate-from/google-dialogflow-to-rasa.mdx index e12eaf40aa07..97ee2d4d47fd 100644 --- a/docs/docs/migrate-from/google-dialogflow-to-rasa.mdx +++ b/docs/docs/migrate-from/google-dialogflow-to-rasa.mdx @@ -79,8 +79,9 @@ To send a request to the server, run: ```bash curl 'localhost:5005/model/parse?emulation_mode=dialogflow' -d '{"text": "hello"}' -The `emulation_mode` parameter tells Rasa that you want your json -response to have the same format as you would get from dialogflow. +The `emulation_mode` parameter tells Rasa that you want your JSON response to have the same format as you would +get from DialogFlow sessions.detectIntent method (the format is +described [here](https://cloud.google.com/dialogflow/es/docs/reference/rest/v2/DetectIntentResponse)). You can also leave it out to get the result in the usual Rasa format. ## Terminology: diff --git a/rasa/nlu/emulators/dialogflow.py b/rasa/nlu/emulators/dialogflow.py index 51b3498bff1f..2bca67455fdd 100644 --- a/rasa/nlu/emulators/dialogflow.py +++ b/rasa/nlu/emulators/dialogflow.py @@ -31,7 +31,9 @@ def normalise_response_json(self, data: Dict[Text, Any]) -> Dict[Text, Any]: """ entities = { entity_type: [] - for entity_type in {x[ENTITY_ATTRIBUTE_TYPE] for x in data[ENTITIES]} + for entity_type in { + entity[ENTITY_ATTRIBUTE_TYPE] for entity in data[ENTITIES] + } } for entity in data[ENTITIES]: @@ -49,6 +51,6 @@ def normalise_response_json(self, data: Dict[Text, Any]) -> Dict[Text, Any]: "fulfillmentText": "", "fulfillmentMessages": [], "outputContexts": [], - "intentDetectionConfidence": data[INTENT][PREDICTED_CONFIDENCE_KEY] + "intentDetectionConfidence": data[INTENT][PREDICTED_CONFIDENCE_KEY], }, } diff --git a/rasa/shared/nlu/training_data/formats/dialogflow.py b/rasa/shared/nlu/training_data/formats/dialogflow.py index 72a102c6ab5d..76d8ad8cf78c 100644 --- a/rasa/shared/nlu/training_data/formats/dialogflow.py +++ b/rasa/shared/nlu/training_data/formats/dialogflow.py @@ -36,27 +36,27 @@ def read(self, fn: Text, **kwargs: Any) -> "TrainingData": ) root_js = rasa.shared.utils.io.read_json_file(fn) - examples_js = self._read_examples_js(fn, language, fformat) + examples = self._read_examples(fn, language, fformat) - if not examples_js: + if not examples: rasa.shared.utils.io.raise_warning( f"No training examples found for dialogflow file {fn}!", docs=DOCS_URL_MIGRATE_GOOGLE, ) return TrainingData() elif fformat == DIALOGFLOW_INTENT: - return self._read_intent(root_js, examples_js) + return self._read_intent(root_js, examples) else: # path for DIALOGFLOW_ENTITIES - return self._read_entities(root_js, examples_js) + return self._read_entities(root_js, examples) def _read_intent( - self, intent_js: Dict[Text, Any], examples_js: List[Dict[Text, Any]] + self, intent: Dict[Text, Any], examples: List[Dict[Text, Any]] ) -> "TrainingData": """Reads the intent and examples from respective jsons.""" - intent = intent_js.get("name") + intent = intent.get("name") training_examples = [] - for ex in examples_js: + for ex in examples: text, entities = self._join_text_chunks(ex["data"]) training_examples.append(Message.build(text, intent, entities)) @@ -100,47 +100,45 @@ def _flatten(list_of_lists: List[List[Any]]) -> List[Any]: @staticmethod def _extract_lookup_tables( - entity_js: Dict[Text, Any], examples_js: List[Dict[Text, Any]] + entity: Dict[Text, Any], examples: List[Dict[Text, Any]] ) -> Optional[List[Dict[Text, Any]]]: - """Extract the lookup table from the entity synonyms.""" - synonyms = [e["synonyms"] for e in examples_js if "synonyms" in e] + """Extracts the lookup table from the entity synonyms.""" + synonyms = [e["synonyms"] for e in examples if "synonyms" in e] synonyms = DialogflowReader._flatten(synonyms) elements = [synonym for synonym in synonyms if "@" not in synonym] if len(elements) == 0: return None - return [{"name": entity_js.get("name"), "elements": elements}] + return [{"name": entity.get("name"), "elements": elements}] @staticmethod def _extract_regex_features( - entity_js: Dict[Text, Any], examples_js: List[Dict[Text, Any]] - ) -> Optional[List[Dict[Text, Any]]]: + entity: Dict[Text, Any], examples: List[Dict[Text, Any]] + ) -> List[Dict[Text, Any]]: """Extract the regex features from the entity synonyms.""" - synonyms = [e["synonyms"] for e in examples_js if "synonyms" in e] + synonyms = [e["synonyms"] for e in examples if "synonyms" in e] synonyms = DialogflowReader._flatten(synonyms) return [ - {"name": entity_js.get("name"), "pattern": synonym} for synonym in synonyms + {"name": entity.get("name"), "pattern": synonym} for synonym in synonyms ] @staticmethod def _read_entities( - entity_js: Dict[Text, Any], examples_js: List[Dict[Text, Any]] + entity: Dict[Text, Any], examples: List[Dict[Text, Any]] ) -> "TrainingData": - entity_synonyms = transform_entity_synonyms(examples_js) + entity_synonyms = transform_entity_synonyms(examples) - if entity_js["isRegexp"]: - regex_features = DialogflowReader._extract_regex_features( - entity_js, examples_js - ) + if entity["isRegexp"]: + regex_features = DialogflowReader._extract_regex_features(entity, examples) return TrainingData([], entity_synonyms, regex_features, [],) else: - lookup_tables = DialogflowReader._extract_lookup_tables( - entity_js, examples_js - ) + lookup_tables = DialogflowReader._extract_lookup_tables(entity, examples) return TrainingData([], entity_synonyms, [], lookup_tables,) @staticmethod - def _read_examples_js(fn: Text, language: Text, fformat: Text) -> Any: + def _read_examples( + fn: Text, language: Text, fformat: Text + ) -> Optional[List[Dict[Text, Any]]]: """Infer and load the example file based on the root filename and root format.""" @@ -155,5 +153,5 @@ def _read_examples_js(fn: Text, language: Text, fformat: Text) -> Any: else: return None - def reads(self, s, **kwargs): + def reads(self, s: Text, **kwargs: Any) -> "TrainingData": raise NotImplementedError diff --git a/tests/nlu/emulators/test_dialogflow.py b/tests/nlu/emulators/test_dialogflow.py index 64bbb3ff5813..34563b9ca419 100644 --- a/tests/nlu/emulators/test_dialogflow.py +++ b/tests/nlu/emulators/test_dialogflow.py @@ -27,6 +27,6 @@ def test_dialogflow_response(): "fulfillmentText": "", "fulfillmentMessages": [], "outputContexts": [], - "intentDetectionConfidence": data["intent"]["confidence"] - } + "intentDetectionConfidence": data["intent"]["confidence"], + }, } From 9e5c900ceeb6b95a1d6236401a842b6b2b130d21 Mon Sep 17 00:00:00 2001 From: alwx Date: Tue, 3 Nov 2020 17:11:15 +0100 Subject: [PATCH 11/15] Defaultdict --- rasa/nlu/emulators/dialogflow.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/rasa/nlu/emulators/dialogflow.py b/rasa/nlu/emulators/dialogflow.py index 2bca67455fdd..2e947315cc58 100644 --- a/rasa/nlu/emulators/dialogflow.py +++ b/rasa/nlu/emulators/dialogflow.py @@ -1,4 +1,5 @@ import uuid +from collections import defaultdict from typing import Any, Dict, Text from rasa.shared.nlu.constants import ( @@ -29,13 +30,7 @@ def normalise_response_json(self, data: Dict[Text, Any]) -> Dict[Text, Any]: Returns: The transformed input data. """ - entities = { - entity_type: [] - for entity_type in { - entity[ENTITY_ATTRIBUTE_TYPE] for entity in data[ENTITIES] - } - } - + entities = defaultdict(list) for entity in data[ENTITIES]: entities[entity[ENTITY_ATTRIBUTE_TYPE]].append( entity[ENTITY_ATTRIBUTE_VALUE] From f794e6f377f60bc56cdbed01037b6271df7beb4b Mon Sep 17 00:00:00 2001 From: alwx Date: Wed, 4 Nov 2020 13:46:22 +0100 Subject: [PATCH 12/15] Post-review updates --- docs/docs/migrate-from/google-dialogflow-to-rasa.mdx | 2 +- rasa/nlu/emulators/dialogflow.py | 7 +++++-- tests/nlu/emulators/test_dialogflow.py | 11 +++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/docs/docs/migrate-from/google-dialogflow-to-rasa.mdx b/docs/docs/migrate-from/google-dialogflow-to-rasa.mdx index 97ee2d4d47fd..4fc9b32d6309 100644 --- a/docs/docs/migrate-from/google-dialogflow-to-rasa.mdx +++ b/docs/docs/migrate-from/google-dialogflow-to-rasa.mdx @@ -80,7 +80,7 @@ To send a request to the server, run: ```bash curl 'localhost:5005/model/parse?emulation_mode=dialogflow' -d '{"text": "hello"}' The `emulation_mode` parameter tells Rasa that you want your JSON response to have the same format as you would -get from DialogFlow sessions.detectIntent method (the format is +get from DialogFlow `sessions.detectIntent` method (the format is described [here](https://cloud.google.com/dialogflow/es/docs/reference/rest/v2/DetectIntentResponse)). You can also leave it out to get the result in the usual Rasa format. diff --git a/rasa/nlu/emulators/dialogflow.py b/rasa/nlu/emulators/dialogflow.py index 2e947315cc58..7275b2b9f85e 100644 --- a/rasa/nlu/emulators/dialogflow.py +++ b/rasa/nlu/emulators/dialogflow.py @@ -39,13 +39,16 @@ def normalise_response_json(self, data: Dict[Text, Any]) -> Dict[Text, Any]: return { "responseId": str(uuid.uuid1()), "queryResult": { - "resolvedQuery": data[TEXT], + "queryText": data[TEXT], "action": data[INTENT][INTENT_NAME_KEY], - "contexts": [], "parameters": entities, "fulfillmentText": "", "fulfillmentMessages": [], "outputContexts": [], + "intent": { + "name": data[INTENT][INTENT_NAME_KEY], + "displayName": data[INTENT][INTENT_NAME_KEY], + }, "intentDetectionConfidence": data[INTENT][PREDICTED_CONFIDENCE_KEY], }, } diff --git a/tests/nlu/emulators/test_dialogflow.py b/tests/nlu/emulators/test_dialogflow.py index 34563b9ca419..ecf1b82e8054 100644 --- a/tests/nlu/emulators/test_dialogflow.py +++ b/tests/nlu/emulators/test_dialogflow.py @@ -20,13 +20,16 @@ def test_dialogflow_response(): assert norm == { "responseId": norm["responseId"], "queryResult": { - "resolvedQuery": data["text"], - "action": data["intent"]["name"], - "contexts": [], + "queryText": "I want italian food", + "action": "inform", "parameters": {"cuisine": ["italian"]}, "fulfillmentText": "", "fulfillmentMessages": [], "outputContexts": [], - "intentDetectionConfidence": data["intent"]["confidence"], + "intent": { + "name": "inform", + "displayName": "inform" + }, + "intentDetectionConfidence": 0.4794813722432127, }, } From 1bb27c6771759ca4c7d22b72f324e0eb822cab21 Mon Sep 17 00:00:00 2001 From: alwx Date: Wed, 4 Nov 2020 13:48:00 +0100 Subject: [PATCH 13/15] Changelog updates --- changelog/7160.improvement.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/7160.improvement.md b/changelog/7160.improvement.md index b66b30b99845..9cff70906737 100644 --- a/changelog/7160.improvement.md +++ b/changelog/7160.improvement.md @@ -1,3 +1,3 @@ -Adapt the training data reader and emulator for DialogFlow to +Adapt the [training data reader and emulator for DialogFlow](migrate-from/google-dialogflow-to-rasa.mdx) to [their latest format](https://cloud.google.com/dialogflow/es/docs/reference/rest/v2/DetectIntentResponse) and add support for regex entities. \ No newline at end of file From 8e51216e1626714d5d4f4957231c823d2ec3ab96 Mon Sep 17 00:00:00 2001 From: alwx Date: Wed, 4 Nov 2020 13:50:08 +0100 Subject: [PATCH 14/15] Black updates --- tests/nlu/emulators/test_dialogflow.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/nlu/emulators/test_dialogflow.py b/tests/nlu/emulators/test_dialogflow.py index ecf1b82e8054..ddd329505e2d 100644 --- a/tests/nlu/emulators/test_dialogflow.py +++ b/tests/nlu/emulators/test_dialogflow.py @@ -26,10 +26,7 @@ def test_dialogflow_response(): "fulfillmentText": "", "fulfillmentMessages": [], "outputContexts": [], - "intent": { - "name": "inform", - "displayName": "inform" - }, + "intent": {"name": "inform", "displayName": "inform"}, "intentDetectionConfidence": 0.4794813722432127, }, } From 2a408939e7dbf184492ebb6738208d4dc4fa1b91 Mon Sep 17 00:00:00 2001 From: alwx Date: Thu, 5 Nov 2020 10:33:07 +0100 Subject: [PATCH 15/15] Docs wording --- docs/docs/migrate-from/google-dialogflow-to-rasa.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/docs/migrate-from/google-dialogflow-to-rasa.mdx b/docs/docs/migrate-from/google-dialogflow-to-rasa.mdx index 4fc9b32d6309..540f7f7b4e0b 100644 --- a/docs/docs/migrate-from/google-dialogflow-to-rasa.mdx +++ b/docs/docs/migrate-from/google-dialogflow-to-rasa.mdx @@ -14,7 +14,7 @@ Navigate to your agent's settings by clicking the gear icon. import dialogflowExport1 from './dialogflow_export.png'; -In DialogFlow, the gear icon that indicates settings sits next to the dropdown menu for choosing between projects. +In Dialogflow, the gear icon that indicates settings sits next to the dropdown menu for choosing between projects. Click on the 'Export and Import' tab and click on the 'Export as ZIP' button. @@ -44,7 +44,7 @@ mv testagent data/ ## Step 3: Train your NLU model -To train a model using your dialogflow data, run: +To train a model using your Dialogflow data, run: ```bash rasa train nlu @@ -80,7 +80,7 @@ To send a request to the server, run: ```bash curl 'localhost:5005/model/parse?emulation_mode=dialogflow' -d '{"text": "hello"}' The `emulation_mode` parameter tells Rasa that you want your JSON response to have the same format as you would -get from DialogFlow `sessions.detectIntent` method (the format is +get from the Dialogflow `sessions.detectIntent` endpoint (the format is described [here](https://cloud.google.com/dialogflow/es/docs/reference/rest/v2/DetectIntentResponse)). You can also leave it out to get the result in the usual Rasa format.