Yomguithereal / talisman

Straightforward fuzzy matching, information retrieval and NLP building blocks for JavaScript.
https://yomguithereal.github.io/talisman/
MIT License
704 stars 47 forks source link

What's the best way to use this library from ClojureScript in the browser? #176

Open harold opened 3 years ago

harold commented 3 years ago

Hi! Found this library from the docs of the excellent clj-fuzzy, which we have used to great success.

This lib looks great.

Can you advise on the best way to use this from cljs on the front end?

In particular we'd like to user jaro-winkler to compare strings.

Thanks in advance for your time and consideration.

Yomguithereal commented 3 years ago

Hello @harold. I haven't used Clojurescript since quite a long time now so I am not sure what I would advise to better load this JavaScript code into your own but I am sure this can be done. However, you will maybe require some glue code such as the one I had (for the reverse purpose) in clj-fuzzy here so that you can pass and get usual Clojure values instead of js wrapped ones? But maybe this has changed now and is taken care of automatically?

harold commented 3 years ago

Thanks for your reply. That glue code is interesting and helpful.

I guess one question I have is about these import statements:

It looks like there is some browser support for this (https://caniuse.com/es6-module-dynamic-import), but maybe it's better to use something like webpack? That might allow me to pre-produce a small .js file with just the code I need in it, then I could just interop from cljs directly.

Seems like there are a few options. If we end up going this way I will report my findings.

Regardless, thanks for all your work in this area, it's really very much appreciated.

Yomguithereal commented 3 years ago

@harold the lib's code is indeed written using ES6 import syntax but the shipped code is transpiled. Check the actual code you get when installing the lib under node_modules and you'll see those import & export disappear in favor of commonjs requires. So it should not be an issue on your side and I guess ClojureScript will handle this naturally, but I have been out of touch with it since a long time.

Yomguithereal commented 3 years ago

Sorry I closed/reopen the issue by mistake.

harold commented 3 years ago

Check the actual code you get when installing the lib

Oh, that's interesting! I will, thanks!

harold commented 3 years ago

Looked into this a bit more this afternoon.

There are hints around about possible ways to do this:

I poked around a bit and it didn't immediately work for me (says more about me and my project than anything else, ha!)

I'm sure it could be made to work with more effort, and if anyone does get it working I'd love to hear.

For now, since we're really only trying to do jaro-winkler, I think we're going to start with this single-file implementation:

Thanks again for all your great and inspiring work. :bowing_man: