|
2 | 2 | # Licensed under the MIT License. |
3 | 3 | from enum import Enum |
4 | 4 | from typing import Dict |
5 | | -from botbuilder.ai.luis import LuisRecognizer, LuisApplication |
| 5 | +from botbuilder.ai.luis import LuisRecognizer |
6 | 6 | from botbuilder.core import IntentScore, TopIntent, TurnContext |
7 | 7 |
|
8 | 8 | from booking_details import BookingDetails |
@@ -32,6 +32,9 @@ class LuisHelper: |
32 | 32 | async def execute_luis_query( |
33 | 33 | luis_recognizer: LuisRecognizer, turn_context: TurnContext |
34 | 34 | ) -> (Intent, object): |
| 35 | + """ |
| 36 | + Returns an object with preformatted LUIS results for the bot's dialogs to consume. |
| 37 | + """ |
35 | 38 | result = None |
36 | 39 | intent = None |
37 | 40 |
|
@@ -78,13 +81,20 @@ async def execute_luis_query( |
78 | 81 | from_entities[0]["text"].capitalize() |
79 | 82 | ) |
80 | 83 |
|
81 | | - # TODO: This value will be a TIMEX. And we are only interested in a Date so grab the first result and drop the Time part. |
| 84 | + # This value will be a TIMEX. And we are only interested in a Date so grab the first result and drop the Time part. |
82 | 85 | # TIMEX is a format that represents DateTime expressions that include some ambiguity. e.g. missing a Year. |
83 | | - date_entities = recognizer_result.entities.get("$instance", {}).get( |
84 | | - "datetime", [] |
85 | | - ) |
86 | | - if len(date_entities) > 0: |
87 | | - result.travel_date = None # TODO: Set when we get a timex format |
| 86 | + date_entities = recognizer_result.entities.get("datetime", []) |
| 87 | + if date_entities: |
| 88 | + timex = date_entities[0]["timex"] |
| 89 | + |
| 90 | + if timex: |
| 91 | + datetime = timex[0].split("T")[0] |
| 92 | + |
| 93 | + result.travel_date = datetime |
| 94 | + |
| 95 | + else: |
| 96 | + result.travel_date = None |
| 97 | + |
88 | 98 | except Exception as e: |
89 | 99 | print(e) |
90 | 100 |
|
|
0 commit comments