Skip to content
Snippets Groups Projects
Commit 963cb5c4 authored by Felipe Duerno's avatar Felipe Duerno
Browse files

fix error when trying to put folders inside the training data folder

parent b16e3b60
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ LABEL mantainer "Diego Dorgam <diego.dorgam@rocket.chat>" ...@@ -4,6 +4,7 @@ LABEL mantainer "Diego Dorgam <diego.dorgam@rocket.chat>"
ENV HUBOT_LANG='en' \ ENV HUBOT_LANG='en' \
HUBOT_CORPUS='training_data/corpus.yml' \ HUBOT_CORPUS='training_data/corpus.yml' \
HUBOT_RECURSIVE_TRAINING=false \
HUBOT_ADAPTER=rocketchat \ HUBOT_ADAPTER=rocketchat \
HUBOT_OWNER=RocketChat \ HUBOT_OWNER=RocketChat \
HUBOT_NAME=HubotNatural \ HUBOT_NAME=HubotNatural \
......
...@@ -51,6 +51,7 @@ services: ...@@ -51,6 +51,7 @@ services:
- HUBOT_DESCRIPTION='Hubot natural language processing' - HUBOT_DESCRIPTION='Hubot natural language processing'
- HUBOT_LOG_LEVEL=debug - HUBOT_LOG_LEVEL=debug
- HUBOT_CORPUS=training_data/corpus.yml - HUBOT_CORPUS=training_data/corpus.yml
- HUBOT_RECURSIVE_TRAINING=false
- HUBOT_LANG=pt - HUBOT_LANG=pt
- RESPOND_TO_DM=true - RESPOND_TO_DM=true
- RESPOND_TO_LIVECHAT=true - RESPOND_TO_LIVECHAT=true
......
...@@ -25,13 +25,18 @@ common.stringElseRandomKey = (variable) -> ...@@ -25,13 +25,18 @@ common.stringElseRandomKey = (variable) ->
if variable instanceof Array if variable instanceof Array
variable[Math.floor(Math.random() * variable.length)] variable[Math.floor(Math.random() * variable.length)]
getYAMLFiles = (filepath) -> getYAMLFiles = (filepath, recursive = false) ->
listFile = fs.readdirSync filepath listFile = fs.readdirSync filepath
dataFiles = [] dataFiles = []
if listFile.length > 0 for filename in listFile
dataFiles = listFile.map (filename) -> file = filepath + '/' + filename
return yaml.safeLoad fs.readFileSync filepath + '/' + filename, 'utf8' if fs.lstatSync(file).isFile()
else 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.') console.error('The directory: ' + filepath + ' is empty.')
return dataFiles return dataFiles
...@@ -61,7 +66,8 @@ common.loadConfigfile = (filepath) -> ...@@ -61,7 +66,8 @@ common.loadConfigfile = (filepath) ->
return yaml.safeLoad fs.readFileSync filepath, 'utf8' return yaml.safeLoad fs.readFileSync filepath, 'utf8'
else if fs.lstatSync(filepath).isDirectory() else if fs.lstatSync(filepath).isDirectory()
yamlFiles = getYAMLFiles(filepath) recursiveTraining = process.env.HUBOT_RECURSIVE_TRAINING || false
yamlFiles = getYAMLFiles(filepath, recursiveTraining)
return concatYAMLFiles(yamlFiles) return concatYAMLFiles(yamlFiles)
catch err catch err
......
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