Learn a language by code, natural language processing in JavaScript



Most common use of a natural language processor is to create a chat bot. That’s great! however, there are other uses and I think I have found a very cool javascript library which can do this in browser.

It’s called compromise. The creator of this library Spencer Kelly describes it as not the cleverest, but I think it’s pretty darn clever.

You can find it on GitHub:

We can do a lot with this tiny library but I am going to go through a very simple example of how you can use this to learn a language and coding within a browser. You can do the same on the server (node.js) if you like. I think doing something like this within a browser is going to help a lot more people and it’s great fun!

Lets do this

<!-- Point to the library -->
<script src="https://unpkg.com/compromise@latest/builds/compromise.min.js"></script>

What did she do?

let doc = nlp('She sells seashells by the seashore.');
let sentence = doc.sentences();

predict = sentence.toFutureTense().out('text');
// She will sell seashells by the seashore.

reflect = sentence.toPastTense().out('text');
// She sold seashells by the seashore.


// Plural + Future
fbStatus = nlp("Dinosaur is back.").nouns(0).toPlural().sentences().toFutureTense().out('text');

// Dinosaurs will be back.

// And a lot more!

So this is just a very small part of what compromise NLP library can do. May be you can create a tool to teach language and code? Or create a cool chat bot of your own.

Happy coding, happy learning.