root/lex/trunk/jsp/lexicon.jsp

Revision 394, 16.7 kB (checked in by chris, 3 years ago)

Fix problem with being unable to create an LS for clauses with no
predicate, e.g. Gen 3,5(f).

Reorganised jsp directory to separate includes and css from jsp pages.

Renamed lsedit.jsp to lexicon.jsp.

Added a controller for lexicon.jsp.

Moved tests into their own package.

Separated finished and unfinished tests to make it easier to run all the
finished and working ones.

Line 
1 <%@ include file="include/setup.jsp" %>
2 <%@ include file="include/auth.jsp" %>
3
4 <% String pageTitle = "Edit Logical Structure"; %>
5 <%@ include file="include/header.jsp" %>
6
7 <%@ page import="java.util.Arrays" %>
8 <%@ page import="java.util.Collections" %>
9 <%@ page import="java.util.Map" %>
10 <%@ page import="java.util.Hashtable" %>
11 <%@ page import="java.util.Iterator" %>
12 <%@ page import="java.util.List" %>
13 <%@ page import="java.util.Vector" %>
14 <%@ page import="java.util.Enumeration" %>
15 <%@ page import="java.io.OutputStream" %>
16 <%@ page import="java.io.IOException" %>
17 <%@ page import="java.sql.*" %>
18 <%@ page import="jemdros.*" %>
19 <%@ page import="org.aptivate.web.controls.*" %>
20 <%@ page import="com.qwirx.lex.*" %>
21 <%@ page import="com.qwirx.db.sql.*" %>
22 <%@ page import="com.qwirx.lex.controller.LexiconController" %>
23 <%@ page import="com.qwirx.lex.emdros.*" %>
24 <%@ page import="com.qwirx.lex.lexicon.*" %>
25 <%@ page import="com.qwirx.lex.lexicon.Lexeme.Variable" %>
26
27 <style type="text/css">
28         h4 { margin-top: 8pt; margin-bottom: 0pt; }
29         td { vertical-align: top; }
30 </style>
31
32 <%     
33         LexiconController controller = new LexiconController(request, emdros, sql);     
34        
35         List<String> errors = controller.getErrorMessages();
36         if (errors.size() > 0)
37         {
38                 %>
39                 <div id="error_message">
40                         <ul>
41                                 <% for (String error : errors) { %>
42                                         <li><%= error %></li>
43                                 <% } %>
44                         </ul>
45                 </div>
46                 <%
47         }
48
49         Lexeme root = Lexeme.getTreeRoot(sql);
50         Lexeme.Finder finder = new Lexeme.Finder(root,
51                 controller.getLexeme().getID());
52         finder.visit();
53         Lexeme current = finder.getFoundLexeme();
54         root.sortInPlace();     
55 %>
56
57 <script type="text/javascript"><!--
58
59         var logics = [
60                 [ "BadID", "New Structure..." ],
61         <%
62                 controller.new LogicalStructureArray(out, root).visit();
63         %>
64         ];
65
66 //--></script>
67 <script type="text/javascript" src="js/lsedit.js"></script>
68
69 <form name="nav" method="get" action="lexicon.jsp">
70 <table>
71 <tr class="nav1"><th colspan="4">Navigator</th></tr>
72 <tr class="nav2">
73         <th>Filter</th>
74         <th>Lexicon Entry</th>
75         <th>Action</th>
76 </tr>
77 <tr class="nav1">
78         <td><input name="filter" value="<%=
79                 request.getParameter("filter") != null
80                 ? request.getParameter("filter") : ""
81         %>" onKeyUp="doFilter(filter, lsid, logics,
82                 <%= controller.getLexeme().getID() %>)" /></td>
83         <td>
84                 <%
85                 LexiconController.LogicalStructureList navigateStructureLister =
86                         controller.new LogicalStructureList(-1, root);
87                 navigateStructureLister.visit();
88                 List<String[]> navigateStructures = navigateStructureLister.getValues();
89                 navigateStructures.add(0, new String[]{"", "New Structure..."});
90                 %>
91                 <%= new SelectBox("lsid", navigateStructures, request).toString() %>
92         </td>
93         <td>
94                 <input type="submit" value="Go" />
95         </td>
96 </tr>
97 </table>
98 </form>
99
100 <script type="text/javascript"><!--
101
102         var nav = document.forms.nav;
103         doFilter(nav.filter, nav.lsid, logics, <%= controller.getLexeme().getID() %>);
104        
105 //--></script>
106
107 <%
108 if (controller.getLexeme().getID() == -1)
109 {
110         %>
111         <p>Please select a lexicon entry from the list above.</p>
112         <%
113 }
114 else if (controller.getLexeme().getID() == 0)
115 {
116         %>
117         <p>You cannot edit the root lexeme. Please select another lexicon entry
118                 from the list above.</p>
119         <%
120 }
121 else if (current == null)
122 {
123         %>
124         <p>The selected lexicon entry does not exist or is invalid.</p>
125         <%
126                
127         current = new Lexeme(sql);
128         current.surface = request.getParameter("surface");
129 }
130 else
131 {
132         %>
133 <table border
134         <tr>
135                 <td>ID</td>
136                 <td><%= controller.getLexeme().getID() <= 0 ? "New" :
137                         (controller.getLexeme().getID() + "") %></td>
138         </tr>
139         <tr>
140                 <td>Predicate Lexeme(s)</td>
141                 <td>
142                         <%
143                                 String surface = current.surface;
144                                 if (surface != null)
145                                 {
146                                         surface = surface.replaceAll("<", "&lt;")
147                                                 .replaceAll(">", "&gt;");
148                                         %><%= surface %><%
149                                 }
150                         %>
151                 </td>
152         </tr>
153         <tr>
154                 <td>Syntactic Macroroles</td>
155                 <td>
156                         <form method="POST" action="lexicon.jsp">
157                         <input type="hidden" name="lsid" value="<%=
158                                 controller.getLexeme().getID() %>">
159                         <%
160                         List<String[]> options = Arrays.asList(new String[][]{
161                                 new String[]{"-1", "Unknown/Not Specified"},
162                                 new String[]{"0",  "None"},
163                                 new String[]{"1",  "MR1"},
164                                 new String[]{"2",  "MR2"},
165                                 new String[]{"3",  "MR3"}
166                         });
167                         SelectBox sb = new SelectBox("sa", options, request);
168                         sb.setDefaultValue("" + current.getNumSyntacticArgs());
169                         %>
170                         <%= sb.toString() %>
171                         <input type="submit" value="Save"/>
172                         </form>
173                 </td>
174         </tr>
175         <tr>
176                 <td>Inherited Logical Structure</td>
177                 <%
178                         String activeLogic = null;
179                         {
180                 %>
181                 <td>
182                         <%
183                                 Lexeme l = current.parent;
184                                
185                                 while (l != null && (l.getLogicalStructure() == null ||
186                                         l.getLogicalStructure().equals("")))
187                                 {
188                                         l = l.parent;
189                                 }
190                                        
191                                 if (l != null)
192                                 {
193                                         activeLogic = l.getLogicalStructure();
194                                 }
195                                        
196                                 if (l == null || l.getLogicalStructure() == null)
197                                 {
198                                         %>none<%
199                                 }
200                                 else
201                                 {
202                                         out.print(
203                                                 l.getLogicalStructure()
204                                                         .replaceAll("<", "&lt;")
205                                                         .replaceAll(">", "&gt;") +
206                                                 " (from <a href=\"lexicon.jsp?lsid=" + l.getID() +
207                                                 "\">" + l.getID() + "</a>)\n");
208                                 }
209                         %>
210                 </td>
211                 <%
212                         }
213                 %>
214         </tr>
215         <% Map allVars = new Hashtable(); %>
216         <tr>
217                 <td>Inherited Variables</td>
218                 <td>
219                         <%
220                         {
221                                 Map vars = null;
222                                 boolean haveShownVars = false;
223
224                                 if (current.parent != null) {
225                                         try
226                                         {
227                                                 vars = current.parent.getAllVariables(sql);
228        
229                                                 if (vars.size() > 0)
230                                                 {
231                                                         %>
232                         <table border>
233                         <tr>
234                                 <th>Name</th>
235                                 <th>Value</th>
236                                 <th>From</th>
237                         </tr>
238                                                         <%
239                                                         haveShownVars = true;
240                                                 }
241        
242                                                 for (Iterator vi = vars.keySet().iterator(); vi.hasNext(); )
243                                                 {
244                                                         String name  = (String)( vi.next() );
245                                                         Variable v   = (Variable)( vars.get(name) );
246                                                        
247                                                         %>
248                         <tr>
249                                 <td><%= v.name %></td>
250                                 <td><%= v.value %></td>
251                                 <td><a href="lexicon.jsp?lsid=<%= v.lexemeId %>"><%= v.lexemeId %></a></td>
252                         </tr>
253                                                         <%
254                                                 }
255                                         } catch (SQLException sqlEx) {
256                                                 %><%= sqlEx %><%
257                                         }
258                                 }
259                                
260                                 if (vars != null) allVars = vars;
261                                
262                                 if (haveShownVars)
263                                 {
264                                         %></table><%
265                                 }
266                                 else
267                                 {
268                                         %>none<%
269                                 }
270                         }
271                         %>
272                 </td>
273         </tr>
274         <tr>
275                 <td>New Variables</td>
276                 <td>
277                         <%
278                         if (controller.getLexeme().getID() <= 0) {
279                                 %>Save this new structure before creating variables.<%
280                         } else {
281                                 %>
282                         <table border>
283                         <tr>
284                                 <th>Name</th>
285                                 <th>Value</th>
286                         </tr>
287                                 <%
288                
289                                 Map vars = null;
290                                
291                                 try {
292                                         vars = current.getVariables(sql);
293                                        
294                                         for (Iterator vi = vars.keySet().iterator();
295                                                 vi.hasNext(); )
296                                         {
297                                                 String name = (String)( vi.next() );
298                                                 Variable v  = (Variable)( vars.get(name) );
299                                                 allVars.put(name, v);
300                                                
301                                                 %>
302                         <tr>
303                                 <form method="POST" action="lexicon.jsp">
304                                 <input type="hidden" name="vid" value="<%= v.id %>">
305                                 <input type="hidden" name="lsid" value="<%=
306                                         controller.getLexeme().getID() %>">
307                                 <td><input name="vn" value="<%= v.name %>"></td>
308                                 <td>
309                                         <input name="vv" value="<%= v.value %>">
310                                         <input type="submit" name="vcu" value="Update">
311                                         <input type="submit" name="vd" value="Delete">
312                                 </td>
313                                 </form>
314                         </tr>
315                                                 <%
316                                         }
317                                 } catch (SQLException sqlEx) {
318                                         %><%= sqlEx %><%
319                                 }
320
321                                 %>
322                         <tr>
323                                 <form method="POST" action="lexicon.jsp">
324                                 <input type="hidden" name="lsid" value="<%=
325                                         controller.getLexeme().getID() %>">
326                                 <td><input name="vn"></td>
327                                 <td>
328                                         <input name="vv">
329                                         <input type="submit" name="vcu" value="Create">
330                                 </td>
331                                 </form>
332                         </tr>
333                         </table>
334                                 <%
335                         }
336                         %>
337                 </td>
338         </tr>
339         <tr>
340                 <td>New Logical Structure</td>
341                 <td>
342                         <form name="oslash">
343                                 <input type="hidden" name="oslash" value="&Oslash;" />
344                         </form>
345                        
346                         <form name="lsform" method="POST" action="lexicon.jsp">
347                         <input type="hidden" name="lsid" value="<%=
348                                 controller.getLexeme().getID() %>" />
349                         <table>
350                         <tr>
351                                 <td colspan="3">
352                                         <h4>Causativity</h4>
353                                 </td>
354                         </tr>
355                         <tr>
356                                 <td valign="top">
357                                         <input type="checkbox" name="ls_caused" value="1"
358                                                 onClick="return updateLS()"
359                                                 <%= current.isCaused() ? "CHECKED" : "" %>
360                                                 />
361                                 </td>
362                                 <td valign="top">
363                                         There is a controlling agent (&alpha; CAUSE &beta;)
364                                 </td>
365                                 <td>
366                                         <strong>do</strong>'(&lt;x&gt;, &Oslash;) CAUSE [...]
367                                 </td>
368                         </tr>
369                         <tr>
370                                 <td colspan="3">
371                                         <h4>Punctuality</h4>
372                                 </td>
373                         </tr>
374                         <tr>
375                                 <td rowspan="3" valign="top">
376                                         <input type="checkbox" name="ls_punct" value="1"
377                                                 onClick="return updateLS()"
378                                                 <%= current.isPunctual() ? "CHECKED" : "" %>
379                                                 />
380                                 </td>
381                                 <td>This must be done in an instant (punctual)
382                                 </td>
383                         </tr>
384                         <tr>
385                                 <td>
386                                         <input type="radio" name="ls_punct_result" value="1"
387                                                 onClick="return updateLS()"
388                                                 <%= current.hasResultState() ? "CHECKED" : "" %>
389                                                 />
390                                                 It has a result state
391                                 </td>
392                                 <td>
393                                         INGR
394                                 </td>
395                         </tr>
396                         <tr>
397                                 <td>
398                                         <input type="radio" name="ls_punct_result" value="0"
399                                                 onClick="return updateLS()"
400                                                 <%= current.hasResultState() ? "" : "CHECKED" %>
401                                                 />
402                                                 It has <strong>no</strong> result state
403                                 </td>
404                                 <td>
405                                         SEMEL
406                                 </td>
407                         </tr>
408                         <tr>
409                                 <td colspan="3">
410                                         <h4>Non-punctuality</h4>
411                                 </td>
412                         </tr>
413                         <tr>
414                                 <td valign="top">
415                                         <input type="checkbox" name="ls_telic" value="1"
416                                                 onClick="return updateLS()"
417                                                 <%= current.isTelic() ? "CHECKED" : "" %>
418                                                 />
419                                 </td>
420                                 <td>
421                                         This must be done as a process reaching an endpoint (... in an hour)
422                                 </td>
423                                 <td>
424                                         BECOME
425                                 </td>
426                         </tr>
427                         <tr>
428                                 <td colspan="3">
429                                         <h4>Dynamicity (Change, Activity)</h4>
430                                 </td>
431                         </tr>
432                         <tr>
433                                 <td valign="top">
434                                         <input type="radio" name="ls_dynamic" value="0"
435                                                 onClick="return updateLS()"
436                                                 <%= current.isDynamic() ? "" : "CHECKED" %>
437                                                 />
438                                 </td>
439                                 <td>
440                                         This is a lasting condition (state)
441                                 </td>
442                                 <td></td>
443                         </tr>
444                         <tr>
445                                 <td valign="top">
446                                         <input type="radio" name="ls_dynamic" value="1"
447                                                 onClick="return updateLS()"
448                                                 <%= current.isDynamic() ? "CHECKED" : "" %>
449                                                 />
450                                 </td>
451                                 <td>
452                                         This is something that can be done <strong>actively</strong>
453                                         (<em>activity</em>)
454                                 </td>
455                                 <td>
456                                         <strong>do</strong>'(&lt;x&gt;, [...])
457                                 </td>
458                         </tr>
459                         <tr>
460                                 <td colspan="2">
461                                         <h4>Predicate</h4>
462                                 </td>
463                                 <td valign="bottom">
464                                         <input name="ls_pred" value="<%=
465                                                 current.getPredicate() == null ? "" :
466                                                 current.getPredicate()
467                                         %>" onKeyUp="return updateLS()" />
468                                 </td>
469                         </tr>
470                         <tr>
471                                 <td colspan="3">
472                                         <h4>Endpoint (Achievement)</h4>
473                                 </td>
474                         </tr>
475                         <tr>
476                                 <td valign="top">
477                                         <input type="radio" name="ls_endpoint" value="0"
478                                                 onClick="return updateLS()"
479                                                 <%= current.hasEndpoint() ? "" : "CHECKED" %> />
480                                 </td>
481                                 <td>
482                                         This <em>activity</em> has no endpoint
483                                 </td>
484                                 <td>
485                                 </td>
486                         </tr>
487                         <tr>
488                                 <td valign="top">
489                                         <input type="radio" name="ls_endpoint" value="1"
490                                                 onClick="return updateLS()"
491                                                 <%= current.hasEndpoint() ? "CHECKED" : "" %> />
492                                 </td>
493                                 <td>
494                                         This <em>activity</em> has an endpoint
495                                         (<em>Active Achievement</em>)
496                                 </td>
497                                 <td>
498                                         &amp; INGR
499                                 </td>
500                         </tr>
501                         <tr>
502                                 <td></td>
503                                 <td>Predicate:</td>
504                                 <td>
505                                         <input name="ls_pred_2" value="<%=
506                                                 current.getResultPredicate() == null ? "" :
507                                                 current.getResultPredicate()
508                                         %>" onKeyUp="return updateLS()" />
509                                 </td>
510                         </tr>
511                         <tr>
512                                 <td></td>
513                                 <td>Argument:</td>
514                                 <td>
515                                         <select name="ls_arg_2" onChange="return updateLS()">
516                                         <option value="x" <%=
517                                                 current.getResultPredicateArg() != null &&
518                                                 current.getResultPredicateArg().equals("x")
519                                                 ? "SELECTED " : ""
520                                         %>>&lt;x&gt;</option>
521                                         <option value="y" <%=
522                                                 current.getResultPredicateArg() != null &&
523                                                 current.getResultPredicateArg().equals("y")
524                                                 ? "SELECTED " : ""
525                                         %>>&lt;y&gt;</option>
526                                         <option value="x,y" <%=
527                                                 current.getResultPredicateArg() != null &&
528                                                 current.getResultPredicateArg().equals("x,y")
529                                                 ? "SELECTED " : ""
530                                         %>>&lt;x&gt;, &lt;y&gt;</option>
531                                         </select>
532                                 </td>
533                         </tr>
534                         <tr>
535                                 <td colspan="3">
536                                         <h4>Thematic Relation</h4>
537                                 </td>
538                         </tr>
539                         <tr>
540                                 <td colspan="2">
541                                         <select name="ls_trel" onChange="return updateLS()">
542                                         <option value="" <%=
543                                                 current.getThematicRelation() == null ? "SELECTED" : ""
544                                         %>>None/Unknown</option>
545                                         <%
546                                                 ThematicRelation[] rels = ThematicRelation.list();
547                                                 for (int i = 0; i < rels.length; i++)
548                                                 {
549                                                         ThematicRelation rel = rels[i];
550                                                         %><option value="<%= i %>" <%=
551                                                                 current.getThematicRelation() == rels[i]
552                                                                 ? "SELECTED" : ""
553                                                         %>><%=
554                                                                 rel.getPrompt()
555                                                                 .replaceAll("<", "&lt;")
556                                                                 .replaceAll(">", "&gt;")
557                                                         %></option><%
558                                                 }
559                                         %>
560                                         </select>
561                                 </td>
562                                 <td>
563                                         <input name="ls_trel_text" readonly="1" value="" />
564                                 </td>
565                         </tr>
566                         <tr>
567                                 <td colspan="3">
568                                         <h4>Logical Structure</h4>
569                                 </td>
570                         </tr>
571                         <tr>
572                                 <td colspan="2">
573                                         <input name="ls" width="80" size="60" value="<%=
574                                                 current.getLogicalStructure() == null ? "" :
575                                                 current.getLogicalStructure()
576                                         %>" readonly="1" />
577                                 </td>
578                                 <td>
579                                         <input type="submit" name="ls_save" value="Save" />
580                                 </td>
581                         </tr>
582                         </table>
583                         </form>
584                        
585                         <script type="text/javascript"><!--
586                        
587                         var them_rels = [
588                         <%
589                                 for (int i = 0; i < rels.length; i++)
590                                 {
591                                         ThematicRelation rel = rels[i];
592                                         %>
593                                                 ["<%= rel.getLabel()   %>",
594                                              "<%= rel.getPrompt()  %>",
595                                              "<%= rel.getArgText() %>"],
596                                         <%
597                                 }
598                         %>                                                                 
599                         ];
600                                                                                                                
601                         updateLS();
602                        
603                         //--></script>
604                 </td>
605         </tr>
606         <tr>
607                 <td>Evaluated Logical Structure</td>
608                 <td>
609                         <%
610                                 activeLogic = current.getEvaluatedLogicalStructure(allVars);
611                                        
612                                 if (activeLogic == null) activeLogic = "none";
613                                
614                                 activeLogic = activeLogic.replaceAll("<", "&lt;")
615                                         .replaceAll(">", "&gt;");
616                         %>
617                         <%= activeLogic %>
618                 </td>
619         </tr>
620         <tr>
621                 <td>Domain Parent</td>
622                 <td>
623                         <script type="text/javascript"><!--
624                                 var parents = [
625                                         [ "0", "None" ],
626                                         <%
627                                         controller.new LogicalStructureArray(out, root).visit();
628                                         %>
629                                 ];
630                         //--></script>
631                        
632                         <form name="dpform" method="POST" action="lexicon.jsp">
633                         <input type="hidden" name="lsid" value="<%=
634                                 controller.getLexeme().getID() %>" />
635                         <input name="filter" onKeyUp="doFilter(filter, dpid, parents,
636                                 <%= controller.getLexeme().getID() %>)" />
637                         <%
638                         LexiconController.LogicalStructureList parentStructureLister =
639                                 controller.new LogicalStructureList(
640                                         controller.getLexeme().getID(), root);
641                         parentStructureLister.visit();
642                         List<String[]> parentStructures = parentStructureLister.getValues();
643                         parentStructures.add(0, new String[]{"0", "None"});
644                         %>
645                         <%= new SelectBox("dpid", parentStructures, request).toString() %>
646                         <input type="submit" value="Save" />
647                         </form>
648                 </td>
649         </tr>
650         <tr>
651                 <td>Domain Label</td>
652                 <td>
653                         <form name="dlform" method="POST" action="lexicon.jsp">
654                         <input type="hidden" name="lsid" value="<%=
655                                 controller.getLexeme().getID() %>">
656                         <input name="dl" value="<%=
657                                 current.label == null ? "" : current.label
658                         %>">
659                         <input type="submit" value="Save" />
660                         </form>
661                 </td>
662         </tr>
663         <tr>
664                 <td>Domain Description</td>
665                 <td>
666                         <form name="ddform" method="POST" action="lexicon.jsp">
667                         <input type="hidden" name="lsid" value="<%=
668                                 controller.getLexeme().getID() %>">
669                         <input name="dd" width="80" size="80" value="<%=
670                                 current.desc == null ? "" : current.desc
671                         %>">
672                         <input type="submit" value="Save">
673                         </form>
674                 </td>
675         </tr>
676         <!--
677         <tr>
678                 <td>Save changes</td>
679                 <td>
680                         <form name="cpform" method="POST" action="lexicon.jsp">
681                         <input type="hidden" name="lsid" value="<%=
682                                 controller.getLexeme().getID() %>" />
683                         <input type="hidden" name="surface" value="<%= surface %>" />
684                         <input type="submit" name="savecopy" value="Save Copy" />
685                         </form>
686                 </td>
687         </tr>
688         -->
689 </table>
690
691 <h2><font color="red">Delete</font></h2>
692
693 <p>
694         Delete this lexicon entry, and change referring clauses to:
695 </p>
696
697 <form name="delform" method="POST" action="lexicon.jsp">
698 <input type="hidden" name="lsid" value="<%= controller.getLexeme().getID() %>">
699 <%
700 LexiconController.LogicalStructureList replacementStructureLister =
701         controller.new LogicalStructureList(0, root);
702 replacementStructureLister.visit();
703 List<String[]> replacementStructures = replacementStructureLister.getValues();
704 replacementStructures.add(0, new String[]{"0", "Not specified"});
705 %>
706 <%= new SelectBox("newlsid", replacementStructures, request).toString() %>
707 <input type="submit" name="delrepl" value="Delete">
708 </form>
709
710         <%
711 } // end if (controller.getLexeme().getID() <= 0)
712 %>
713
714 <form name="addform" method="POST" action="lexicon.jsp">
715         <h2 style="color: red">Create</h2>
716         <p>
717                 Create a new lexicon entry:
718                 <input type="submit" name="createnew" value="Create" />
719         </p>
720 </form>
721
722 <%@ include file="include/footer.jsp" %>
Note: See TracBrowser for help on using the browser.