Coder Social home page Coder Social logo

Regex entities with optional words about adapt HOT 6 OPEN

corus87 avatar corus87 commented on May 25, 2024
Regex entities with optional words

from adapt.

Comments (6)

forslund avatar forslund commented on May 25, 2024

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.

corus87 avatar corus87 commented on May 25, 2024

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.

forslund avatar forslund commented on May 25, 2024

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.

forslund avatar forslund commented on May 25, 2024

"(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.

corus87 avatar corus87 commented on May 25, 2024

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.

forslund avatar forslund commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.