MycroftAI / mycroft-core

Mycroft Core, the Mycroft Artificial Intelligence platform.
https://mycroft.ai
Apache License 2.0
6.53k stars 1.27k forks source link

cannot get regex file working #977

Closed mortommy closed 7 years ago

mortommy commented 7 years ago

Hi, I'm trying to extend one skill I have developed adding new regex expression and I decided to create a new file. With the expression:

(?P<Command>dim|brighten) (?P<Item>.*)

when in cli I type:

dim something or bright something

I always get:

~~~~"data": {"lang": "en-us", "utterances": ["dim something"]}, "context": null}
mycroft.skills.intent_service - ERROR -
Traceback (most recent call last):
~~~~19-py2.7.egg/mycroft/skills/intent_service.py", line 54, in handle_utterance
normalize(utterance, lang), 100))
StopIteration
~~~~", "data": {"lang": "en-us", "utterance": "dim something"}, "context": null}
~~~~wolfram-alpha__init__ - DEBUG - WolframAlpha fallback attempt: dim something
skill-wolfram-alpha__init__ - DEBUG - Unknown intent: dim something

If, in the file, I define the expression as dim (?P<Item>.*)

it works. Is it not possible to start a regex with a group?

As additional information, I have another regex file where I also use Command and Item as group name.

Thank you.

Regards.

forslund commented 7 years ago

Hi, the regex looks good and I believe it should work. What does the code building the intent using the regex look like?

mortommy commented 7 years ago

Hi, thank you for your answer. The code is:

dimmer_status_intent = IntentBuilder("Dimmer_StatusIntent").require("DimmerStatusKeyword").require("Command").require("Item").build()
self.register_intent(dimmer_status_intent, self.handle_dimmer_status_intent)

the DimmerStatusKeyword file is:

dim
brighten

the other intents I developed before are still working, just this new one is not.

Thank you.

forslund commented 7 years ago

Not sure here...I've tested it and there's something fishy going on.

I think you can move forward by using the regexp (dim|brighten) (?P<Item>.*) and getting the command from DimmerStatusKeyword value in your handler

using the following intent

IntentBuilder("Dimmer_StatusIntent").require("DimmerStatusKeyword").require("Item").build()

I'll have to look into this more

forslund commented 7 years ago

Ok, I've spent the morning checking this. As far as I can understand it works as intended.

I can get it working in the following two ways for the sentence dim the desktop lamp:

IntentBuilder("Dimmer_StatusIntent").require("Command").require("Item").build()

and

IntentBuilder("Dimmer_StatusIntent").require("DimmerStatusKeyword").require("Item").build()

but now with this:

IntentBuilder("Dimmer_StatusIntent").require("DimmerStatusKeyword").require("Command").require("Item").build()

I think what is happening is that dim or brighten is required twice and sure enough: dim dim desktop lamp works for above intent.

The thing is that the words in the sentence can only be matched to a single require() statement. In your case both DimmerStatusKeyword and Command requires the same dim or brighten and since there is only a single dim in dim the desktop lamp.

I think the correct way is to do as I suggested in my previous post.

mortommy commented 7 years ago

Thank you for the explanation. I'm looking for an example about the way you explained in the previous post. Do you mean using Message.metadata? Thank you

forslund commented 7 years ago

Yes,

metadata is simply called data now.

for you it would look something like:

    def handle_dimmer_status_intent(self, message):
        command = message.data.get('DimmerStatusKeyword')

Then command would be either 'dim' or 'brighten'

forslund commented 7 years ago

@mortommy Did you get it working? Can we close the issue?

mortommy commented 7 years ago

Hi, I got it working right now using your example. Thank you for your support.

forslund commented 7 years ago

Great to hear you got it working! Closing this issue.