Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detecção de Sentimentos e Suporte a Idiomas #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 50 additions & 5 deletions robots/text.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const algorithmia = require('algorithmia')
const algorithmiaApiKey = require('../credentials/algorithmia.json').apiKey
const algorithmiaLang = require('../credentials/algorithmia.json').lang
const sentenceBoundaryDetection = require('sbd')

const watsonApiKey = require('../credentials/watson-nlu.json').apikey
const NaturalLanguageUnderstandingV1 = require('watson-developer-cloud/natural-language-understanding/v1.js')

const gotitaiApiKey = require('../credentials/gotitai.json').apiKey

const nlu = new NaturalLanguageUnderstandingV1({
iam_apikey: watsonApiKey,
version: '2018-04-05',
Expand All @@ -15,21 +18,24 @@ const state = require('./state.js')

async function robot() {
console.log('> [text-robot] Starting...')
const content = state.load()

var content = state.load()
await fetchContentFromWikipedia(content)
sanitizeContent(content)
breakContentIntoSentences(content)
limitMaximumSentences(content)
await fetchKeywordsOfAllSentences(content)

await fetchGotItAi(content)
state.save(content)

async function fetchContentFromWikipedia(content) {
console.log('> [text-robot] Fetching content from Wikipedia')
const algorithmiaAuthenticated = algorithmia(algorithmiaApiKey)
const wikipediaAlgorithm = algorithmiaAuthenticated.algo('web/WikipediaParser/0.1.2')
const wikipediaResponse = await wikipediaAlgorithm.pipe(content.searchTerm)
var term = {
"articleName": content.searchTerm,
"lang": algorithmiaLang
}
const wikipediaResponse = await wikipediaAlgorithm.pipe(term)
const wikipediaContent = wikipediaResponse.get()

content.sourceContentOriginal = wikipediaContent.content
Expand Down Expand Up @@ -78,9 +84,48 @@ async function robot() {
content.sentences = content.sentences.slice(0, content.maximumSentences)
}

async function fetchGotItAi(content) {
var body = { 'T': content.sourceContentOriginal, 'EM': true };
const fetch = require("node-fetch")
const url = "https://api.gotit.ai/NLU/v1.2/Analyze"
console.log('> [text-robot] Getting feeling from GotIt.Ai')
const getData = async url => {
try {
const response = await fetch(url, {
'method': 'post',
'body': JSON.stringify(body),
'headers': {
'Content-Type': 'application/json',
'Authorization': `Basic ${gotitaiApiKey }`
}
})
const json = await response.json()
let arr = Object.values(json.emotions);
let max = Math.max(...arr);
if(json.emotions.sadness == max) {
content.feeling = "sadness"
} else if(json.emotions.joy == max) {
content.feeling = "sadness"
} else if(json.emotions.fear == max) {
content.feeling = "sadness"
} else if(json.emotions.disgust == max) {
content.feeling = "sadness"
} else if(json.emotions.anger == max) {
content.feeling = "sadness"
} else {
content.feeling = "1"

}
console.log(`> [text-robot] the feeling is ${content.feeling}: by GotIt.Ai`)
} catch (error) {
console.log(`> [text-robot] ${error}`)
}
};
await getData(url)
}

async function fetchKeywordsOfAllSentences(content) {
console.log('> [text-robot] Starting to fetch keywords from Watson')

for (const sentence of content.sentences) {
console.log(`> [text-robot] Sentence: "${sentence.text}"`)

Expand Down
6 changes: 3 additions & 3 deletions robots/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ const rootPath = path.resolve(__dirname, '..')
async function robot() {
console.log('> [video-robot] Starting...')
const content = state.load()

await convertAllImages(content)
await createAllSentenceImages(content)
await createYouTubeThumbnail()
await createAfterEffectsScript(content)
//await createTemplate(content)
await renderVideoWithAfterEffects()

state.save(content)
Expand Down Expand Up @@ -143,8 +143,8 @@ async function robot() {

async function renderVideoWithAfterEffects() {
return new Promise((resolve, reject) => {
const aerenderFilePath = '/Applications/Adobe After Effects CC 2019/aerender'
const templateFilePath = `${rootPath}/templates/1/template.aep`
const aerenderFilePath = '/Applications/Adobe After Effects CC 2019/aerender'
const templateFilePath = `${rootPath}/templates/${content.feeling}/template.aep`
const destinationFilePath = `${rootPath}/content/output.mov`

console.log('> [video-robot] Starting After Effects')
Expand Down
Binary file added templates/anger/earthmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/anger/newsroom.mp3
Binary file not shown.
Binary file added templates/anger/swoosh-01.wav
Binary file not shown.
Binary file added templates/anger/swoosh-02.wav
Binary file not shown.
Binary file added templates/anger/template.aep
Binary file not shown.
Binary file added templates/anger/transition-woosh-01.wav
Binary file not shown.
Binary file added templates/disgust/earthmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/disgust/newsroom.mp3
Binary file not shown.
Binary file added templates/disgust/swoosh-01.wav
Binary file not shown.
Binary file added templates/disgust/swoosh-02.wav
Binary file not shown.
Binary file added templates/disgust/template.aep
Binary file not shown.
Binary file added templates/disgust/transition-woosh-01.wav
Binary file not shown.
Binary file added templates/fear/earthmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/fear/newsroom.mp3
Binary file not shown.
Binary file added templates/fear/swoosh-01.wav
Binary file not shown.
Binary file added templates/fear/swoosh-02.wav
Binary file not shown.
Binary file added templates/fear/template.aep
Binary file not shown.
Binary file added templates/fear/transition-woosh-01.wav
Binary file not shown.
Binary file added templates/joy/earthmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/joy/newsroom.mp3
Binary file not shown.
Binary file added templates/joy/swoosh-01.wav
Binary file not shown.
Binary file added templates/joy/swoosh-02.wav
Binary file not shown.
Binary file added templates/joy/template.aep
Binary file not shown.
Binary file added templates/joy/transition-woosh-01.wav
Binary file not shown.
Binary file added templates/sadness/earthmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added templates/sadness/newsroom.mp3
Binary file not shown.
Binary file added templates/sadness/swoosh-01.wav
Binary file not shown.
Binary file added templates/sadness/swoosh-02.wav
Binary file not shown.
Binary file added templates/sadness/template.aep
Binary file not shown.
Binary file added templates/sadness/transition-woosh-01.wav
Binary file not shown.