-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument.html
More file actions
166 lines (129 loc) · 5.47 KB
/
document.html
File metadata and controls
166 lines (129 loc) · 5.47 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ConveyAPI - Simple Example</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
font-size: 14px;
line-height: 20px;
}
</style>
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="index.html">ConveyAPI</a>
<div class="nav-collapse">
<ul class="nav">
<li class="active"><a href="document.html">Document Example</a></li>
<li class="active"><a href="twitter.html">Twitter Example</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="container">
<h1>Try it: Analyze a Document</h1>
<p>Below is a simple example of using the ConveyAPI with jQuery to analyze a document.</p>
<form class="well form-horizontal">
<div class="control-group">
<label class="control-label">API Key:</label>
<div class="controls">
<input id="apiKey" type="text" class="span4" placeholder="Your ConveyAPI Key...">
</div>
</div>
<div class="control-group">
<label class="control-label" for="textarea">Text:</label>
<div class="controls">
<textarea id="text" class="span4" id="textarea" rows="4"></textarea> <br/>
</div>
</div>
<div class="form-actions">
<button id="submit"type="button" class="btn btn-primary">Analyze</button>
<button class="btn" type="button">Clear</button>
</div>
</form>
<div id="result" style="display: none;">
<blockquote>
<p id="responseText"></p>
<dl class='dl-horizontal'>
<dt>polarity:</dt>
<dd><span id="polarity" class='label'><span></dd>
<dt>emotion:</dt>
<dd><span id="emotion" class='label'><span></dd>
<dt>intensity:</dt>
<dd><span id="intensity" class='label'><span></dd>
<dt>spam:</dt>
<dd><span id="spam" class='label'><span></dd>
</dl>
</blockquote>
</div>
<h2>Source Code</h2>
<p>To use ConveyAPI in with jQuery, make sure to use the 'callback' parameter in order to have your response returned as JSONP (JSON with Padding).</p>
<pre>
var apiUrl = "http://beta.conveyapi.com/analysis-engine/process?callback=?";
$("#submit").click(function () {
$("#result").slideUp();
$.getJSON(apiUrl,
{ api_key: $("#apiKey").val(), text: $("#text").val(), suppress_status_codes: true},
function(jsonData) {
if(jsonData.status.code == 200) {
$("#result").slideDown();
var doc = jsonData.document;
$("#polarity").text(doc.annotations.polarity.value +
" (" + doc.annotations.polarity.confidence.toFixed(2) + ")");
$("#emotion").text(doc.annotations.emotion.value +
" (" + doc.annotations.emotion.confidence.toFixed(2) + ")");
$("#intensity").text(doc.annotations.intensity.value
+ " (" + doc.annotations.intensity.confidence.toFixed(2) + ")");
$("#spam").text(doc.annotations.spam.value
+ " (" + doc.annotations.spam.confidence.toFixed(2) + ")");
} else {
alert(jsonData.status.message);
}
});
});
</pre>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="js/jquery-1.7.2.min.js"></script>
<script>
var apiUrl = "http://beta.conveyapi.com/analysis-engine/process?callback=?";
$("#submit").click(function () {
$("#result").slideUp();
$.getJSON(apiUrl,
{ api_key: $("#apiKey").val(), text: $("#text").val(), suppress_status_codes: true},
function(jsonData) {
if(jsonData.status.code == 200) {
$("#result").slideDown();
var doc = jsonData.document;
$("#responseText").text(doc.text);
$("#polarity").text(doc.annotations.polarity.value + " (" + doc.annotations.polarity.confidence.toFixed(2) + ")");
$("#emotion").text(doc.annotations.emotion.value + " (" + doc.annotations.emotion.confidence.toFixed(2) + ")");
$("#intensity").text(doc.annotations.intensity.value + " (" + doc.annotations.intensity.confidence.toFixed(2) + ")");
$("#spam").text(doc.annotations.spam.value + " (" + doc.annotations.spam.confidence.toFixed(2) + ")");
switch(doc.annotations.polarity.value) {
case "positive":
$("#polarity").addClass("label-success");
break;
case "neutral":
$("#polarity").addClass("label-warning");
break;
case "negative":
$("#polarity").addClass("label-important");
break;
}
} else {
alert(jsonData.status.message);
}
});
});
</script>
</body>
</html>