You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bayes_classify.lua 762B

1234567891011121314151617181920212223242526
  1. -- Lua script to perform bayes classification
  2. -- This script accepts the following parameters:
  3. -- key1 - prefix for bayes tokens (e.g. for per-user classification)
  4. -- key2 - set of tokens encoded in messagepack array of int64_t
  5. local prefix = KEYS[1]
  6. local input_tokens = cmsgpack.unpack(KEYS[2])
  7. local output_spam = {}
  8. local output_ham = {}
  9. for i, token in ipairs(input_tokens) do
  10. local token_data = redis.call('HMGET', prefix .. tostring(token), 'H', 'S')
  11. if token_data then
  12. local ham_count = tonumber(token_data[1]) or 0
  13. local spam_count = tonumber(token_data[2]) or 0
  14. output_ham[i] = ham_count
  15. output_spam[i] = spam_count
  16. else
  17. output_ham[i] = 0
  18. output_spam[i] = 0
  19. end
  20. end
  21. return cmsgpack.pack({ output_ham, output_spam })