-
Notifications
You must be signed in to change notification settings - Fork 1
/
watson.html
64 lines (48 loc) · 1.76 KB
/
watson.html
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
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html>
<head>
<title>JSSample</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(function() {
var params = {
// Request parameters
};
$.ajax({
url: "https://watson-api-explorer.mybluemix.net/tone-analyzer/api/v3/tone?version=2016-05-19&text=" + $.param(params),
beforeSend: function(xhrObj){
// Request headers
xhrObj.setRequestHeader("Content-Type","text/plain");
},
type: "POST",
// Request body
data: "Once upon a time, there was a sad rabbit in the forest at night.",
})
.done(function(data) {
//str = JSON.stringify(data);
//document.write (str);
var output_watson = data["document_tone"]["tone_categories"][0];//["tones"];
//document.write (output_watson["category_name"]);
var determineTone = output_watson["tones"];
//document.write (JSON.stringify(determineTone));
var maxScore = 0;
var toneName = "test";
//document.write(determineTone.length);
for(var i=0; i<determineTone.length; i++){
//document.write(i);
var score = determineTone[i]["score"];
//document.write (score);
if ( maxScore <= score){ maxScore = score; toneName = determineTone[i]["tone_name"];}
}
document.write (toneName);
document.write (score);
})
.fail(function() {
alert("error");
});
});
</script>
</body>
</html>