diff --git a/Dockerfile b/Dockerfile index ed7f3064d559faed972678788b2a2a2f3232533a..5a338258342d8e3414d32322c76f589288d45c30 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,7 @@ LABEL mantainer "Diego Dorgam <diego.dorgam@rocket.chat>" ENV HUBOT_LANG='en' \ HUBOT_CORPUS='training_data/corpus.yml' \ + HUBOT_RECURSIVE_TRAINING=false \ HUBOT_ADAPTER=rocketchat \ HUBOT_OWNER=RocketChat \ HUBOT_NAME=HubotNatural \ diff --git a/docker-compose.yml b/docker-compose.yml index afaa03e066d540d6356c751fc29aa897d1c76872..6989eaf088b04649aeffafa0d99af5aaf3dea91c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -51,6 +51,7 @@ services: - HUBOT_DESCRIPTION='Hubot natural language processing' - HUBOT_LOG_LEVEL=debug - HUBOT_CORPUS=training_data/corpus.yml + - HUBOT_RECURSIVE_TRAINING=false - HUBOT_LANG=pt - RESPOND_TO_DM=true - RESPOND_TO_LIVECHAT=true diff --git a/scripts/lib/common.coffee b/scripts/lib/common.coffee index 13c2cb4d092e9c8519fb5808c7091c48df2300e4..6c55908c74a87784b711b9c941d246c017d96193 100644 --- a/scripts/lib/common.coffee +++ b/scripts/lib/common.coffee @@ -31,14 +31,19 @@ common.sendMessages = (messages, msg, variables = {}) -> messages = messages.map (message) -> return common.msgVariables message, msg, variables msg.sendWithNaturalDelay messages - -getYAMLFiles = (filepath) -> + +getYAMLFiles = (filepath, recursive = false) -> listFile = fs.readdirSync filepath + dataFiles = [] - if listFile.length > 0 - dataFiles = listFile.map (filename) -> - return yaml.safeLoad fs.readFileSync filepath + '/' + filename, 'utf8' - else + for filename in listFile + file = filepath + '/' + filename + if fs.lstatSync(file).isFile() + dataFiles.push(yaml.safeLoad fs.readFileSync file, 'utf8') + else if recursive + dataFiles = dataFiles.concat(getYAMLFiles file, recursive) + + if dataFiles.lenght is 0 console.error('The directory: ' + filepath + ' is empty.') return dataFiles @@ -68,7 +73,8 @@ common.loadConfigfile = (filepath) -> return yaml.safeLoad fs.readFileSync filepath, 'utf8' else if fs.lstatSync(filepath).isDirectory() - yamlFiles = getYAMLFiles(filepath) + recursiveTraining = process.env.HUBOT_RECURSIVE_TRAINING || false + yamlFiles = getYAMLFiles(filepath, recursiveTraining) return concatYAMLFiles(yamlFiles) catch err