Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Logical operations in match #1089

Closed
thegoatherder opened this issue Feb 9, 2024 · 2 comments
Closed

Feature request: Logical operations in match #1089

thegoatherder opened this issue Feb 9, 2024 · 2 comments

Comments

@thegoatherder
Copy link
Contributor

thegoatherder commented Feb 9, 2024

It would be cool if we could match a #Value or #TextValue with logical arithmetic conditions applied

Example

nlp('I will see him in 12 months').match('#Value>=12').tag('YearsDuration')
nlp('I will see him in 48 hours').match('#Value>=24').tag('DaysDuration')

Even cooler if we can do string conditions / lookups too:

nlp('I prescribed him 1000mg of cyanide').match('#Value>=100 #Unit:in:[mg,g,kg] of? (cyanide|arsenic)').tag('LethalDosage')
@thegoatherder thegoatherder changed the title Feature request: Logical arithmetic operations on #Value, #TextValue in match Feature request: Logical operations in match Feb 9, 2024
@spencermountain
Copy link
Owner

hey, very neat idea -
for >, < numbers, you can currently do:

nlp('fifty five but not 12 or thirteen').values().greaterThan(20)// "fifty five"

Happy to add a .values().isUnit(['kg', 'mg']) , so you can chain the two filters together. That should work.

I can add a similar method for dates, if you'd like. Just checked, and am surprised we don't have that one, already.
Will try and do it today.
cheers

@spencermountain
Copy link
Owner

ok, .numbers().isUnit(unit) has been added in compromise@14.12.0
and
dates().isBefore(iso) and dates().isAfter(iso) methods have been added in compromise-dates@3.5.0
😅
let me know if something weird appears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants