spencermountain/compromise

Feature request: Logical operations in match

thegoatherder opened this issue · 2 comments

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')

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

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.