NaturalNode / natural

general natural language facilities for node
MIT License
10.56k stars 861 forks source link

Chaining of commands? #439

Open giorgio79 opened 6 years ago

giorgio79 commented 6 years ago

Like jquery, or en-pos https://github.com/FinNLP/en-pos

Would be nice if we could

natural("my nice text").sentences().tokenize().tag();

Here is a sample from en-pos

const Tag = require("en-pos").Tag;
var tags = new Tag(["this","is","my","sentence"])
.initial() // initial dictionary and pattern based tagging
.smooth() // further context based smoothing
.tags;
console.log(tags);
// ["DT","VBZ","PRP$","NN"]
Hugo-ter-Doest commented 6 years ago

Would be nice indeed. It would require some revision of methods so that they return an object with the right methods attached. I will put it on the backlog. Feel free to create a PR!

Hugo

kettanaito commented 5 years ago

Alternatively, you can get rid of binding functions to explicit this and use functional composition (which doesn't work now):

const transformSentence = compose(
  classifier.classify,
  tagger.tag,
  tokenizer.tokenize,
)

Functional composition is much more powerful than object chaining. I do understand the implications this puts into internal design of a library, it's just a suggestion ;)