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

NLP for dates #12

Closed
uncenter opened this issue Feb 9, 2024 · 31 comments
Closed

NLP for dates #12

uncenter opened this issue Feb 9, 2024 · 31 comments

Comments

@uncenter
Copy link

uncenter commented Feb 9, 2024

Numbat supports mathematical calculations just fine but it doesn't have date calculations like Raycast. I looked around for some date NLP libraries in Rust but couldn't find many still maintained, maybe you or other people know of some though.

Screenshot 2024-02-09 at 12 37 19 (Arc)

Screenshot 2024-02-09 at 12 39 21 (Arc)

@MatthiasGrandl
Copy link
Owner

See: sharkdp/numbat#327
sharkdp/numbat#287 (merged just 2 hours ago)

@uncenter
Copy link
Author

uncenter commented Feb 9, 2024

Oh wow! The timing ahah. Can't wait to see that in loungy :)

@MatthiasGrandl
Copy link
Owner

Yeah I hope Numbat will be enough to support this. To be honest the calculator in raycast is super dope and just feels very natural. Numbat is definitely much more strict with their inputs.

@uncenter
Copy link
Author

uncenter commented Feb 9, 2024

Yeah. Better than nothing I suppose!

@MatthiasGrandl
Copy link
Owner

There is also this https://erhanbaris.github.io/smartcalc-app/ which might be worth looking into. Although I am not sure if it is abandoned. It seems to be better for this usecase than numbat though and pretty close to raycast.

@MatthiasGrandl
Copy link
Owner

MatthiasGrandl commented Feb 9, 2024

Oh and there is also https://github.com/printfn/fend ... not a library :(

@uncenter
Copy link
Author

uncenter commented Feb 9, 2024

There is also this erhanbaris.github.io/smartcalc-app which might be worth looking into. Although I am not sure if it is abandoned. It seems to be better for this usecase than numbat though and pretty close to raycast.

Ooh this does look good!

@sharkdp
Copy link

sharkdp commented Feb 10, 2024

To be honest the calculator in raycast is super dope and just feels very natural. Numbat is definitely much more strict with their inputs.

Having a strict syntax for Numbat is a design choice. We want users to be able to trust the result of their computations. If you have loose/ambiguous parsing rules, it's sometimes hard to tell if the calculator understands your input in the same way that you do.

Yeah. Better than nothing I suppose!

As you found out, date-time support has just landed. It's not even released yet (as we might change e.g. function names), but you can play with it on https://numbat.dev/ and/or read the documentation here: https://numbat.dev/doc/date-and-time.html

Please give us feedback and tell us if you think there is something we can improve (ideally, create a new ticket in our repository). There is already a collection of date-time-related enhancements in this ticket: sharkdp/numbat#323.

There is also this https://erhanbaris.github.io/smartcalc-app/ which might be worth looking into. Although I am not sure if it is abandoned. It seems to be better for this usecase than numbat though and pretty close to raycast.

Interesting reference, I hadn't seen that before. What are some things that smartcalc-app can do that Numbat can't?

Please note that https://github.com/erhanbaris/smartcalc is GPL-2.0 licensed, so integration into your MIT licensed tool is not possible without relicensing.

@MatthiasGrandl
Copy link
Owner

@sharkdp thanks for the input! You are definitely right about the license.

What are some things that smartcalc-app can do that Numbat can't?

i think it’s only the less strict matching that feels better for this usecase. I 100% agree that numbat is the better library overall.

@uncenter
Copy link
Author

uncenter commented Feb 10, 2024

Having a strict syntax for Numbat is a design choice.

I totally understand, I wasn't trying to make a criticism of the library at all. Compared to Raycast though a more general syntax might be more favorable, though not necessarily!

As you found out, date-time support has just landed. It's not even released yet (as we might change e.g. function names), but you can play with it on numbat.dev and/or read the documentation here: numbat.dev/doc/date-and-time.html

I'll try it out and let you know how it is :)

@sharkdp
Copy link

sharkdp commented Feb 10, 2024

Sorry if I came off as bitter — I'm not! I am actually really excited that you, @MatthiasGrandl, decided to embed Numbat into your tool. I hope that it will be a fruitful collaboration and I'm looking forward to any kind of feedback we can get.

@sharkdp
Copy link

sharkdp commented Feb 12, 2024

Numbat v1.10 has been released now with initial support for dates & times. We made a couple of changes to the syntax since my last post. See https://numbat.dev/doc/date-and-time.html and https://numbat.dev/doc/conversion-functions.html for an overview of the new features.

@MatthiasGrandl
Copy link
Owner

@sharkdp super cool, will update soon. I played around a bit on the numbat website and it seems very nice.

@MatthiasGrandl
Copy link
Owner

@sharkdp do I need to load some extra module? I just updated, but it doesn't seem to recognize now().

@sharkdp
Copy link

sharkdp commented Feb 12, 2024

Do you happen to have an old version of the prelude/standard library installed on your system? (e.g. in ~/.config/numbat/modules or /usr/share/numbat/modules), like from installing via brew?

@MatthiasGrandl
Copy link
Owner

I did still have 1.9.0 of the numbat CLI installed. Just removed it and confirmed no numbat/modules folder is present, but still can't get it to work 🤔

@sharkdp
Copy link

sharkdp commented Feb 12, 2024

Hm. How did you install and how do you run Numbat?

Does use datetime::functions work?

@sharkdp
Copy link

sharkdp commented Feb 12, 2024

If you built it from source, make sure that the prelude is up to date at build time.

@MatthiasGrandl
Copy link
Owner

@MatthiasGrandl
Copy link
Owner

Does use datetime::functions work?

it says datetime is private

@sharkdp
Copy link

sharkdp commented Feb 12, 2024

Does use datetime::functions work?

it says datetime is private

I meant.. as a Numbat command: use datetime::functions.

it doesn't seem to recognize now().

What is the error message? Do other new features like 42 -> hex work?

@MatthiasGrandl
Copy link
Owner

What is the error message?

now()

ResolverError(
    ParseErrors(
        [
            ParseError {
                kind: ExpectedPrimary,
                span: Span {
                    start: SourceCodePositition {
                        byte: 7,
                        line: 1,
                        position: 8,
                    },
                    end: SourceCodePositition {
                        byte: 7,
                        line: 1,
                        position: 8,
                    },
                    code_source_id: 86,
                },
            },
        ],
    ),
)

42 -> hex

TypeCheckError(
    UnknownIdentifier(
        Span {
            start: SourceCodePositition {
                byte: 6,
                line: 1,
                position: 7,
            },
            end: SourceCodePositition {
                byte: 8,
                line: 1,
                position: 9,
            },
            code_source_id: 108,
        },
        "he",
        None,
    ),
)

@sharkdp
Copy link

sharkdp commented Feb 12, 2024

It looks like you're not sending the last character of input to Numbat?

@MatthiasGrandl
Copy link
Owner

OMG no everything is working as expected on numbat. I am just an idiot and not handling those kinds of results at all... 🤦 sorry for not debugging properly and wasting your time!

@MatthiasGrandl
Copy link
Owner

image

jup works nicely!!

@MatthiasGrandl
Copy link
Owner

made it a bit prettier and pushed

@uncenter
Copy link
Author

I don't think it makes sense for Numbat to make these changes but it might make sense for Loungy to do some processing on this queries before sending them to Numbat. For example, given two weeks from now becomes now() + two weeks by replacing now with now(), from with +, and switching the order.

@MatthiasGrandl
Copy link
Owner

yeah I think that could be easily achieved by matching the phrase from now

@MatthiasGrandl
Copy link
Owner

image

@uncenter
Copy link
Author

uncenter commented Feb 12, 2024

So cool! I think that solves my original issue, feel free to close this :)

@MatthiasGrandl
Copy link
Owner

yeah I am sure more such patterns will come up in the future, but for now that should be good enough :)

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

No branches or pull requests

3 participants