borenet | 93558dc | 2015-06-25 07:47:40 -0700 | [diff] [blame] | 1 | -- Aggregate the output from ngrams.lua. |
| 2 | |
| 3 | -- Get the data from all shards. |
| 4 | counts = {} |
| 5 | dofile("/tmp/lua-output") |
| 6 | |
| 7 | -- Put the data into a sortable "array". |
| 8 | countArray = {} |
| 9 | for ngram, count in pairs(counts) do |
| 10 | table.insert(countArray, {count, ngram}) |
| 11 | end |
| 12 | |
| 13 | -- Sort the data. |
| 14 | function compare(a, b) |
| 15 | return a[1] > b[1] |
| 16 | end |
| 17 | table.sort(countArray, compare) |
| 18 | |
| 19 | -- Write the result. |
| 20 | for i, countPair in ipairs(countArray) do |
| 21 | io.write(countPair[1], "\t", countPair[2], "\n") |
| 22 | end |