Comments (13)
Is channel
registered as a keyword as well?
from adapt.
@oblitum me too. I wrote a method that's been merged into cpkodi for doing this consistently with multiline .rx files.
from adapt.
Would you mind creating this issue on the Adapt issue page instead? Also, it sounds similar, but the opposite to this issue.
from adapt.
Hey, sorry for the super delayed response here. I believe that this issue was addressed by a bug in optionally
some time ago. A recreation of your issue (using adapt only) yields the following results:
from adapt.intent import IntentBuilder
from adapt.engine import IntentDeterminationEngine
def run_test(required):
engine = IntentDeterminationEngine()
engine.register_entity("Test", "TestKeyword")
engine.register_regex_entity(r"by (?P<Artist>.*)")
test_intent = IntentBuilder("TestIntent"). \
require("TestKeyword")
if required:
test_intent = test_intent.require('Artist').build()
else:
test_intent = test_intent.optionally('Artist').build()
engine.register_intent_parser(test_intent)
print(list(engine.determine_intent("test by Artist")))
run_test(True)
run_test(False)
> [{'intent_type': 'TestIntent', 'TestKeyword': 'Test', 'Artist': 'artist', 'target': None, 'confidence': 0.375}]
> [{'intent_type': 'TestIntent', 'TestKeyword': 'Test', 'Artist': 'artist', 'target': None, 'confidence': 1.0}]
from adapt.
I'm still experiencing this intermittently with adapt-parser 0.4.0. Here's my code (__init__.py
excerpt) in my local version of pcwii's cpkodi skill:
...
@intent_handler(IntentBuilder('WatchPVRChannelNumber').require("WatchKeyword")
.require("PVRKeyword").optionally("ChannelNumber").build())
def handle_channel(self, message):
if 'ChannelNumber' in message.data:
self.dLOG("Adapt successfully recognized an optional regex.")
play_channel_number(self.kodi_path, int(message.data['ChannelNumber']))
return
if channel_no := self._match_adapt_regex(message.data['utterance'], "ChannelNumber") is not None:
self.dLOG("Adapt failed to recognize an optional regex.")
play_channel_number(self.kodi_path, int(channel_no))
return
...
def _match_adapt_regex(self, string, rxfile):
with open(os.path.join(os.path.dirname(__file__), "regex", self.lang, rxfile + ".rx")) as f:
self.dLOG("Matching " + string)
for line in f.readlines():
self.dLOG(line.strip())
match = re.match(line.strip(), string)
if match is not None:
return match[rxfile]
return None
And here's the regex file I'm using, ChannelNumber.rx
in the regex/en-us
directory:
.*channel (?P<ChannelNumber>\d+)
.*channel number (?P<ChannelNumber>\d+)
And that gives me the following output:
12:49:31.894 | INFO | 719574 | __main__:handle_utterance:76 | Utterance: ['watch channel 5']
12:49:31.922 | INFO | 719538 | cpkodi-skill_pcwii:dLOG:96 | Matching watch channel 5
12:49:31.923 | INFO | 719538 | cpkodi-skill_pcwii:dLOG:96 | .*channel (?P<ChannelNumber>\d+)
12:49:31.926 | INFO | 719538 | cpkodi-skill_pcwii:dLOG:96 | Adapt failed to recognize an optional regex.
Then I tried it with this decorator and it worked, but I don't see why:
@intent_handler(IntentBuilder('').require("WatchKeyword").require("PVRKeyword").optionally("ChannelNumber"))
Is this user error? What can I do to help debug this? Is adapt being deprecated in favor of padatious?
from adapt.
Ah yes, that is user error then, that's part of PVRKeyword
! I suppose I need to use one-of
or have the optionally term before the PVRKeyword if regexes still don't consume parts of the utterance.
I still don't understand why it works now, though.
from adapt.
hey @david-morris , I've opened MycroftAI/mycroft-core#2883 against mycroft to request some better tools to help us debug issues like this.
Regex entities in particular are thorny in how they influence ranking, as are optional
fields on intents. The combination of the two can result in unexpected behaviors, and without the ability to see the full context of the environment (i.e. mycroft state) I don't believe that they can be fully reproduced or debugged.
from adapt.
Hey folks, I'm facing a very similar problem and I can't figure how to fix. I have a locale/pt-br/Percent.rx
file with (?P<Percent>\d+%)
. Then I have an intent decorated with @intent_handler(IntentBuilder('BrightnessIntent').one_of('Brighten', 'Darken').require('Target').optionally('Percent'))
. Inside the intent handler, I never get the matching percent value in message.data
, but changing optionally
for require
makes it present, for the same utterance.
from adapt.
Hi @oblitum ,
Could you check out the issue I filed against the Mycroft documentation and add your perspective on the information I posted? I don't see any obvious source of your problem, but I think it's good to have that info when developing intents.
Additionally, as someone new to this community, I'm a bit uncertain about whether we should be posting on Adapt issues when mycroft-core currently uses adapt 0.3.7 and adapt 0.4.0 has been released. Could someone with more experience comment on that?
from adapt.
Good question, I'm not sure what is best. maybe it's better to open on mycroft-core and if it can be determined that it's adapt and not mycroft-core that is at fault it can be moved by maintainers...
But if the issue / question is specific to adapt it may be better to go here directly.
So I'd say...it depends :P
from adapt.
@david-morris thanks for your input regarding the docs, but I don't think it's a match issue, because actually the one I posted formerly was just one of the attempts, originally it was .*?(?P<Percent>\d+%)
, then I changed it to .*?(?P<Percent>\d+%).*
, then .*(?P<Percent>\d+%).*
, .*?(?P<Percent>\d+)%
, etc, nothing worked to change the adapt behavior that simply never captured the "Percent" in message.data
when it was optionally
, and always captured it when it was require
.
from adapt.
I've given up trying to use .optionally
and I'm regex matching the message.data['utterance']
directly, it works.
from adapt.
@oblitum and @david-morris , in a lengthy explanation of some dark corners of adapt to @chrisveilleux , I concluded that there is a failure to meet the principle of least astonishment. I'm finally tackling this with #137 (and fixing a few other latent bugs), and I'd encourage you to try the latest version when it gets merged!
from adapt.
Related Issues (20)
- Using keyword "my" results in regex problems HOT 9
- Possible Regression using two or more regex HOT 3
- How do I use audio for intent classification? Any code? HOT 2
- upgrade to latest pyee HOT 1
- Catching first number with regex fails HOT 6
- Confusing examples: MultiIntent* examples define unused Parser and EntityTagger HOT 2
- Trie's `max_threshold` is documented as int, seems to be float
- `ZeroDivisionError` in determine_intent when tags are empty HOT 1
- Entity matching more than it should HOT 3
- An issue with adapt-parser. Adding new intents is breaking old behavior. HOT 3
- Adapt react-native HOT 2
- Add license and test files to PyPI packages HOT 2
- Consolidate package requirements HOT 4
- Tooling for debugging Adapt
- Improve the readability of Adapt
- AttributeError when re-registering regex
- IntentDeterminationEngine.determine_intent does not return sorted results
- Github Action: Fix exit status
- Regex entities with optional words HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adapt.