blob: e30297eefcdea617034a996c74e5f5ca6b10fa6f [file] [log] [blame]
genia.likes.science@gmail.com67605862013-10-04 05:43:57 -07001$(document).ready(function() {
2
3 var A = new AsterixDBConnection().dataverse("TinySocial");
4
5 function addResult(dom, res) {
6 for (i in res) {
7 $(dom).append(res[i] + "<br/>");
8 }
9 }
10
11 // 0A - Exact-Match Lookup
12 $('#run0a').click(function () {
13 $('#result0a').html('');
14
15 var expression0a = new FLWOGRExpression()
16 .ForClause("$user", new AExpression("dataset FacebookUsers"))
17 .WhereClause(new AExpression("$user.id = 8"))
18 .ReturnClause("$user");
19
20 var success0a = function(res) {
21 addResult('#result0a', res["results"]);
22 };
23
24 A.query(expression0a.val(), success0a);
25 });
26
27 // 0B - Range Scan
28 $("#run0b").click(function() {
29 $('#result0b').html('');
30
31 var expression0b = new FLWOGRExpression()
32 .ForClause("$user", new AExpression("dataset FacebookUsers"))
33 .WhereClause().and(new AExpression("$user.id >= 2"), new AExpression("$user.id <= 4"))
34 .ReturnClause("$user");
35
36 var success0b = function(res) {
37 addResult('#result0b', res["results"]);
38 };
39
40 A.query(expression0b.val(), success0b);
41 });
42
43 // 1 - Other Query Filters
44 $("#run1").click(function() {
45 $('#result1').html('');
46
47 var expression1 = new FLWOGRExpression()
48 .ForClause("$user", new AExpression("dataset FacebookUsers"))
49 .WhereClause().and(
50 new AExpression("$user.user-since >= datetime('2010-07-22T00:00:00')"),
51 new AExpression("$user.user-since <= datetime('2012-07-29T23:59:59')")
52 )
53 .ReturnClause("$user");
54
55 var success1 = function(res) {
56 addResult('#result1', res["results"]);
57 };
58 A.query(expression1.val(), success1);
59 });
60
61 // 2A - Equijoin
62 $("#run2a").click(function() {
63 $('#result2a').html('');
64
65 var expression2a = new FLWOGRExpression()
66 .ForClause ("$user", new AExpression("dataset FacebookUsers"))
67 .ForClause ("$message", new AExpression("dataset FacebookMessages"))
68 .WhereClause(new AExpression("$message.author-id = $user.id"))
69 .ReturnClause({
70 "uname" : "$user.name",
71 "message" : "$message.message"
72 });
73
74 var success2a = function(res) {
75 addResult('#result2a', res["results"]);
76 };
77 A.query(expression2a.val(), success2a);
78 });
79
80 // 2B - Index Join
81 $("#run2b").click(function() {
82 $('#result2b').html('');
83
84 var expression2b = new FLWOGRExpression()
85 .ForClause ("$user", new AExpression("dataset FacebookUsers"))
86 .ForClause ("$message", new AExpression("dataset FacebookMessages"))
87 .WhereClause(new AExpression("$message.author-id /*+ indexnl */ = $user.id"))
88 .ReturnClause({
89 "uname" : "$user.name",
90 "message" : "$message.message"
91 });
92
93 var success2b = function(res) {
94 addResult('#result2b', res["results"]);
95 };
96 A.query(expression2b.val(), success2b);
97 });
98
99 // 3 - Nested Outer Join
100 $("#run3").click(function() {
101 $('#result3').html('');
102
103 var expression3messages = new FLWOGRExpression()
104 .ForClause("$message", new AExpression("dataset FacebookMessages"))
105 .WhereClause(new AExpression("$message.author-id = $user.id"))
106 .ReturnClause("$message.message");
107
108 var expression3 = new FLWOGRExpression()
109 .ForClause ("$user", new AExpression("dataset FacebookUsers"))
110 .ReturnClause({
111 "uname": "$user.name",
112 "messages" : expression3messages
113 });
114
115 var success3 = function(res) {
116 addResult('#result3', res["results"]);
117 };
118 A.query(expression3.val(), success3);
119 });
120
121 // 4 - Theta Join
122 $("#run4").click(function() {
123 $('#result4').html('');
124
125 var expression4messages = new FLWOGRExpression()
126 .ForClause( "$t2", new AExpression("dataset TweetMessages"))
127 .WhereClause( new AExpression("spatial-distance($t.sender-location, $t2.sender-location) <= 1"))
128 .ReturnClause({ "msgtxt" : "$t2.message-text" });
129
130 var expression4 = new FLWOGRExpression()
131 .ForClause( "$t", new AExpression("dataset TweetMessages"))
132 .ReturnClause({
133 "message" : "$t.message-text",
134 "nearby-messages" : expression4messages
135 });
136
137 var success4 = function(res) {
138 addResult('#result4', res["results"]);
139 };
140 A.query(expression4.val(), success4);
141 });
142
143 // 5 - Fuzzy Join
144 $("#run5").click(function() {
145 $('#result5').html('');
146
147 var similarUsersExpression = new FLWOGRExpression()
148 .ForClause("$t", new AExpression("dataset TweetMessages"))
149 .LetClause ("$tu", new AExpression("$t.user"))
150 .WhereClause(new AExpression("$tu.name ~= $fbu.name"))
151 .ReturnClause({
152 "twitter-screenname": "$tu.screen-name",
153 "twitter-name": "$tu.name"
154 });
155
156 var expression5 = new FLWOGRExpression()
157 .ForClause ("$fbu", new AExpression("dataset FacebookUsers"))
158 .ReturnClause(
159 {
160 "id" : "$fbu.id",
161 "name" : "$fbu.name",
162 "similar-users" : similarUsersExpression
163 }
164 );
165
166 var success5 = function (res) {
167 addResult('#result5', res["results"]);
168 };
169
170 var simfunction = new SetStatement( "simfunction", "edit-distance" );
171 var simthreshold = new SetStatement( "simthreshold", "3");
172
173 A.query(
174 [ simfunction.val() , simthreshold.val() , expression5.val() ],
175 success5
176 );
177 });
178
179 // 6 - Existential Quantification
180 $("#run6").click(function() {
181 $('#result6').html('');
182
183 var expression6 = new FLWOGRExpression()
184 .ForClause ("$fbu", new AQLClause().set("dataset FacebookUsers"))
185 .WhereClause(
186 new QuantifiedExpression (
187 "some" ,
188 {"$e" : new AExpression("$fbu.employment") },
189 new FunctionExpression("is-null", new AExpression("$e.end-date"))
190 )
191 )
192 .ReturnClause("$fbu");
193
194 var success6 = function(res) {
195 addResult('#result6',res["results"]);
196 };
197
198 A.query(expression6.val(), success6);
199 });
200
201 // 7 - Universal Quantification
202 $("#run7").click(function() {
203 $('#result7').html('');
204
205 var expression7 = new FLWOGRExpression()
206 .ForClause("$fbu", new AExpression("dataset FacebookUsers"))
207 .WhereClause(
208 new QuantifiedExpression (
209 "every" ,
210 {"$e" : new AExpression("$fbu.employment") },
211 new FunctionExpression("not", new FunctionExpression("is-null", new AExpression("$e.end-date")))
212 )
213 )
214 .ReturnClause("$fbu");
215
216 var success7 = function(res) {
217 addResult('#result7', res["results"]);
218 };
219 A.query(expression7.val(), success7);
220 });
221
222 // 8 - Simple Aggregation
223 $('#run8').click(function () {
224
225 $('#result8').html('');
226
227 var expression8 = new FunctionExpression(
228 "count",
229 new FLWOGRExpression()
230 .ForClause("$fbu", new AExpression("dataset FacebookUsers"))
231 .ReturnClause("$fbu")
232 );
233
234 var success8 = function(res) {
235 addResult('#result8', res["results"]);
236 };
237 A.query(expression8.val(), success8);
238 });
239
240 // 9a - Grouping & Aggregation
241 $("#run9a").click(function() {
242 $('#result9a').html('');
243
244 var expression9a = new FLWOGRExpression()
245 .ForClause("$t", new AExpression("dataset TweetMessages"))
246 .GroupClause("$uid", new AExpression("$t.user.screen-name"), "with", "$t")
247 .ReturnClause(
248 {
249 "user" : "$uid",
250 "count" : new FunctionExpression("count", new AExpression("$t"))
251 }
252 );
253
254 var success9a = function(res) {
255 addResult('#result9a', res["results"]);
256 };
257 A.query(expression9a.val(), success9a);
258 });
259
260 // 9b - Hash-based Grouping & Aggregation
261 $("#run9b").click(function() {
262 $('#result9b').html('');
263
264 var expression9b = new FLWOGRExpression()
265 .ForClause("$t", new AExpression("dataset TweetMessages"))
266 .AQLClause("/*+ hash*/")
267 .GroupClause("$uid", new AExpression("$t.user.screen-name"), "with", "$t")
268 .ReturnClause(
269 {
270 "user" : "$uid",
271 "count" : new FunctionExpression("count", new AExpression("$t"))
272 }
273 );
274
275 var success9b = function(res) {
276 addResult('#result9b', res["results"]);
277 };
278 A.query(expression9b.val(), success9b);
279 });
280
281 // 10 - Grouping and Limits
282 $("#run10").click(function() {
283 $('#result10').html('');
284
285 var expression10 = new FLWOGRExpression()
286 .ForClause("$t", new AExpression("dataset TweetMessages"))
287 .GroupClause("$uid", new AExpression("$t.user.screen-name"), "with", "$t")
288 .LetClause("$c", new FunctionExpression("count", new AExpression("$t")))
289 .OrderbyClause( new AExpression("$c"), "desc" )
290 .LimitClause(new AExpression("3"))
291 .ReturnClause(
292 {
293 "user" : "$uid",
294 "count" : "$c"
295 }
296 );
297
298 var success10 = function(res) {
299 addResult('#result10', res["results"]);
300 };
301 A.query(expression10.val(), success10);
302 });
303
304 // 11 - Left Outer Fuzzy Join
305 $("#run11").click(function() {
306 $('#result11').html('');
307
308 var expression11 = new FLWOGRExpression()
309 .ForClause( "$t", new AExpression("dataset TweetMessages"))
310 .ReturnClause({
311 "tweet" : new AExpression("$t"),
312 "similar-tweets": new FLWOGRExpression()
313 .ForClause( "$t2", new AExpression("dataset TweetMessages"))
314 .WhereClause().and(
315 new AExpression("$t2.referred-topics ~= $t.referred-topics"),
316 new AExpression("$t2.tweetid != $t.tweetid")
317 )
318 .ReturnClause("$t2.referred-topics")
319 });
320
321 var success11 = function(res) {
322 addResult('#result11', res["results"]);
323 };
324
325 var simfunction = new SetStatement( "simfunction", "jaccard" );
326 var simthreshold = new SetStatement( "simthreshold", "0.3");
327 A.query(
328 [ simfunction.val(), simthreshold.val(), expression11.val()],
329 success11
330 );
331
332 });
333
334 /*$('#run0a').trigger('click');
335 $('#run0b').trigger('click');
336 $('#run1').trigger('click');
337 $('#run2a').trigger('click');
338 $('#run2b').trigger('click');
339 $('#run3').trigger('click');
340 $('#run4').trigger('click');
341 $('#run5').trigger('click');
342 $('#run6').trigger('click');
343 $('#run7').trigger('click');
344 $('#run8').trigger('click');
345 $('#run9a').trigger('click');
346 $('#run9b').trigger('click');
347 $('#run10').trigger('click');
348 $('#run11').trigger('click');*/
349});