Skip to content
Snippets Groups Projects
Unverified Commit 3d1b04dd authored by Diego Dorgam's avatar Diego Dorgam Committed by GitHub
Browse files

Merge pull request #39 from lappis-unb/folder_inside_training_data

Add recursive strategy when reading the training corpus
parents b521a2ee bbf19ac7
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
......
......@@ -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
......
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