-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (42 loc) · 1.54 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const vision = require('@google-cloud/vision');
const questionType = require('./helper-modules/question-type.js');
const standardQuestion = require('./helper-modules/standard-question.js');
const theseQuestion = require('./helper-modules/these-question.js');
const extractQA = require('./helper-modules/extract-qa.js')
// Creates a client
const client = new vision.ImageAnnotatorClient();
const fileName = process.argv[2];
// Performs text detection on the local file
client
.textDetection(fileName)
.then(results => {
const detections = results[0].textAnnotations;
var fullText = detections[0]['description'];
var dict = extractQA(fullText);
var question = dict['question'];
var answers = dict['answers'];
if (question.trim().length == 0) {
questionArray = answers.slice(0, answers.length - 3)
answers = answers.slice(answers.length - 3, answers.length)
question = ""
for (var i = 0; i < questionArray.length; i++) {
question += questionArray[i]
}
console.log("WARNING: Difficulty parsing question")
}
console.log('Question: ' + question);
console.log('Answers: ' + answers);
var negative = false;
if (questionType.negative(question)) {
question = question.toLowerCase().replace('not', '').replace('never', '');
negative = true;
}
if (questionType.standard(question)) {
standardQuestion(question, answers, negative);
} else {
theseQuestion(question, answers, negative);
}
})
.catch(err => {
console.error('ERROR:', err);
});