Node Summary – Naive summarization algorithm for Node.js
jbrooksuk.github.io
jbrooksuk.github.io
I notice it was originally written in synchronous style, but rewritten using callbacks. Callbacks don't magically make something CPU-bound asynchronous. They just make it full of callbacks.
The reason it's "node-summary" is because that's what I was doing at the time, Node.js and never thought it would be as popular as it's become, so it's not neat or well coded.
Feel free to make changes though :)
I'd love it if there was a quick way to analyze a code base to tell you what level of asychronicity you've achieved. I don't know how such a tool would be written, but I reckon you'd need to start with a list of node.js core API functions sorted into those that are sync and those that are async. Then the level of sync to async is roughly a function of average function size and the ratio of sync to async functions. Many small async functions that consume async core functions would be ideal.
That being said, still kudos to the author of this lib and other others for contributing code to the commons.
1. You want to add optional results. See underscore's each function that returns an object for the current iteration, then an optional iterator value in addition, which you sometimes need.
2. There are many functional patterns that utilize callbacks where you want to pass functions in as parameters (which could do anything, including accessing the file system or waiting on an external call). Underscore also has loads of examples where this is the case, despite being a sync library.
3. This is probably the least valid reason, but sometimes you do not know going in whether or not a function you are writing will be async. If you create a sync interface, it will need to be changed if the function needs to be async in the future, or if it needs to pass additional results. In my experience the latter is not terribly uncommon. The former is pretty unlikely in library code, but I could see it happening in application code regularly. Breaking apis is not fun for anyone.
The function passed to _.each is used to access the elements of an array. It is called once for each element. It is used as a mechanism to pass a block of code to _.each, not to get a result from _.each.
An implementation of Luhn's algorithm (which accepts a URL or HTML input and also handles relatively clean text extraction with boilerpipe) is available here: http://nbviewer.ipython.org/github/ptwobrussell/Mining-the-S...
I haven't kept up much with "state of the art" summarization techniques, but this approach is pretty intuitive and works about as well as anything I can imagine (without getting into machine-driven language generation, which is a whole different topic.)
You can change the code to run only -> for j in range(0, i)
* (instead of range(0, n))
and then store the same score both in values[i][j] and values[j[i]
I'll look at implementing your changes shortly, perhaps after a rewrite to circumvent the blocking behaviour experienced with the callbacks.
Thanks!
I was wondering why it's being starred again :)