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>"
ENV HUBOT_LANG='en' \
HUBOT_CORPUS='training_data/corpus.yml' \
HUBOT_RECURSIVE_TRAINING=false \
HUBOT_ADAPTER=rocketchat \
HUBOT_OWNER=RocketChat \
HUBOT_NAME=HubotNatural \
......
......@@ -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
......
......@@ -25,13 +25,18 @@ common.stringElseRandomKey = (variable) ->
if variable instanceof Array
variable[Math.floor(Math.random() * variable.length)]
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
......@@ -61,7 +66,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
......
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