Skip to content

Commit

Permalink
Function breakIntoSessions implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
ThiagoNelsi committed Dec 30, 2019
1 parent 3bcbb3b commit 7461072
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ credentials/*.json

# Tests
robots/test-watson.js
test.js

# Logs
logs
Expand Down
53 changes: 53 additions & 0 deletions robots/text-robot.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ exports.text_robot = async content => {
console.log('> [text-robot] Limpando conteúdo...')
sanitizeWikipediaContent(content)

console.log('> [text-robot] Quebrando texto em sessões...')
breakContentIntoSessions(content)
console.log(content.sessions)
process.exit(0)

console.log('> [text-robot] Resumindo conteúdo')
await summarizeAllContent(content)
console.log('> [text-robot] Resumo: ' + content.summarizedSourceContent)
Expand All @@ -39,6 +44,54 @@ exports.text_robot = async content => {

}

function breakContentIntoSessions(content) {

content.sessions = []
content.lines = removeBlankLines(content.sourceContentOriginal.split('\n'))


for(let i = 0; i < content.lines.length; i++) {

var j = i + 1
let session = []

if(content.lines[i].trim()[0] === '=') {

session = {
titulo:removeMarkdowns(content.lines[i].trim()),
text:[]
}

while(j < content.lines.length && content.lines[j].trim()[0] != '=') {

session.text.push(content.lines[j].trim())
j++

}

session.text = session.text.join('\n')
content.sessions.push(session)

}

}

function removeMarkdowns(text) {
return text.split('=').join('').trim()
}

function removeBlankLines(text) {
const lines = text.filter((line) => {
if(line.trim().length === 0) {
return false
}
return true
})
return lines
}

}

function sanitizeWikipediaContent(content) {

content.sanitizedContent = removeBlankLinesAndMarkdowns(content.sourceContentOriginal)
Expand Down

0 comments on commit 7461072

Please sign in to comment.