Comments (6)
Not sure if I've understood it correctly but it may be the way regexes work. They match as much as possible. (atleast from what I've gathered messing around on https://pythex.org/
A workaround may be to do something like:
(for|about) ((the (?P<search>.+))|(?P<search2>.+))
But then you need to make your intent use .one_of('search', 'search2')
so it's not terribly elegant. It feels like the intent should be expressible using regexes but I'm not enough of a guru to figure it out either :/
Edit: (literally 5 min later) (for|about) (the|)?(?P<search>.+$)
should work as you expected (not sure what I did wrong yesterday) so something in adapt is causing this if it's not working for you. I'll do some more experimentation in adapt and see what I can see...
from adapt.
Thanks @forslund for looking into my issue.
Unfortunately it does not work on my end with register_regex_entity("(for|about) (|the)?(?P<search>.+$)")
search for the moon still matches the the article, "search": "the moon",
but it should only match moon.
It is possible to do an or statement in the regex with ( for| a| an) but I can't believe there is no way to match just nothing. If no article matches, it should just match the whole rest of the sentence.
I played a bit around on regex101 and with this pattern (for|about)( (an|a|the)|\b) (?P<search>.*)
it does match with both sentences only moon, but unfortunately not with adapt :(
I do have some workarounds in my project, like making a new intent for this case but it would be nice to have a cleaner solution.
from adapt.
Did some digging tonight, the issue is (I think) the iterative approach adapt uses with regexes...
The sentence "tell me about the moon" will be tried in stages
"tell"
"tell me"
"tell me about"
"tell me about the" <- match found
"tell me about the moon" <- match found
and adapt chooses to report back "the" as the match...
However using negative lookahead:
(for|about) (the|)?(?P<search>(?!the).+$)
should not match against "tell me about the", but should work with "tell me about the moon", however for some reason this doesn't result in any match...I see that "moon" is matched but somehow not used as a result. will need to dig some more...
from adapt.
"(for|about) (the |)?(?P<search>(?!the)\S+$)"
Seems to work in my test case...there is an issue where an extra space is matched: " moon" causing a later match to fail.
from adapt.
Indeed this works on my end too.
It also works with several words "(for|about) (the |a |an |)?(?P<search>(?!the|a|an).*)"
. But it does look a bit ugly though... Is it because of the design of adapt we have to set the optional words twice? Or is it because of regex works?
Something like (an |a |the |.* )
would be much cleaner, but I got the feeling its not possible because of regex...
With this solution I can hardcode something in my code to have an easier matching.
Anyway, thank you very much for your help!
from adapt.
Partially it's caused by how adapts runs multiple passes over subsets of the utterance but partially something seems slightly wrong (or I don't quite understand it). I will look into it some more and see if I can understand the internals better but I'm not sure I'll be able to improve things.
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
- 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
- tokenize voice input? HOT 2
- Possible bug in context merging in context.py HOT 1
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.