ngrams_aggregate.lua 473 B

12345678910111213141516171819202122
  1. -- Aggregate the output from ngrams.lua.
  2. -- Get the data from all shards.
  3. counts = {}
  4. dofile("/tmp/lua-output")
  5. -- Put the data into a sortable "array".
  6. countArray = {}
  7. for ngram, count in pairs(counts) do
  8. table.insert(countArray, {count, ngram})
  9. end
  10. -- Sort the data.
  11. function compare(a, b)
  12. return a[1] > b[1]
  13. end
  14. table.sort(countArray, compare)
  15. -- Write the result.
  16. for i, countPair in ipairs(countArray) do
  17. io.write(countPair[1], "\t", countPair[2], "\n")
  18. end