<commit_before># Description
#   Natural language queries for factoids
#
# Dependencies:
#   "natural": "0.1.19"
#
# Configuration:
#   None
#
# Commands:
#   None
#
# Notes:
#   None
#
# Author:
#   ivey

FTNatural = require('natural')
FTStemmer = FTNatural.PorterStemmer

factoidkeys = [
  ['wtfischef', ['chef', 'what', 'is']],
  ['smtest', ['sparklemotion', 'monkey', 'apple']]
]

compare = (tokens, factoidkey) ->
  keywords = factoidkey[1]
  contained = (word for word in keywords when word in tokens)
  contained.length == keywords.length

module.exports = (robot) ->
  robot.hear /(.*)\?$/i, (msg) ->
    stems = FTStemmer.tokenizeAndStem(msg.match[1])
    stems.unshift msg.message.user.room.replace(/@.*/,'')
    result = (k for k in factoidkeys when compare(stems,k))
    if result[0]
      robot.receive new TextMessage(msg.message.user, "~#{result[0]}")<commit_msg>better stemming<commit_after># Description
#   Natural language queries for factoids
#
# Dependencies:
#   "natural": "0.1.19"
#
# Configuration:
#   None
#
# Commands:
#   stemming <words> - how would natural factoid stem a set of words?
#
# Notes:
#   None
#
# Author:
#   ivey

TextMessage = require('hubot').TextMessage
FTNatural = require('natural')
FTStemmer = FTNatural.PorterStemmer

factoidkeys = [
  ['merlinsupport', ['merlin', 'who', 'support']],
  ['chefsupport', ['chef', 'who', 'support']]
]

compare = (tokens, factoidkey) ->
  keywords = factoidkey[1]
  contained = (word for word in keywords when word in tokens)
  contained.length == keywords.length

module.exports = (robot) ->
  robot.respond /stemming (.*)/i, (msg) ->
    msg.send FTStemmer.tokenizeAndStem(msg.match[1]).toString()

  robot.hear /(.*)\?$/i, (msg) ->
    stems = FTStemmer.tokenizeAndStem(msg.match[1])
    stems.unshift msg.message.user.room.replace(/@.*/,'')
    result = (k for k in factoidkeys when compare(stems,k))
    if result[0]
      robot.receive new TextMessage(msg.message.user, "~#{result[0][0]}")
{'fraction_non_alphanumeric': 0.17290192113245703, 'fraction_numerical': 0.00910010111223458, 'mean_word_length': 3.9848866498740554, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3805497', 'n_tokens_mistral': 735, 'n_tokens_neox': 717, 'n_words': 160}