MycroftAI / adapt

Adapt Intent Parser
Apache License 2.0
711 stars 155 forks source link

Using keyword "my" results in regex problems #100

Closed stratus-ss closed 3 years ago

stratus-ss commented 4 years ago

Be clear about the software, hardware and version you are running

Try to provide steps that we can use to replicate the Issue

Given the following intent:

 @intent_handler(IntentBuilder('').require('CreateItemKeyword').require("Food")
                    .require("ShoppingList").optionally("Category"))
    def create_item_on_list(self, message):
        """
        I NEED TO FIX THE REGEX AS IT DOES NOT CAPTURE SPACES
        Handles the initial voice interaction from the user.
        Uses add.item.rx and optionally category.rx and list.rx
        :param message:
        :return:
        """
        category = None
        item_to_add = message.data['Food']
        try:
            category = message.data['Category']
        except KeyError:
            # Category is optional so this is a non-fatal error
            pass
        try:
            self.list_name = message.data['ShoppingList']
            self.list_id = self.determine_list_id(self.list_name)
            if self.list_id is None:
                self.speak("Sorry the %s list does not exist" % self.list_name)
                exit()
            self.grocery_state_file = "groceries_%s.txt" % self.list_id
        except KeyError:
            # If there is a key error, its most likely to be on the shopping list name
            # The shopping list name is required to find the list_id
            # without list_id this error is considered fatal
            exit()

        shopping_list_dict, categories = self.refresh_lists()
        try:
            self.add_to_my_list(full_list=shopping_list_dict, item_name=item_to_add, all_categories=categories,
                                item_category=category)
            self.speak("Adding %s to your list" % item_to_add)
        except:
            # This is a generic catchall which should exit instead of throwing the mycroft error
            self.speak("Sorry, I couldn't add %s to %s list" % (item_to_add, self.list_name))
            exit()

With this regex:

add (?P<Food>.*) (to my) (?P<ShoppingList>.*) list
add (?P<Food>.*) (to the) (?P<ShoppingList>.*) list

Or this:

add (?P<Food>.*) to (the|my) (?P<ShoppingList>.*) list

Or this

add (?P<Food>.*) to my (?P<ShoppingList>.*) list
add (?P<Food>.*) to the (?P<ShoppingList>.*) list

Be as specific as possible about the expected condition, and the deviation from expected condition.

If I trigger this by saying "Hey Mycroft add stuff to my grocery list" the ShoppingList is set to "my grocery list."

If I say "Hey Mycroft add stuff to the grocery list", the regex works properly and ShoppingList is set to "grocery"

Provide log files or other output to help us see the error

logs to follow shortly

stratus-ss commented 4 years ago

The Grocery List exists and works with the word 'the' console output from a successful add:

 add stuff to the grocery list                                                     
 >> Adding stuff to your list                                                              

15:06:59.291 | INFO     | 116927 | __main__:handle_wakeword:67 | Wakeword Detected: hey jarvis
 15:06:59.661 | INFO     | 116927 | __main__:handle_record_begin:37 | Begin Recording...
 15:07:01.896 | INFO     | 116927 | __main__:handle_record_end:45 | End Recording...
~~~~| INFO     | 116927 | __main__:handle_utterance:72 | Utterance: ['add stuff to the grocery list']
 15:07:03.732 | INFO     | 116919 | OurGroceriesSkill | List is 14819 minutes old
Updating groceries list as it is older than 10 minutes
 15:07:03.974 | INFO     | 116919 | OurGroceriesSkill | List is 2 minutes old
categories list under 10 minutes old... skipping refresh
 15:07:04.247 | INFO     | 116919 | OurGroceriesSkill | -----> Added item <------

audio.log bus.log enclosure.log skills.log voice.log

However, using the keyword "my" causes the same skill to fail

 add stuff to my grocery list                                                                       
 >> Sorry the my grocery list list does not exist  

 15:07:09.411 | INFO     | 116927 | __main__:handle_wakeword:67 | Wakeword Detected: hey jarvis
 15:07:09.779 | INFO     | 116927 | __main__:handle_record_begin:37 | Begin Recording...
 15:07:14.021 | INFO     | 116927 | __main__:handle_record_end:45 | End Recording...
~~~~ | INFO     | 116927 | __main__:handle_utterance:72 | Utterance: ['add stuff to my grocery list']
clusterfudge commented 4 years ago

Can you include logs with at the DEBUG level? I'm not seeing the events from the intent parser.

stratus-ss commented 4 years ago

how do I enable debug?

The only thing I found was self.log.debug(). Do I need a bunch of these statements? if so, where would you like these included?

clusterfudge commented 4 years ago

You should be able to configure via a mycroft.conf file like so: https://github.com/MycroftAI/mycroft-core/blob/dev/mycroft/configuration/mycroft.conf#L253

stratus-ss commented 4 years ago

These are the logs while testing the "the" keyword after setting Debug as suggested

the_keyword_voice.log the_keyword_skills.log the_keyword_enclosure.log the_keyword_bus.log the_keyword_audio.log

stratus-ss commented 4 years ago

these are the logs from the two tests with the trigger "add stuff to my grocery list" voice.log skills.log enclosure.log bus.log audio.log

Here are the regex during today's tests

add (?P<Food>.*) (to my) (?P<ShoppingList>.*) list
add (?P<Food>.*) (to the) (?P<ShoppingList>.*) list
clusterfudge commented 4 years ago

Unfortunately, the log lines I was expecting are not present; it appears that almost all DEBUG logs have been removed from mycroft-core, which makes this a bit more difficult to diagnose with tinkering. Also, just to confirm, you restarted each of the processes after changing the configuration? I believe this config change requires a restart.

Adapt emits a couple of events that will be helpful, that show the intermediate state of the parser. Hopefully, they're wired up enough that you can add logging for them somewhere.

You'll want to add an event handler for tagged_entities to the instance of IntentDeterminationEngine held in the intent service. I'm no longer familiar enough with mycroft-core to point out where that happens, and unfortunately it does not appear that the internal emitter is bound to the message bus (which would've made this a lot easier).

clusterfudge commented 3 years ago

hey @stratus-ss did you have any luck with this? If you're still seeing this issue, please let us know and we'll try to address it prior to 1.0.0. I suspect this is similar to what you reported https://github.com/MycroftAI/adapt/issues/102, and I'll have the same sad answer for you.

clusterfudge commented 3 years ago

I'm going to close this out as cannot reproduce, as we're no longer getting any notes from the reporter.