3 <SCRIPT language="Javascript">
4 var query="*"; // stringa che contiene la query nel suo stato attuale.
7 var storepb=1; // queste tre variabili contengono il numero da assegnare al prossimo simbolo set, val o boole per creare il link nel frame in alto a sinistra.
8 var stadd; // contiene la stringa da aggiungere alla query.
9 var fb; // contiene la stringa da aggiungere alla query prima che i set,val e boole siano convertiti in link.
10 var ltr="*"; // qui viene memorizzato qual è l' ultimo link su cui si è cliccato.
14 var novvars2=0; // queste tre variabili servono per sapere dove memorizzare i nomi delle rvar,svar e vvar inserite dall' utente.
16 var ricordaliaslist=0;
18 var numeroazioniannullate=0;
19 var terminecic="";var listaliases="";vlds=new Array();//contengono i parametri per dialogare col server in caso di ambiguità nella Match Conclusion.
20 var disambiguation_choices = "";
21 aliasglob=new Array();//per conservare la lista degli alias
26 vvars1=new Array(100);
27 vvars2=new Array(100); // contengono le rvar,svar e vvar inserite dall' utente.
41 aliasglob=new Array();
43 numeroazioniannullate=0;
45 function ask_uwobo(url)
47 return (top.topurl+"/ask_uwobo?url="+escape("http://mowgli.cs.unibo.it:58080/apply?xmluri=" + escape(url) + "&keys=T1%2CT2%2CL%2CE¶m.processorURL=http%3A//mowgli.cs.unibo.it%3A58080/¶m.getterURL=http%3A//mowgli.cs.unibo.it%3A58081/¶m.proofcheckerURL=http%3A//mowgli.cs.unibo.it%3A58084/¶m.draw_graphURL=http%3A//mowgli.cs.unibo.it%3A58083/¶m.uri_set_queueURL=http%3A//mowgli.cs.unibo.it%3A58082/¶m.UNICODEvsSYMBOL=unicode¶m.keys=d_c%2CC1%2CHC2%2CL¶m.thkeys=T1%2CT2%2CL%2CE¶m.embedkeys=d_c%2CTC1%2CHC2%2CL¶m.doctype-public=-//W3C//DTD%20XHTML%201.0%20Transitional//EN¶m.encoding=iso-8859-1¶m.thencoding=iso-8859-1¶m.media-type=text/html¶m.thmedia-type=text/html¶m.interfaceURL=http%3A//helm.cs.unibo.it/helm/html/cic/index.html¶m.thinterfaceURL=http%3A//helm.cs.unibo.it/helm/html/theory/index.html¶m.CICURI=dummy:query_result¶m.naturalLanguage=yes¶m.annotations=no¶m.topurl=http://helm.cs.unibo.it/helm&prop.method=html"));
49 function help(w) // quando invocata, visualizza l' help relativo ad un oggetto. Di solito è legata ad un evento onFocus o onMouseOver.
53 case -10: hw.document.write("Insert an <a href="+top.topurl+top.action+"grammarpdq.html#Id target=gw>Id</a> or an <a href="+top.topurl+top.action+"grammarpdq.html#Uri target=gw>Uri</a> here.")
55 case -9: hw.document.write("By clicking this you may add or remove aliases as you wish.")
57 case -81: hw.document.write("Allows you to recover your last input")
59 case -8: hw.document.write("Allows you to delete your last input")
61 case -7: hw.document.write("Erases your query and starts a new pre-defined query, you will keep your list of aliases.")
63 case -6: hw.document.write("Puts this string in the current cursor position. This button works only with Internet Explorer.")
65 case -5: hw.document.write("Erases your query and starts a new one.")
67 case -4: hw.document.write("If you click this your query will be processed and the results will appear in the frame above.")
69 case -3: hw.document.write("Substitutes your query with the text written in the area above. Unless you have a good knowledge of MathQL, it's recommended that you use this only to recover errors.")
71 case -2: hw.document.write("This is the edit/submit window. You can modify your query here, but be aware that no syntax check will be performed and that if you enter a <a href="+top.topurl+top.action+"grammar.html#rvar target=gw>variable</a> it won't be available for quick composition later. You may also want to add a <a href="+top.topurl+top.action+"grammar.html#set target=gw>set</a>, a <a href="+top.topurl+top.action+"grammar.html#val target=gw>val</a> or a <a href="+top.topurl+top.action+"grammar.html#boole target=gw>boole</a> somewhere in the query. If you do, write '<set>','<val>' or '<bol>' in the point you'd like it to appear, or use the buttons on the right if you are using IE. When you're done with the query, click the Submit button.")
73 case -1: hw.document.write("You may see the grammar here.")
75 case 0: hw.document.write("")
77 case 1: hw.document.write("You may enter an arbitrary statement here; be careful since syntax errors won't be detected.");
79 case 2: hw.document.write("Enter an <a href="+top.topurl+top.action+"grammar.html#attr_list target=gw>attr_list</a> here.");
81 case 3: hw.document.write("Enter an <a href="+top.topurl+top.action+"grammar.html#id target=gw>id</a> here.");
83 case 4: hw.document.write("You must select one previously entered <a href="+top.topurl+top.action+"grammar.html#rvar target=gw>rvar</a>. If you haven't already entered at least one, you can't choose this. ");
85 case 5: hw.document.write("Enter a <a href="+top.topurl+top.action+"grammar.html#path target=gw>path</a> here.");
87 case 6: hw.document.write("You must select one previously entered <a href="+top.topurl+top.action+"grammar.html#svar target=gw>svar</a>. If you haven't already entered at least one, you can't choose this. ");
89 case 7: hw.document.write("Enter a <a href="+top.topurl+top.action+"grammar.html#string_list target=gw>string_list</a> here.");
91 case 8: hw.document.write("You must select one <a href="+top.topurl+top.action+"grammar.html#vvar target=gw>vvar</a> previously entered as an 'attr'. If you haven't already entered at least one, you can't choose this. ");
93 case 81: hw.document.write("You must select one <a href="+top.topurl+top.action+"grammar.html#vvar target=gw>vvar</a> previously entered in a 'let' statement. If you haven't already entered at least one, you can't choose this. ");
95 case 9: hw.document.write("Enter a single <a href="+top.topurl+top.action+"grammar.html#quoted_string target=gw>quoted_string</a> here.");
99 function tpa(quotpath)
101 while (quotpath.indexOf("<")>-1)
102 {quotpath=quotpath.replace("<","<");}
103 while (quotpath.indexOf(">")>-1)
104 {quotpath=quotpath.replace(">",">");}
107 function idcheck(ident)
110 partediid=/[a-zA-Z0-9_\-\']/;
111 if (!lettera.test(ident.charAt(0))){alert("an Id must begin with a letter.");return(0)}
112 while (ident.length>0)
114 ident=ident.substring(1,(ident.length));
116 if (!partediid.test(ident.charAt(0))){alert(ident.charAt(0)+" is not a valid character for an Id.");return(0);}
120 function uricheck(ident)
123 cic=ident.substring(0,5);//alert(cic);
124 if (cic!="cic:/"){alert("an Uri must begin with the string 'cic:/'");return(0);}
125 ident=ident.substring(5,ident.length);//alert(ident);
126 if (ident.indexOf(".")<0){alert("an Uri must contain a '.'");return(0);}
127 ident1=ident.substring(0,ident.indexOf("."));//alert(ident1);
128 ident2=ident.substring(ident.indexOf(".")+1,ident.length);//alert(ident2);
129 while (ident1.length>0)
131 if (ident1.indexOf("/")>-1)
133 if (idcheck(ident1.substring(0,ident1.indexOf("/")))==0){return (0)}
134 ident1=ident1.substring(ident1.indexOf("/")+1,ident1.length);//alert(ident1);
136 else {if (idcheck(ident1)==0){return (0)}
139 if (ident2=="con"||ident2=="var"){return(1)}
140 if (ident2.substring(0,6)!="ind#1/"){alert ("syntax error in the Uri.");return(0);}
141 ident2=ident2.substring(6,ident2.length);//alert(ident2);
142 if (!cifra.test(ident2.charAt(0))){alert ("syntax error in the Uri.");return(0);}
143 if (ident2.indexOf("/")>-1)
145 while (ident2.charAt(0)!="/")
148 if (!cifra.test(ident2.charAt(0))){alert ("syntax error in the Uri.");return(0);}
149 ident2=ident2.substring(1,ident2.length);
152 while (ident2.length>0)
155 ident2=ident2.substring(1,ident2.length);
156 if (ident2.length>0){
157 if (!cifra.test(ident2.charAt(0))){alert ("syntax error in the Uri.");return(0);}
162 function gramcheck(how,what) // esegue il controllo sintattico sulla stringa "what", controllando che rispetti i requisiti indicati dalla clausola "how". Se qualcosa non è ok, la variabile "wrong" viene posta ad 1 e la stringa da aggiungere viene ignorata, mentre viene visualizzato un apposito messaggio di errore.
165 var alpha=/[A-Za-z:_]/
168 case "qsl": // lista di quoted string
169 if (what.charAt(0)!="{") {gramcheck("qs",what);break;}
170 if (what.charAt(what.length-1)!="}") {alert ("The list must end with a '}'.");wrong=1;break;}
171 what=what.substring(1,what.length-1);//alert (what);
172 while (what.indexOf("\",\"")>-1)
174 as=what.substring(0,what.indexOf("\",\"")+1);//alert(as);
175 what=what.substring(what.indexOf("\",\"")+2,what.length);//alert(what);
178 gramcheck("qs",what);
180 case "qp": // quoted path
181 if (what.charAt(0)!="\"") {alert ("A quoted string must be included between quotes."); wrong=1; break;}
182 if (what.charAt(what.length-1)!="\"") {alert ("A quoted string must be included between quotes."); wrong=1; break;}
183 while (what.indexOf("\"/\"")>-1)
185 as=what.substring(0,what.indexOf("\"/\"")+1);//alert(as);
186 what=what.substring(what.indexOf("\"/\"")+2,what.length);//alert(what);
189 gramcheck("qs",what);
191 case "qs": // quoted string
192 if (what.charAt(0)!="\"") {alert ("A quoted string must be included between quotes."); wrong=1; break;}
193 if (what.charAt(what.length-1)!="\"") {alert ("A quoted string must be included between quotes."); wrong=1; break;}
194 what=what.substring(0,what.length-1);//alert (what);
196 else while (what.length>0)
198 what=what.substring(1,what.length);
199 if (what.charAt(0)=="\"" && slash==0) {alert ("A \" in a quoted string must be preceded by a \\.");wrong=1;break;}
200 if (what.charAt(0)=="\\") {slash=1} else {slash=0}
201 if (slash==1 && what.length==1) {alert ("A \\ in a quoted string must be followed by something.");wrong=1;}
204 case "vlist": // lista di vvar (tutto ciò che si trova dopo "attr")
205 //alert(what.substring(0,4));
206 if ((what.substring(0,4))!="attr"){wrong=1;alert("A vvar_list must begin with the word 'attr'")}
207 what=what.substring(5,(what.length));vl=what;
208 //alert(what+"what");
209 while (what.length>0)
211 if (what.indexOf(",")>0) {vv=(what.substring(0,what.indexOf(",")));}
214 if (vv.charAt(0)!="$"){wrong=1;alert("A vvar must begin with a '$'");}
215 if (vv.indexOf("<-")>0)
217 what=what.substring(vv.length+1,what.length);
218 //alert(what+" nuovowhat "+wrong);
219 path=vv.substring(vv.indexOf("<-")+2,vv.length);
220 //alert(path+" path "+wrong);
221 gramcheck("qp",path);
222 vv=vv.substring(1,(vv.indexOf("<-")));
223 //alert(vv+" vv "+wrong);
226 else {wrong=1;alert("An Assign must contain a '<-'.");what="";}
227 //alert (what+"what");
231 //alert (what.charAt(0));
232 if (!alpha.test(what.charAt(0))) {wrong=1;alert("An ID must begin with a letter , ':' , or '_' .");}
233 while (what.length>1) {
234 what=what.substring(1,(what.length));
235 if (!alpha.test(what.charAt(0)) && !numero.test(what.charAt(0)))
236 {wrong=1;alert(what.charAt(0)+" is not a valid character for an id.");}
237 //document.write(what+"<BR>");
242 if (how=="vlist" && wrong==0) // nel caso in cui sia stato eseguito il controllo su una lista di vvar e non siano stati riscontrati errori, tutte le variabili inserite vengono memorizzate.
246 if (vl.indexOf(",")>-1)
248 vvars2[novvars2++]=vl.substring(0,vl.indexOf("<"));
249 vl=vl.substring(vl.indexOf(",")+1,vl.length);
253 vvars2[novvars2++]=vl.substring(0,vl.indexOf("<"));;
257 //alert ("esco dal loop");
259 if (wrong==0) {cw.inputok=1} else stadd="";
261 function savelink(n,t) // invocata quando si clicca su un link, memorizza quale di questi debba poi essere sostituito.
263 if (t=='s') { top.ltr="[?set"+String(n)+"]";}
264 if (t=='v') { top.ltr="[?val"+String(n)+"]";}
265 if (t=='b') { top.ltr="[?bol"+String(n)+"]";}
268 function aggcw() // invocata automaticamente ad ogni modifica della variabile "query", fa apparire nel frame in alto a destra il menu di composizione relativo al primo link della query. Consente quindi di comporre tutta la query senza mai cliccare su alcun link.
273 if (pq.indexOf("[?")>-1)
275 ltr=pq.slice(pq.indexOf("[?"));
276 ltr=ltr.substring(ltr.indexOf("[?"),(ltr.length-ltr.indexOf("[?"))-(ltr.length-ltr.indexOf("]")-1));
277 wto=ltr.substring(2,5);
278 if (wto=="set") {window.open(top.topurl+action+"set.html","cw");pq="";}
279 else if (wto=="val") {window.open(top.topurl+action+"val.html","cw");pq="";}
280 else if (wto=="bol") {window.open(top.topurl+action+"boole.html","cw");pq="";}
281 else pq=pq.substring(pq.indexOf("[?")+2,pq.length);
283 else {window.open(top.topurl+action+"blank.html","cw");pq="";}
286 function aggform() // aggiorna il form nel frame centrale. Invocata ad ogni cambio della variabile "query".
289 while (cquery.indexOf("<")>-1)
291 cquery=cquery.replace(cquery.substring(cquery.indexOf("<"),cquery.indexOf(">")+1),"");
294 while (cquery.indexOf("[?")>-1)
297 if (cquery.indexOf("]")>-1)
299 while (cquery.indexOf("]")<cquery.indexOf("[?") && cquery.indexOf("]")>-1)
300 {cquery=cquery.replace("]","q+u+a+d+r+a+c+h+i+u+s+a");}//alert("loop"+cquery.indexOf("]")+cquery.indexOf("[?"))}
301 ag1=cquery.slice(cquery.indexOf("[?"));//alert(ag1);
302 ag1=ag1.substring(ag1.indexOf("[?"),(ag1.length-ag1.indexOf("[?"))-(ag1.length-ag1.indexOf("]")));//alert(ag1);
303 ag2=ag1.substring(2,5);//alert(ag2);
304 if (ag2=="set") cquery=cquery.replace(cquery.substring(cquery.indexOf("[?"),cquery.indexOf("]")+1),"<set>");
305 else if (ag2=="val") cquery=cquery.replace(cquery.substring(cquery.indexOf("[?"),cquery.indexOf("]")+1),"<val>");
306 else if (ag2=="bol") cquery=cquery.replace(cquery.substring(cquery.indexOf("[?"),cquery.indexOf("]")+1),"<boole>");
307 else cquery=cquery.replace(cquery.substring(cquery.indexOf("[?"),cquery.indexOf("[?")+1),"q+u+a+d+r+a");
310 else {cquery=cquery.replace("[?","q+u+a+d+r+a?")}
313 while (cquery.indexOf("q+u+a+d+r+a+c+h+i+u+s+a")>-1)
315 cquery=cquery.replace("q+u+a+d+r+a+c+h+i+u+s+a","]");
317 while (cquery.indexOf("q+u+a+d+r+a")>-1)
319 cquery=cquery.replace("q+u+a+d+r+a","[");
321 while (cquery.indexOf("<")>-1)
323 cquery=cquery.replace("<","<");
325 while (cquery.indexOf(">")>-1)
327 cquery=cquery.replace(">",">");
331 function ripristina()
333 //alert (actinput+" "+storia.length);
334 if (numeroazioniannullate>0)
336 numeroazioniannullate--;
337 query=storia[actinput+1];actinput++;
339 qw.document.write(query);
348 //alert (actinput+" "+storia.length);
351 numeroazioniannullate++;
352 query=storia[actinput-1];actinput--;
354 qw.document.write(query);
357 if (query=="*"){cw.location=top.topurl+action+"set.html";ltr="*";} else {aggcw();}
361 function parse() // prende la stringa che si sta tentando di inserire nella query, aggiunge i link dove necessario e mette il risultato nella variabile "fb"
363 while (fb.indexOf("[set]")>-1){
364 if (fb.indexOf("set")>0)
366 fb=fb.replace("[set]","<A HREF="+top.topurl+action+"set.html target=cw onclick=top.savelink("+top.storeps+",'s')>[?set"+top.storeps+"]</A>");
370 while (fb.indexOf("[val]")>-1){
371 if (fb.indexOf("val")>0)
373 fb=fb.replace("[val]","<A HREF="+top.topurl+action+"val.html target=cw onclick=top.savelink("+top.storepv+",'v')>[?val"+top.storepv+"]</A>");
377 while (fb.indexOf("[boole]")>-1){
378 if (fb.indexOf("boole")>0)
380 fb=fb.replace("[boole]","<A HREF="+top.topurl+action+"boole.html target=cw onclick=top.savelink("+top.storepb+",'b')>[?bol"+top.storepb+"]</A>");
385 function aggq() // aggiorna la query sostituendo l' ultimo link editato con la stringa inserita, poi aggiorna tutti i frame.
387 //window.open(top.topurl+action+"summary.html","cw");
390 nst=ltr.substring(5,(ltr.length-1));// alert(nst+" "+ltr);
391 query=query.replace("<A HREF="+top.topurl+action+"set.html target=cw onclick=top.savelink("+nst+",'s')>"+ltr+"</A>",ltr);
392 query=query.replace("<A HREF="+top.topurl+action+"val.html target=cw onclick=top.savelink("+nst+",'v')>"+ltr+"</A>",ltr);
393 query=query.replace("<A HREF="+top.topurl+action+"boole.html target=cw onclick=top.savelink("+nst+",'b')>"+ltr+"</A>",ltr);
395 query=query.replace(ltr,fb);
396 actinput++;storia[actinput]=query;numeroazioniannullate=0;//alert (actinput+" "+storia.length);
397 qw.document.write(query);aggform();
401 var topurl=document.location.protocol+'//'+document.location.host;
403 var action="/getpage?url=";
407 // UTILITY FUNCTIONS FOR templateambigpdq1.html
408 function templateambigpdq1_armageddon()
411 top.window.open(top.topurl+top.action+"start.html","qw");
412 top.window.open(top.topurl+top.action+"blank.html","cw");
413 top.window.open(top.topurl+top.action+"blank.html","hw");
414 top.window.open(top.topurl+top.action+"blank.html","gw");
415 top.window.open(top.topurl+top.action+"blank.html","sw");
418 function templateambigpdq1_resetta()
420 if (confirm("This will erase your query and start a new one. Are you sure you want to do this?"))
421 {templateambigpdq1_armageddon();}
424 function templateambigpdq1_listauri(document,elenco)
426 for (i=0;i<elenco.length;i++)
428 document.write("<input type=checkbox name=uricheck value="+elenco[i]+"> "+elenco[i]+"<br>");
432 function templateambigpdq1_invia(document,top,elenco,ident)
434 vecchiavlds=top.vlds.length;
435 stringa=top.topurl+"/searchPattern?term="+top.terminecic;
436 stringa=stringa+"&aliases="+top.listaliases;
437 stringa=stringa+"&choices=";
439 top.vlds[top.vlds.length]=ident;
440 for (j=0;j<elenco.length;j++)
442 if (document.disamb.uricheck[j].checked)
444 top.vlds[top.vlds.length]=document.disamb.uricheck[j].value;
447 top.vlds[top.vlds.length]=";";
448 for (j=0;j<top.vlds.length;j++)
450 choices=choices+(top.vlds[j]==";"?";":escape(top.vlds[j]))+" ";
452 choices=choices.substring(0,choices.length-2);
453 stringa=stringa+escape(choices);
454 if (top.vlds.length==vecchiavlds){alert("You must select at least one of the options.");}
457 window.open(ask_uwobo(stringa),"cw");
461 function templateambigpdq1_selezionaCostanti(document,elenco) {
462 for (i=0; i<elenco.length; i++) {
463 if (elenco[i].substring(elenco[i].length-4, elenco[i].length) != ".var") {
464 document.disamb.uricheck[i].checked = true;
466 document.disamb.uricheck[i].checked = false;
473 // UTILITY FUNCTIONS FOR templateambigpdq2.html
474 function templateambigpdq2_armageddon()
477 top.window.open(top.topurl+top.action+"start.html","qw");
478 top.window.open(top.topurl+top.action+"blank.html","cw");
479 top.window.open(top.topurl+top.action+"blank.html","hw");
480 top.window.open(top.topurl+top.action+"blank.html","gw");
481 top.window.open(top.topurl+top.action+"blank.html","sw");
484 function templateambigpdq2_resetta()
486 if (confirm("This will erase your query and start a new one. Are you sure you want to do this?"))
487 {templateambigpdq2_armageddon();}
490 function templateambigpdq2_listainterpretazioni(document,elenco,labels)
492 for (i=0;i<elenco.length;i++)
494 document.write("<input type=radio name=interp value="+elenco[i]+"> "+labels[i]+"<br />");
498 function templateambigpdq2_invia(document,elenco)
500 stringa=top.topurl+"/searchPattern?term="+top.terminecic;
501 stringa=stringa+"&aliases="+(top.listaliases==""?"":"%20");
502 controllo=stringa.length;
503 for (j=0;j<elenco.length;j++)
505 if (document.disamb.interp[j].checked)
507 stringa=stringa+escape(elenco[j]);
509 // TODO da implementare nella terza fase
510 //top.aliasglob[top.aliasglob.length]=document.disamb.interp[j].value;
512 //for (k=0;k<top.aliasglob.length;k++){alert(top.aliasglob[k])}
513 //top.listaliases=top.listaliases+document.disamb.interp[j].value;//in caso di query ulteriori con la stessa lista di alias
517 if (stringa.length!=controllo)
519 window.open(ask_uwobo(stringa),"cw");
521 else {alert("You must choose one option.");}
526 // UTILITY FUNCTIONS FOR templateambigpdq3.html
527 function templateambigpdq3_init(aliases)
529 top.aliasglob = new Array();
530 for (i=0; i<aliases.length; i++) {
531 top.aliasglob[i] = aliases[i];
533 top.vlds=new Array();
534 top.window.open(top.topurl+top.action+"editorpdq.html", "sw");
539 document.write(' <FRAMESET ROWS="69%,31%"> <FRAMESET COLS="40%,60%"> <FRAMESET ROWS="46%,54%"> <FRAME NAME="qw" SRC="'+topurl+action+'start.html"> <FRAME NAME="sw" SRC="'+topurl+action+'blank.html"> </FRAMESET> <FRAME NAME="cw" SRC="'+topurl+action+'blank.html"> </FRAMESET> <FRAMESET COLS="49%,51%"> <FRAME NAME="gw" SRC="'+topurl+action+'blank.html" onFocus="help(-1)";> <FRAME NAME="hw" SRC="'+topurl+action+'blank.html"> </FRAMESET> </FRAMESET>');