Skip to content
Snippets Groups Projects
Commit 31dce57a authored by Diego's avatar Diego
Browse files

insert transferTOhuman function

parent 856f5d58
No related branches found
No related tags found
No related merge requests found
...@@ -8,4 +8,5 @@ hubot.env ...@@ -8,4 +8,5 @@ hubot.env
.DS_Store .DS_Store
Procfile Procfile
train.js train.js
scripts/config/rocket.yml env.sh
brill.js
...@@ -2,7 +2,7 @@ FROM node:alpine ...@@ -2,7 +2,7 @@ FROM node:alpine
LABEL mantainer "Diego Dorgam <diego.dorgam@rocket.chat>" LABEL mantainer "Diego Dorgam <diego.dorgam@rocket.chat>"
ENV LISTEN_ON_ALL_PUBLIC=false RESPOND_TO_DM=true RESPOND_TO_EDITED=true HUBOT_CORPUS='corpus.yml' HUBOT_ADAPTER=rocketchat HUBOT_OWNER=RocketChat HUBOT_NAME=HubotNatural HUBOT_DESCRIPTION="Processamento de linguagem natural com hubot" ROCKETCHAT_URL=http://rocketchat:3000 ROCKETCHAT_ROOM=GENERAL RESPOND_TO_DM=true ROCKETCHAT_USER=chatbot ROCKETCHAT_PASSWORD=@12345@ ROCKETCHAT_AUTH=password HUBOT_LOG_LEVEL=debug ENV HUBOT_LANG='pt' RESPOND_TO_LIVECHAT=true LISTEN_ON_ALL_PUBLIC=false RESPOND_TO_DM=true RESPOND_TO_EDITED=true HUBOT_CORPUS='corpus.yml' HUBOT_ADAPTER=rocketchat HUBOT_OWNER=RocketChat HUBOT_NAME=HubotNatural HUBOT_DESCRIPTION="Processamento de linguagem natural com hubot" ROCKETCHAT_URL=http://rocketchat:3000 ROCKETCHAT_ROOM=GENERAL RESPOND_TO_DM=true ROCKETCHAT_USER=chatbot ROCKETCHAT_PASSWORD=@12345@ ROCKETCHAT_AUTH=password HUBOT_LOG_LEVEL=debug
RUN npm install -g coffee-script hubot yo generator-hubot natural js-yaml && \ RUN npm install -g coffee-script hubot yo generator-hubot natural js-yaml && \
apk --update add --no-cache git && \ apk --update add --no-cache git && \
......
version: '2'
services:
hubot-natural:
image: diegodorgam/hubot-natural:alpine
environment:
ROCKETCHAT_URL: 'https://demo.rocket.chat'
HUBOT_ADAPTER: rocketchat
HUBOT_NAME: 'Cat Bot'
HUBOT_DESCRIPTION: 'Processamento de linguagem natural com hubot'
ROCKETCHAT_ROOM: j8pjQdHtZR5JnGF2S
RESPOND_TO_DM: 'true'
RESPOND_TO_LIVECHAT: 'true'
ROCKETCHAT_USER: catbot
ROCKETCHAT_PASSWORD: '@cat!bot'
ROCKETCHAT_AUTH: password
HUBOT_LOG_LEVEL: debug
HUBOT_CORPUS: 'rocket.yml'
fs = require 'fs' fs = require 'fs'
path = require 'path' path = require 'path'
natural = require 'natural' natural = require 'natural'
PorterStemmerPt = require path.join '..','..','node_modules','natural','lib','natural','stemmers','porter_stemmer_pt.js' lang = (process.env.HUBOT_LANG || 'en')
if lang == "en"
PorterStemmer = require path.join '..','..','node_modules','natural','lib','natural','stemmers','porter_stemmer.js'
else
PorterStemmer = require path.join '..','..','node_modules','natural','lib','natural','stemmers','porter_stemmer_' + lang + '.js'
config = {} config = {}
events = {} events = {}
...@@ -42,6 +46,19 @@ sendWithNaturalDelay = (msgs, elapsed=0) -> ...@@ -42,6 +46,19 @@ sendWithNaturalDelay = (msgs, elapsed=0) ->
cb?() cb?()
, delay , delay
livechatTransferHuman = (res) ->
setTimeout ->
res.robot.adapter.callMethod 'livechat:transfer',
roomId: res.envelope.room
departmentId: process.env.DEPARTMENT_ID
, 1000
setUserName = (res, name) ->
res.robot.adapter.callMethod 'livechat:saveInfo',
_id: res.envelope.user.id
name: name
,
_id: res.envelope.room
classifyInteraction = (interaction, classifier) -> classifyInteraction = (interaction, classifier) ->
if Array.isArray interaction.classifiers if Array.isArray interaction.classifiers
...@@ -52,7 +69,7 @@ classifyInteraction = (interaction, classifier) -> ...@@ -52,7 +69,7 @@ classifyInteraction = (interaction, classifier) ->
classifier.addDocument(doc, interaction.node.name) classifier.addDocument(doc, interaction.node.name)
if Array.isArray interaction.next?.interactions if Array.isArray interaction.next?.interactions
interaction.next.classifier = new natural.LogisticRegressionClassifier(PorterStemmerPt) interaction.next.classifier = new natural.LogisticRegressionClassifier(PorterStemmer)
for nextInteractionName in interaction.next.interactions for nextInteractionName in interaction.next.interactions
nextInteraction = config.interactions.find (n) -> nextInteraction = config.interactions.find (n) ->
return n.node.name is nextInteractionName return n.node.name is nextInteractionName
...@@ -63,7 +80,7 @@ classifyInteraction = (interaction, classifier) -> ...@@ -63,7 +80,7 @@ classifyInteraction = (interaction, classifier) ->
interaction.next.classifier.train() interaction.next.classifier.train()
if interaction.multi == true if interaction.multi == true
interaction.classifier = new natural.LogisticRegressionClassifier(PorterStemmerPt) interaction.classifier = new natural.LogisticRegressionClassifier(PorterStemmer)
for doc in interaction.classifiers for doc in interaction.classifiers
interaction.classifier.addDocument(doc, doc) interaction.classifier.addDocument(doc, doc)
interaction.classifier.train() interaction.classifier.train()
...@@ -100,7 +117,7 @@ incErrors = (res) -> ...@@ -100,7 +117,7 @@ incErrors = (res) ->
key = 'errors_'+res.envelope.room+'_'+res.envelope.user.id key = 'errors_'+res.envelope.room+'_'+res.envelope.user.id
errors = res.robot.brain.get(key) or 0 errors = res.robot.brain.get(key) or 0
errors++ errors++
console.log 'inc errors', errors console.log 'inc errors ', errors
res.robot.brain.set(key, errors) res.robot.brain.set(key, errors)
return errors return errors
...@@ -120,7 +137,7 @@ module.exports = (_config, robot) -> ...@@ -120,7 +137,7 @@ module.exports = (_config, robot) ->
console.log 'Processing interactions' console.log 'Processing interactions'
console.time 'Processing interactions (Done)' console.time 'Processing interactions (Done)'
classifier = new natural.LogisticRegressionClassifier(PorterStemmerPt) classifier = new natural.LogisticRegressionClassifier(PorterStemmer)
#console.log(config.interactions) #console.log(config.interactions)
for interaction in config.interactions for interaction in config.interactions
{node, classifiers, event} = interaction {node, classifiers, event} = interaction
...@@ -158,7 +175,6 @@ module.exports = (_config, robot) -> ...@@ -158,7 +175,6 @@ module.exports = (_config, robot) ->
newMsg = buildClassificationDebugMsg(res, classifications) newMsg = buildClassificationDebugMsg(res, classifications)
robot.adapter.chatdriver.customMessage(newMsg); robot.adapter.chatdriver.customMessage(newMsg);
if classifications[0].value >= trust if classifications[0].value >= trust
clearErrors res clearErrors res
[node_name, sub_node_name] = classifications[0].label.split('|') [node_name, sub_node_name] = classifications[0].label.split('|')
...@@ -198,8 +214,9 @@ module.exports = (_config, robot) -> ...@@ -198,8 +214,9 @@ module.exports = (_config, robot) ->
currentNode = nodes[node_name or error_node_name] currentNode = nodes[node_name or error_node_name]
currentNode.process.call @, res, msg, subClassifications currentNode.process.call @, res, msg, subClassifications
robot.hear /(.+)/i, (res) -> robot.hear /(.+)/i, (res) ->
# console.log(res)
console.log(res.message)
res.sendWithNaturalDelay = sendWithNaturalDelay.bind(res) res.sendWithNaturalDelay = sendWithNaturalDelay.bind(res)
msg = res.match[0].replace res.robot.name+' ', '' msg = res.match[0].replace res.robot.name+' ', ''
msg = msg.replace(/^\s+/, '') msg = msg.replace(/^\s+/, '')
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment