root/lex/trunk/jsp/wordnet.jsp

Revision 394, 38.8 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 <% String pageTitle = "Text Browser with Wordnet"; %>
2 <%@ include file="include/header.jsp" %>
3
4 <%@ page import="java.util.*" %>
5 <%@ page import="java.util.regex.*" %>
6 <%@ page import="java.net.*" %>
7 <%@ page import="java.sql.*" %>
8 <%@ page import="jemdros.*" %>
9 <%@ page import="com.qwirx.lex.ontology.*" %>
10 <%@ page import="com.qwirx.lex.wordnet.*" %>
11 <%@ page import="com.qwirx.lex.parser.*" %>
12 <%@ page import="com.qwirx.lex.morph.*" %>
13 <%@ page import="com.qwirx.lex.lexicon.*" %>
14 <%@ page import="com.qwirx.crosswire.kjv.KJV" %>
15 <%@ page import="org.crosswire.jsword.book.*" %>
16 <%@ page import="net.didion.jwnl.data.POS" %>
17 <%@ page import="net.didion.jwnl.data.Synset" %>
18
19 <script type="text/javascript"><!--
20
21         function enableEditButton()
22         {
23                 if (document.forms.changels == null)
24                 {
25                         return;
26                 }
27                
28                 var lsselect = document.forms.changels.lsid;
29                 var editform = document.forms.editls;
30                 if (editform == null || editform.submit == null)
31                 {
32                         return;
33                 }
34                        
35                 var sellsid  = -1;
36                 if (lsselect.selectedIndex > 0)
37                 {
38                         sellsid = lsselect.options[lsselect.selectedIndex].value;
39                 }       
40                
41                 editform.submit.disabled = (sellsid != editform.lsid.value);
42                 return true;
43         }
44
45         function enableChangeButton(button, oldValue, selectBox)
46         {
47                 if (button == null) return;
48                 var newValue = selectBox.options[selectBox.selectedIndex].value;
49                 button.disabled = (newValue == oldValue);
50                 return true;
51         }
52        
53 //--></script>
54
55 <style type="text/css">
56         TABLE.tree TD
57         {
58                 text-align: center;
59         }
60 </style>
61
62 <%@ include file="auth.jsp" %>
63 <%@ include file="navclause.jsp" %>
64 <%
65
66         Wordnet wordnet = Wordnet.getInstance();
67
68         Map phrase_functions = emdros.getEnumerationConstants
69                 ("phrase_function_e",false);
70
71         Map phrase_types = emdros.getEnumerationConstants
72                 ("phrase_type_e",false);
73                
74         Map parts_of_speech = emdros.getEnumerationConstants
75                 ("part_of_speech_e",false);
76
77         if (request.getParameter("savearg") != null)
78         {
79                 String phraseIdString = request.getParameter("phraseid");
80                 String newArg         = request.getParameter("newarg");
81                 int phraseId          = Integer.parseInt(phraseIdString);
82                 Change ch = emdros.createChange(EmdrosChange.UPDATE,
83                         "phrase", new int[]{phraseId});
84                 ch.setString("argument_name", newArg);
85                 ch.execute();
86         }
87
88         if (request.getParameter("changemr") != null &&
89                 request.getParameter("mr") != null)
90         {
91                 String phraseIdString = request.getParameter("pid");
92                 String newMRString    = request.getParameter("mr");
93                 int phraseId          = Integer.parseInt(phraseIdString);
94                 int newMR             = Integer.parseInt(newMRString);
95                 Change ch = emdros.createChange(EmdrosChange.UPDATE,
96                         "phrase", new int[]{phraseId});
97                 ch.setInt("macrorole_number", newMR);
98                 ch.execute();
99         }
100
101         Sheaf sheaf = emdros.getSheaf
102         (
103                 "SELECT ALL OBJECTS IN " +
104                 emdros.intersect(userTextAccessSet, min_m, max_m) +
105                 " WHERE [clause self = "+navigator.getClauseId()+
106                 "       GET logical_struct_id, logical_structure "+
107                 "        [phrase GET phrase_type, phrase_function, argument_name, "+
108                 "                    type_id, macrorole_number "+
109                 "          [word GET lexeme, phrase_dependent_part_of_speech, " +
110                 "                    tense, stem, wordnet_gloss, wordnet_synset, " +
111                 "                    graphical_preformative, " +
112                 "                    graphical_locative, " +
113                 "                    graphical_lexeme, " +
114                 "                    graphical_pron_suffix, " +
115                 "                    graphical_verbal_ending, " +
116                 "                    graphical_root_formation, " +
117                 "                    graphical_nominal_ending, " +
118                 "                    person, number, gender, state, " +
119                 "                    surface_consonants, " +
120                 "                    suffix_gender, suffix_number, suffix_person " +
121                 "          ]"+
122                 "        ]"+
123                 "      ]"
124         );
125
126         class BorderTableRenderer extends TableRenderer
127         {
128             public String getTable(String contents)
129             {
130                 return "<table class=\"tree\" border>" + contents + "</table>\n";
131             }
132         }
133
134         BorderTableRenderer rend = new BorderTableRenderer();
135        
136         MatchedObject clause = null;
137         {
138                 SheafConstIterator sci = sheaf.const_iterator();
139                 if (sci.hasNext())
140                 {
141                         Straw straw = sci.next();
142                         StrawConstIterator swci = straw.const_iterator();
143                         if (swci.hasNext())
144                         {
145                                 clause = swci.next();
146                         }
147                 }
148         }
149                  
150         if (clause == null)
151         {
152                 %><p>Selected clause not found or access denied.</p><%
153         }
154         else
155         {
156                 OntologyDb ontology = Lex.getOntologyDb();
157                
158                 String predicate_text = "";
159                 StringBuffer hebrewText = new StringBuffer();
160                 List morphEdges = new ArrayList();
161                 HebrewMorphemeGenerator generator = new HebrewMorphemeGenerator();
162                
163                 /* Prescan to find the predicate lexeme and populate the chart */
164                
165                 {
166                         TreeNode root = new TreeNode("root");
167
168                         SheafConstIterator phrases = clause.getSheaf().const_iterator();
169                         boolean isFirstWord = true;
170        
171                         while (phrases.hasNext())
172                         {
173                                 MatchedObject phrase =
174                                         phrases.next().const_iterator().next();
175        
176                                 String function_name = (String)( phrase_functions.get(
177                                         phrase.getEMdFValue("phrase_function").toString())
178                                 );
179        
180                                 SheafConstIterator words = phrase.getSheaf().const_iterator();
181                                
182                                 while (words.hasNext())
183                                 {
184                                         MatchedObject word = words.next().const_iterator().next();
185
186                                         String psp = (String)( parts_of_speech.get(
187                                                 word.getEMdFValue("phrase_dependent_part_of_speech").toString())
188                                         );
189                                                
190                                         class HebrewFeatureConverter implements MorphemeHandler
191                                         {
192                                                 private TreeNode m_root;
193                                                 private MatchedObject m_word;
194                                                 private StringBuffer m_hebrew;
195                                                 private List m_morphs;
196                                                 boolean m_IsFirstWord, m_IsLastWord;
197                                                 boolean m_IsMorpheme;
198                                                
199                                                 public HebrewFeatureConverter(TreeNode root,
200                                                         MatchedObject word, StringBuffer hebrew,
201                                                         List morphs, boolean isFirstWord,
202                                                         boolean isLastWord)
203                                                 {
204                                                         m_root   = root;
205                                                         m_word   = word;
206                                                         m_hebrew = hebrew;
207                                                         m_morphs = morphs;
208                                                         m_IsFirstWord = isFirstWord;
209                                                         m_IsLastWord  = isLastWord;
210                                                 }
211                                                
212                                                 public boolean isMorpheme()
213                                                 {
214                                                         return m_IsMorpheme;
215                                                 }
216                                                
217                                                 public void convert(String surface,
218                                                         boolean firstMorpheme, boolean lastMorpheme,
219                                                         String desc, String morphNode)
220                                                 {
221                                                         String hebrew = m_word.getEMdFValue(surface).getString();
222                                                         m_hebrew.append(hebrew);
223
224                                                         String translit = navigator.getTransliterator()
225                                                                 .transliterate(hebrew, firstMorpheme,
226                                                                         lastMorpheme);
227                                                         translit = HebrewConverter.toHtml(translit);
228                                                         if (translit.equals("")) translit = "&Oslash;";
229                                                        
230                                                         if (desc != null && desc.equals("CONJ"))
231                                                         {
232                                                                 if (m_IsFirstWord) { desc = "CLM"; }
233                                                                 else               { desc = "CR"; }
234                                                         }
235                                                        
236                                                         // desc += ":" + lastMorpheme + ":" + m_IsLastWord;
237                                                        
238                                                         if (!lastMorpheme)
239                                                         {
240                                                                 translit += "-";
241                                                                 desc += "-";
242                                                                 m_IsMorpheme = true;
243                                                         }
244                                                         else if (translit.endsWith("-"))
245                                                         {
246                                                                 desc += "-";
247                                                                 lastMorpheme = false;
248                                                                 m_IsMorpheme = true;
249                                                         }
250                                                         else
251                                                         {
252                                                                 m_IsMorpheme = false;
253                                                         }
254
255                                                         TreeNode node = m_root.createChild(translit);
256                                                         // node = node.createChild(raw);
257                                                         if (desc == null) desc = "";
258                                                         node.createChild(desc);
259
260                                                         if (lastMorpheme && !m_IsLastWord)
261                                                         {
262                                                                 // blank cell between words
263                                                                 m_root.createChild("");
264                                                         }
265                                                        
266                                                         m_morphs.add(new MorphEdge(morphNode,
267                                                                 translit, m_morphs.size()));
268                                                 }
269                                         }
270
271                                         HebrewFeatureConverter hfc =
272                                                 new HebrewFeatureConverter(root, word, hebrewText,
273                                                         morphEdges, isFirstWord,
274                                                         !phrases.hasNext() && !words.hasNext());
275                                                
276                                         generator.parse(word, hfc, true, sql);
277                                         isFirstWord = false;
278                                        
279                                         if (!hfc.isMorpheme())
280                                         {                               
281                                                 hebrewText.append(" ");                                         
282                                         }
283                                        
284                                         if (psp.equals("verb"))
285                                         {
286                                                 predicate_text =
287                                                         word.getEMdFValue("lexeme").getString();
288                                         }
289                                 }
290                         }
291                        
292                         root.setLabel("<span class=\"hebrew\">" +
293                                 HebrewConverter.toHtml(hebrewText.toString()) +
294                                 "</span>");
295        
296                         %><%= root.toHtml(rend) %><%
297                 }
298
299                 BookData swordVerse = null;
300                 try
301                 {
302                         swordVerse = KJV.getVerse(emdros, selBook, selChapNum,
303                                 selVerseNum);
304                         %><p><em><%=
305                                 OSISUtil.getCanonicalText(swordVerse.getOsisFragment())
306                         %></em></p><%
307                 }
308                 catch (Exception e)
309                 {
310                         %><p>KJV Gloss not found (<%= e %>)</p><%
311                 }               
312                        
313                 %>
314                 <p>Predicate text is: <%=
315                         predicate_text
316                                 .replaceAll("<", "&lt;")
317                                 .replaceAll(">", "&gt;")
318                 %></p>
319                 <%
320                
321                 int numSyntacticMacroroles = -1;
322                 int currentLsId = clause.getEMdFValue("logical_struct_id").getInt();
323        
324                 String selLsIdString = request.getParameter("lsid");
325                 String structure = "";
326
327                 {       
328                         int selLsId = currentLsId;
329                
330                         String newLsString   = request.getParameter("newls");
331                         String lsSaveString  = request.getParameter("lssave");
332                
333                         if (request.getParameter("create") != null && newLsString != null)
334                         {
335                                 try
336                                 {
337                                         Change ch = sql.createChange(SqlChange.INSERT,
338                                                 "lexicon_entries", null);
339                                         ch.setString("Lexeme",    predicate_text);
340                                         ch.setString("Structure", newLsString);
341                                         ch.execute();
342                                         selLsId = ((SqlChange)ch).getInsertedRowId();
343                                         selLsIdString = "" + selLsId;
344                                         lsSaveString = "yes";
345                                 }
346                                 catch (DatabaseException ex)
347                                 {
348                                         %><%= ex %><%
349                                 }
350                                 finally
351                                 {
352                                         sql.finish();
353                                 }
354                         }
355                         else
356                         {               
357                                 try { selLsId = Integer.parseInt(selLsIdString); }
358                                 catch (Exception e) { /* do nothing, use default */ }
359                         }
360                
361                         if (selLsId != currentLsId && lsSaveString != null)
362                         {
363                                 Change ch = emdros.createChange(EmdrosChange.UPDATE,
364                                         "clause", new int[]{navigator.getClauseId()});
365                                 ch.setInt("logical_struct_id", selLsId);
366                                 ch.execute();
367                                 currentLsId = selLsId;
368                         }
369                 }
370                
371                 try
372                 {
373                         PreparedStatement stmt = sql.prepareSelect
374                                 ("SELECT ID,Structure,Syntactic_Args " +
375                                  "FROM lexicon_entries WHERE ID = ?");
376                         stmt.setInt(1, currentLsId);
377                                
378                         ResultSet rs = sql.select();
379                                
380                         if (rs.next())
381                         {
382                                 int    thisLsId      = rs.getInt("ID");
383                                 String thisStructure = rs.getString("Structure");
384                                 int    thisNumSMRs   = rs.getInt("Syntactic_Args");
385
386                                 if (thisStructure != null)
387                                 {
388                                         structure = thisStructure;
389                                 }
390                                 numSyntacticMacroroles = thisNumSMRs;
391                         }
392                 }
393                 catch (DatabaseException ex)
394                 {
395                         %><%= ex %><%
396                 }
397                 finally
398                 {
399                         sql.finish();
400                 }
401        
402                 Vector argNames = new Vector();
403                 Hashtable argNamesHash = new Hashtable();
404
405                 Pattern varPat = Pattern.compile
406                         ("(?s)(?i)<([^>]*)>");
407                 Matcher m = varPat.matcher(structure);
408                 while (m.find())
409                 {
410                         String arg = m.group(1);
411                         if (argNamesHash.get(arg) != null)
412                                 continue;
413                         argNames.addElement(m.group(1));
414                         argNamesHash.put(arg, Boolean.TRUE);
415                 }
416                
417                 Hashtable variables = new Hashtable();
418                
419                 %>
420                 <p>
421                 <table border>
422                 <%
423                
424                 String [] object_types = new String [] {
425                         "word",
426                         "phrase"
427                 };
428                
429                 class Cell {
430                         String label, link, format, html;
431                         int columns;
432                         Vector subcells = new Vector();
433                 }
434
435                 // "ewg" stands for "edit word gloss"
436                 String ewgString = request.getParameter("ewg");
437                 int ewgId = -1;
438                 if (ewgString != null) {
439                         ewgId = Integer.parseInt(ewgString);
440                 }
441
442                 // "ewng" stands for "edit WordNet gloss"
443                 String ewngString = request.getParameter("ewng");
444                 int ewngId = -1;
445                 if (ewngString != null) {
446                         ewngId = Integer.parseInt(ewngString);
447                 }
448
449                 // "swns" stands for "select WordNet sense"
450                 String swnsString = request.getParameter("swns");
451                 int swnsId = -1;
452                 if (swnsString != null) {
453                         swnsId = Integer.parseInt(swnsString);
454                 }
455                
456                 for (int objectNum = 0; objectNum < object_types.length;
457                         objectNum++)
458                 {
459                         String type = object_types[objectNum];
460                         Vector word_row = new Vector(), struct_row = new Vector();
461                         int column = 0;
462                        
463                         SheafConstIterator phrases = clause.getSheaf().const_iterator();
464                         while (phrases.hasNext())
465                         {
466                                 MatchedObject phrase =
467                                         phrases.next().const_iterator().next();
468                                 int first_col = column;
469                                 boolean canWriteToPhrase = emdros.canWriteTo(phrase);
470        
471                                 String function_name = (String)( phrase_functions.get(
472                                         phrase.getEMdFValue("phrase_function").toString())
473                                 );
474
475                                 String phrase_type = (String)( phrase_types.get(
476                                         phrase.getEMdFValue("phrase_type").toString())
477                                 );
478                                
479                                 SheafConstIterator words = phrase.getSheaf().const_iterator();
480                                 while (words.hasNext())
481                                 {
482                                         MatchedObject word =
483                                                 words.next().const_iterator().next();
484                                         column++;
485                                        
486                                         if (type.equals("word"))
487                                         {
488                                                 Lexeme lexeme = Lexeme.findOrBuild(sql, word);
489                                                
490                                                 String part_of_speech = word.getFeatureAsString(
491                                                         word.getEMdFValueIndex(
492                                                                 "phrase_dependent_part_of_speech"));
493                                                 boolean canWriteToWord = emdros.canWriteTo(word);
494                                                        
495                                                 Cell cell = new Cell();
496                                                 cell.label = lexeme.getTranslit();
497                                                 cell.columns = 1;
498                                                 word_row.addElement(cell);
499                                                
500                                                 int wid = word.getID_D();
501
502                                                 // lexicon gloss
503                                                 {
504                                                         Cell glossCell = new Cell();
505                                                         cell.subcells.add(glossCell);
506        
507                                                         if (ewgId == wid &&
508                                                                 request.getParameter("ewgs") != null)
509                                                         {
510                                                                 lexeme.setGloss(request.getParameter("gloss"));
511                                                                 lexeme.save();
512                                                                 lexeme = Lexeme.load(sql, word);
513                                                                 ewgId = -1;
514                                                         }
515                                                        
516                                                         String lexiconGloss = lexeme.getGloss();
517                                                        
518                                                         if (ewgId == wid)
519                                                         {
520                                                                 if (lexiconGloss == null)
521                                                                 {
522                                                                         lexiconGloss = "";
523                                                                 }
524                                                                 glossCell.html = "<form method=\"post\">\n" +
525                                                                         "<input type=\"hidden\" name=\"ewg\"" +
526                                                                         " value=\"" + wid + "\">\n" +
527                                                                         "<input name=\"gloss\" size=\"10\" value=\"" +
528                                                                         HebrewConverter.toHtml(lexiconGloss) +
529                                                                         "\">\n" +
530                                                                         "<input type=\"submit\" name=\"ewgs\""+
531                                                                         " value=\"Save\">\n" +
532                                                                         "</form>";
533                                                         }
534                                                         else
535                                                         {
536                                                                 if (lexiconGloss == null)
537                                                                 {
538                                                                         lexiconGloss = "(gloss)";
539                                                                 }
540                                                                 glossCell.html = "<a href=\"clause.jsp?ewg=" +
541                                                                         wid + "\">" + lexiconGloss + "</a>";
542                                                         }
543                                                 }
544
545                                                 // wordnet gloss
546                                                 {
547                                                         String wordnetGloss = word
548                                                                 .getEMdFValue("wordnet_gloss")
549                                                                 .getString();
550                                                         Long wordnetSynset = new Long(word
551                                                                 .getEMdFValue("wordnet_synset")
552                                                                 .getInt());
553                                                                
554                                                         if (wordnetGloss == null ||
555                                                                 wordnetGloss.equals(""))
556                                                         {
557                                                                 OntologyDb.OntologyEntry entry =
558                                                                         ontology.getWordByLexeme(
559                                                                                 word.getEMdFValue("lexeme")
560                                                                                 .getString());
561                                                                 if (entry != null)
562                                                                 {
563                                                                         wordnetGloss  = entry.m_EnglishGloss;
564                                                                 }
565                                                                 else
566                                                                 {
567                                                                         wordnetGloss  = null;
568                                                                 }
569                                                                
570                                                                 if (entry != null &&
571                                                                         wordnetSynset.longValue() == 0)
572                                                                 {
573                                                                         wordnetSynset = entry.m_Synset;
574                                                                 }
575                                                         }
576
577                                                         if (ewngId == wid &&
578                                                                 request.getParameter("ewngs") != null)
579                                                         {
580                                                                 wordnetGloss = request.getParameter("gloss");
581                                                                 Change ch = emdros.createChange(
582                                                                                 EmdrosChange.UPDATE,
583                                                                                 "word", new int[] {wid});
584                                                                 ch.setString("wordnet_gloss", wordnetGloss);
585                                                                 ch.execute();
586                                                                 ewngId = -1;
587                                                         }
588                                                        
589                                                         POS wordnetPos = null;
590                                                        
591                                                         if (part_of_speech.equals("verb"))
592                                                         {
593                                                                 wordnetPos = POS.VERB;
594                                                         }
595                                                         else if (part_of_speech.equals("noun"))
596                                                         {
597                                                                 wordnetPos = POS.NOUN;
598                                                         }
599                                                         else if (part_of_speech.equals("adjective"))
600                                                         {
601                                                                 wordnetPos = POS.ADJECTIVE;
602                                                         }
603                                                         else if (part_of_speech.equals("adverb"))
604                                                         {
605                                                                 wordnetPos = POS.ADVERB;
606                                                         }
607                                                                
608                                                         Synset [] senses = null;
609                                                         if (wordnetPos != null && wordnetGloss != null)
610                                                         {
611                                                                 senses = wordnet.getSenses(wordnetPos,
612                                                                         wordnetGloss);
613                                                         }
614                                                        
615                                                         Cell wordnetCell = new Cell();
616                                                         cell.subcells.add(wordnetCell);
617                                                        
618                                                         if (wordnetPos == null)
619                                                         {
620                                                                 wordnetCell.html = "";
621                                                         }
622                                                         else if (ewngId == wid && canWriteToWord)
623                                                         {
624                                                                 if (wordnetGloss == null)
625                                                                 {
626                                                                         wordnetGloss = "";
627                                                                 }
628                                                                
629                                                                 wordnetCell.html = "<form method=\"post\">\n" +
630                                                                         "<input type=\"hidden\" name=\"ewng\"" +
631                                                                         " value=\"" + wid + "\">\n" +
632                                                                         "<input name=\"gloss\" size=\"10\" value=\"" +
633                                                                         wordnetGloss.replaceAll("<", "&lt;")
634                                                                                 .replaceAll(">", "&gt;") +
635                                                                         "\">\n" +
636                                                                         "<input type=\"submit\" name=\"ewngs\""+
637                                                                         " value=\"Save\">\n" +
638                                                                         "</form>";
639                                                         }
640                                                         else if (wordnetGloss == null)
641                                                         {
642                                                                 wordnetCell.html = "[<a href=\"clause.jsp?" +
643                                                                         "ewng=" + wid + "\">Add</a>]";
644                                                         }
645                                                         else
646                                                         {
647                                                                 wordnetCell.html = wordnetGloss + " [";
648                                                                
649                                                                 if (canWriteToWord)
650                                                                 {
651                                                                         wordnetCell.html +=
652                                                                                 "<a href=\"clause.jsp?" +
653                                                                                 "ewng=" + wid + "\">edit</a>|";
654                                                                 }
655                                                                
656                                                                 wordnetCell.html += "<a href=\"" +
657                                                                         "http://www.wordreference.com/definition/" +
658                                                                         URLEncoder.encode(wordnetGloss) +
659                                                                         "\">lookup</a>]";
660                                                         }
661
662                                                         if (swnsId == wid &&
663                                                                 request.getParameter("swnss") != null)
664                                                         {
665                                                                 wordnetSynset = new Long(
666                                                                         request.getParameter("wns"));
667                                                                 Change ch = emdros.createChange(
668                                                                                 EmdrosChange.UPDATE,
669                                                                                 "word", new int[] {wid});
670                                                                 ch.setInt("wordnet_synset",
671                                                                         wordnetSynset.longValue());
672                                                                 ch.execute();
673                                                                 swnsId = -1;
674                                                         }
675
676                                                         Cell glossCell = new Cell();
677                                                         cell.subcells.add(glossCell);
678                                                        
679                                                         if (wordnetPos == null)
680                                                         {
681                                                                 glossCell.html = "";
682                                                         }
683                                                         else if (wordnetGloss == null)
684                                                         {       
685                                                                 glossCell.html = "(no word to look up in Wordnet)";
686                                                         }
687                                                         else if (senses == null)
688                                                         {
689                                                                 glossCell.html = "(no match in Wordnet)";
690                                                         }
691                                                         else if (swnsId == wid && canWriteToWord)
692                                                         {
693                                                                 glossCell.html = "<form method=\"post\">\n" +
694                                                                         "<input type=\"hidden\" name=\"swns\"" +
695                                                                         " value=\"" + wid + "\">\n";
696                                                                
697                                                                 for (int i = 0; i < senses.length; i++)
698                                                                 {
699                                                                         Long key = (Long)(senses[i].getKey());
700                                                                         glossCell.html +=
701                                                                                 "<input type=\"radio\" name=\"wns\"" +
702                                                                                 " value=\"" + key.longValue() + "\"" +
703                                                                                 (key.longValue() ==
704                                                                                 wordnetSynset.longValue() ? " checked" : "") +
705                                                                                 " />" +
706                                                                                 senses[i].getGloss()
707                                                                                         .replaceAll("<", "&lt;")
708                                                                                         .replaceAll(">", "&gt;") +
709                                                                                 "<br>\n";
710                                                                 }
711                                                                
712                                                                 glossCell.html +=
713                                                                         "<input type=\"submit\" name=\"swnss\""+
714                                                                         " value=\"Save\">\n" +
715                                                                         "</form>";
716                                                         }
717                                                         else if (wordnetSynset == null)
718                                                         {
719                                                                 glossCell.html = "(no Wordnet sense selected)";
720                                                         }
721                                                         else
722                                                         {
723                                                                 Synset sense = null;
724                                                                
725                                                                 for (int i = 0; i < senses.length; i++)
726                                                                 {
727                                                                         Long key = (Long)(senses[i].getKey());
728                                                                         if (key.longValue() ==
729                                                                                 wordnetSynset.longValue())
730                                                                         {
731                                                                                 sense = senses[i];
732                                                                                 break;
733                                                                         }
734                                                                 }
735                                                                
736                                                                 if (sense == null)
737                                                                 {
738                                                                         glossCell.html =
739                                                                                 "(invalid Wordnet sense selected)";
740                                                                 }
741                                                                 else
742                                                                 {
743                                                                         glossCell.html = sense.getGloss();
744                                                                 }
745                                                         }
746                                                        
747                                                         if (wordnetPos != null && swnsId != wid &&
748                                                                 canWriteToWord)
749                                                         {
750                                                                 glossCell.html +=
751                                                                                 " [<a href=\"clause.jsp?swns=" + wid +
752                                                                                 "\">change</a>]";
753                                                         }
754                                                 }
755
756                                                 // DiB lookup
757                                                 {
758                                                         Cell dictCell = new Cell();
759                                                         cell.subcells.add(dictCell);
760                                                         String gloss = KJV.getDibGloss(
761                                                                 word.getEMdFValue("lexeme").getString());
762                                                         if (gloss == null)
763                                                         {
764                                                                 dictCell.html = "";
765                                                         }
766                                                         else
767                                                         {
768                                                                 dictCell.html = "[DiB] " + gloss;
769                                                         }       
770                                                 }
771                                                                                                
772                                                 // Hebrew-English Dictionary lookup
773                                                 if (swordVerse != null)
774                                                 {
775                                                         Cell dictCell = new Cell();
776                                                         cell.subcells.add(dictCell);
777                                                         String gloss = KJV.getKingJamesGloss(swordVerse,
778                                                                 word.getEMdFValue("lexeme").getString());
779                                                         if (gloss == null)
780                                                         {
781                                                                 dictCell.html = "";
782                                                         }
783                                                         else
784                                                         {
785                                                                 dictCell.html = "[KJV] " + gloss;
786                                                         }       
787                                                 }
788                                         }
789                                 }
790                                
791                                 if (type.equals("phrase"))
792                                 {
793                                         Cell pCell    = new Cell();
794                                         pCell.label   = phrase.getEMdFValue("phrase_function").toString();
795                                         pCell.columns = column - first_col;
796                                         struct_row.addElement(pCell);
797
798                                         if (function_name != null)
799                                                 pCell.label = phrase_type + " (" + function_name + ")";
800                                        
801                                         if (phrase_type == null)
802                                                 continue;
803                                                
804                                         Cell mrCell = new Cell();
805                                         pCell.subcells.add(mrCell);
806                                         mrCell.html = "";
807
808                                         if (phrase_type.equals("VP"))
809                                         {
810                                                 String html = "Macroroles: ";
811                                                
812                                                 switch (numSyntacticMacroroles)
813                                                 {
814                                                         case -1: html += "MR? (unknown)"; break;
815                                                         case 0:  html += "MR0"; break;
816                                                         case 1:  html += "MR1"; break;
817                                                         case 2:  html += "MR2"; break;
818                                                         case 3:  html += "MR3"; break;
819                                                         default: html += "MR! (invalid)"; break;
820                                                 }
821                                                
822                                                 mrCell.html = html;
823                                         }
824                                         else if (phrase_type.equals("NP") ||
825                                                          phrase_type.equals("IrPronNP") ||
826                                                          phrase_type.equals("PersPronNP") ||
827                                                          phrase_type.equals("DemPronNP") ||
828                                                          phrase_type.equals("PropNP") ||
829                                                          phrase_type.equals("PP"))
830                                         {
831                                                 int oldMR = phrase.getEMdFValue("macrorole_number")
832                                                         .getInt();
833                                                 String formName = "mr_" + phrase.getID_D();
834                                                        
835                                                 StringBuffer html = new StringBuffer();
836                                                 html.append("<form name=\"" + formName + "\" " +
837                                                         "method=\"POST\">\n");
838                                                 html.append("<input type=\"hidden\" name=\"pid\" " +
839                                                         "value=\"" + phrase.getID_D() + "\">\n");
840                                                 html.append("<input type=\"hidden\" name=\"prev\" " +
841                                                         "value=\"" + oldMR + "\">\n");
842                                                 html.append("<select name=\"mr\" " +
843                                                         "onChange=\"return enableChangeButton(" +
844                                                         "changemr, "+oldMR+", mr)\">\n");
845                                                 html.append("<option "+((oldMR==-1)?"SELECTED":"")+
846                                                         " value=\"-1\">Unknown\n");
847                                                 html.append("<option "+((oldMR==0) ?"SELECTED":"")+
848                                                         " value=\"0\">None\n");
849                                                 html.append("<option "+((oldMR==1) ?"SELECTED":"")+
850                                                         " value=\"1\">1 (Actor)\n");
851                                                 html.append("<option "+((oldMR==2) ?"SELECTED":"")+
852                                                         " value=\"2\">2 (Undergoer)\n");
853                                                 html.append("</select>\n");
854                                                
855                                                 if (canWriteToPhrase)
856                                                 {
857                                                         html.append("<input type=\"submit\" "+
858                                                                 "name=\"changemr\" value=\"Change\">\n");
859                                                 }
860                                                
861                                                 html.append("</form>\n");
862
863                                                 html.append("<script type=\"text/javascript\"><!--\n");
864                                                 html.append("\tenableChangeButton(" +
865                                                         "document.forms."+formName+".changemr, "+
866                                                         oldMR+", "+
867                                                         "document.forms."+formName+".mr)\n");
868                                                 html.append("//--></script>\n");
869
870                                                 mrCell.html = html.toString();
871                                         }
872                                                
873                                         if (! phrase_type.equals("NP") &&
874                                                 ! phrase_type.equals("IrPronNP") &&
875                                                 ! phrase_type.equals("PersPronNP") &&
876                                                 ! phrase_type.equals("DemPronNP") &&
877                                                 ! phrase_type.equals("PropNP") &&
878                                                 ! phrase_type.equals("PP"))
879                                                 continue;
880
881                                         Cell varCell = new Cell();
882                                         pCell.subcells.add(varCell);
883
884                                         StringBuffer editHtml = new StringBuffer();
885                                          
886                                         String oldArg = phrase.getEMdFValue("argument_name")
887                                                 .toString();
888                                         String newArg = "";
889
890                                         if (oldArg.equals(""))
891                                         {
892                                                 // Argument not decided yet. Maybe we can guess
893                                                 // based on the "function" of the clause?
894                                                
895                                                 if (
896                                                         function_name.equals("Subj") ||
897                                                         function_name.equals("PreS") ||
898                                                         function_name.equals("IrpS") ||
899                                                         function_name.equals("ModS"))
900                                                 {
901                                                         newArg = "x";
902                                                 }
903                                                 else if (
904                                                         function_name.equals("Objc") ||
905                                                         function_name.equals("PreC") ||
906                                                         function_name.equals("PreO") ||
907                                                         function_name.equals("PtcO") ||
908                                                         function_name.equals("IrpO"))
909                                                 {
910                                                         newArg = "y";
911                                                 }
912                                                
913                                                 if (newArg != oldArg &&
914                                                         argNamesHash.get(newArg) != null)
915                                                 {
916                                                         if (canWriteToPhrase)
917                                                         {
918                                                                 Change ch = emdros.createChange(
919                                                                         EmdrosChange.UPDATE,
920                                                                         "phrase", new int[]{phrase.getID_D()});
921                                                                 ch.setString("argument_name", newArg);
922                                                                 ch.execute();
923                                                         }
924                                                         oldArg = newArg;
925                                                 }
926                                         }
927                                         else if (argNamesHash.get(oldArg) == null)
928                                         {
929                                                 argNames.add(oldArg);
930                                                 argNamesHash.put(oldArg, Boolean.TRUE);
931                                         }
932                                                
933                                         if (oldArg.equals(""))
934                                         {
935                                                 if (! newArg.equals(""))
936                                                 {
937                                                         editHtml.append("<font color=\"red\">" +
938                                                                 "Variable not set</font> " +
939                                                                 "(defaults to <em>"+newArg+"</em>)");
940                                                 }
941                                                 else
942                                                 {
943                                                         editHtml.append("<font color=\"red\">" +
944                                                                 "Variable not set</font>");
945                                                 }
946                                         }
947                                         else if (variables.get(oldArg) != null)
948                                         {
949                                                 editHtml.append("<font color=\"red\">" +
950                                                         "Duplicate variable!</font>");
951                                         }
952                                         else
953                                         {
954                                                 variables.put(oldArg, phrase);
955                                         }
956
957                                         String formName = "sv_" + phrase.getID_D();
958
959                                         editHtml.append(
960                                                 "<form method=\"post\" name=\""+formName+"\">\n" +
961                                                 "<input type=\"hidden\" name=\"phraseid\"" +
962                                                 " value=\"" + phrase.getID_D() + "\">\n" +
963                                                 "<select name=\"newarg\" onChange=\"return " +
964                                                 "enableChangeButton(savearg,'"+oldArg+"',newarg)" +
965                                                 "\">\n" +
966                                                 "<option value=\"\" " +
967                                                 (oldArg.equals("") ? " SELECTED" : "") +
968                                                 ">Auto\n" +
969                                                 "<option value=\" \" " +
970                                                 (oldArg.equals(" ") ? " SELECTED" : "") +
971                                                 ">None\n");
972
973                                         for (int j = 0; j < argNames.size(); j++) {
974                                                 String arg = (String)( argNames.elementAt(j) );
975                                                 editHtml.append("<option value=\""+arg+
976                                                         "\""+(oldArg.equals(arg)?" SELECTED":"")+
977                                                         ">"+arg+"\n");
978                                         }
979
980                                         editHtml.append("</select>\n");
981                                        
982                                         if (canWriteToPhrase)
983                                         {
984                                                 editHtml.append
985                                                 (
986                                                         "<input type=\"submit\" name=\"savearg\" "+
987                                                         "value=\"Change\">\n"
988                                                 );
989                                         }
990                                        
991                                         editHtml.append("</form>\n");
992
993                                         editHtml.append("<script type=\"text/javascript\"><!--\n" +
994                                                 "enableChangeButton(" +
995                                                 "document.forms."+formName+".savearg,\""+oldArg+"\"," +
996                                                 "document.forms."+formName+".newarg)\n" +
997                                                 "//--></script>\n");
998                                                                                                
999                                         varCell.html = editHtml.toString();
1000
1001                                         /*
1002                                         Cell typeCell = new Cell();
1003                                         pCell.subcells.add(typeCell);
1004                                         editHtml = new StringBuffer();
1005
1006                                         int oldType = phrase.getEMdFValue("type_id")
1007                                                 .getInt();
1008                                                
1009                                         editHtml.append("<form method=\"post\">\n" +
1010                                                 "<input type=\"hidden\" name=\"phraseid\"" +
1011                                                 " value=\"" + phrase.getID_D() + "\">\n" +
1012                                                 "<select name=\"newtype\">\n" +
1013                                                 "<option value=\"\" " +
1014                                                 (oldType == 0 ? " SELECTED" : "") +
1015                                                 ">None\n");
1016
1017                                         for (int j = 0; j < types.length; j++) {
1018                                                 DataType t = types[j];
1019                                                 editHtml.append("<option value=\""+t.id+
1020                                                         "\""+(oldType == t.id ? " SELECTED" : "")+
1021                                                         ">");
1022                                                 while (t.depth-- > 0) {
1023                                                         editHtml.append("&nbsp;");
1024                                                 }
1025                                                 editHtml.append(t.name+"\n");
1026                                         }
1027
1028                                         editHtml.append("</select>\n" +
1029                                                 "<input type=\"submit\" name=\"savetype\" "+
1030                                                 "value=\"Save\">\n"+
1031                                                 "</form>\n");
1032                                        
1033                                         typeCell.html = editHtml.toString();
1034                                         */
1035                                 }
1036                         }
1037
1038                        
1039                         Vector bigRows = new Vector();
1040                         if (word_row.size() > 0)
1041                                 bigRows.add(word_row);
1042                         if (struct_row.size() > 0)
1043                                 bigRows.add(struct_row);
1044
1045                         Cell filler = new Cell();
1046                         filler.label = "";
1047
1048                         for (int nBigRow = 0; nBigRow < bigRows.size(); nBigRow++) {
1049                                 Vector bigRow = (Vector)( bigRows.elementAt(nBigRow) );
1050                                 int numColumns = bigRow.size();
1051                                 int littleRowsThisBigRow = 0;
1052                                
1053                                 for (Enumeration e = bigRow.elements();
1054                                         e.hasMoreElements(); )
1055                                 {
1056                                         Cell c = (Cell)(e.nextElement());
1057                                         int reqRows = c.subcells.size();
1058                                         if (reqRows > littleRowsThisBigRow)
1059                                                 littleRowsThisBigRow = reqRows;
1060                                 }
1061                                
1062                                 // don't forget to count the top cell as well!
1063                                 littleRowsThisBigRow++;
1064                                
1065                                 for (int r = 0; r < littleRowsThisBigRow; r++) {
1066                                         %><!-- <%= nBigRow %>/<%= r %> -->
1067                                         <tr>
1068                                         <%
1069                                        
1070                                         if (r == 0) {
1071                                                 %>
1072                                                 <th rowspan="<%= littleRowsThisBigRow %>">
1073                                                         <%= type %>
1074                                                 </th>
1075                                                 <%
1076                                         }
1077
1078                                         for (int c = 0; c < numColumns; c++) {
1079                                                 Cell topCell  = (Cell)( bigRow.elementAt(c) );
1080                                                 Cell thisCell = topCell;
1081                                                 if (r > 0) {
1082                                                         if (topCell.subcells != null &&
1083                                                                 r <= topCell.subcells.size())
1084                                                         {
1085                                                                 thisCell = (Cell)(
1086                                                                         topCell.subcells.elementAt(r - 1) );
1087                                                         } else {
1088                                                                 thisCell = filler;
1089                                                         }
1090                                                 }
1091
1092                                                 %>
1093                                                 <td colspan="<%= topCell.columns %>"><%
1094
1095                                                 if (thisCell.html != null) {
1096                                                         %><%= thisCell.html %><%
1097                                                 } else {
1098                                                         String html = thisCell.label
1099                                                                 .replaceAll("<", "&lt;")
1100                                                                 .replaceAll(">", "&gt;");
1101                                                        
1102                                                         if (thisCell.link != null) {
1103                                                                 %><a href="<%= thisCell.link %>"><%
1104                                                         }
1105
1106                                                         %><%= html %><%
1107
1108                                                         if (thisCell.link != null) {
1109                                                                 %></a>><%
1110                                                         }
1111                                                 }
1112                                                
1113                                                 %>
1114                                                 </td><%
1115                                         }
1116        
1117                                         %>
1118                                         </tr>
1119                                         <%
1120                                 }
1121                         }
1122                 }
1123        
1124                 %>
1125                 </table>
1126                 </p>
1127        
1128                 <%
1129                
1130                 {
1131                         Parser p = new Parser(sql);
1132                         p.setVerbose(true);
1133                         List sentences = p.parseFor(morphEdges, "SENTENCE");
1134                        
1135                         if (sentences.size() == 0)
1136                         {
1137                                 %>
1138                                 <p>
1139                                 Parse failed. Click <a href="parse.jsp">here</a> to fix it.
1140                                 </p>
1141                                 <%
1142                         }
1143                         else
1144                         {
1145                                 %>
1146                                 <p>
1147                                 Parse finished with <%= sentences.size() %> possible trees.
1148                                 Showing the first
1149                                 <%= sentences.size() > 3 ? 3 : sentences.size() %>:
1150                                 </p>
1151                                 <%
1152                                 for (int i = 0; i < sentences.size() && i < 3; i++)
1153                                 {
1154                                         Edge sentence = (Edge)( sentences.get(i) );
1155                                        
1156                                         %><%= sentence.toTree().toHtml(rend) %><%
1157                                 }
1158                                
1159                                 %><p>
1160                                 Click
1161                                 <a href="parse.jsp">here</a>
1162                                 to see and edit all <%= sentences.size() %> parses.
1163                                 </p><%
1164                         }
1165                 }
1166                
1167                 %>
1168
1169                 <p>
1170                 <%
1171                 if (!emdros.canWriteTo(clause))
1172                 {
1173                         // just show the current value
1174                         try
1175                         {
1176                                 PreparedStatement stmt = sql.prepareSelect
1177                                         ("SELECT ID,Structure,Syntactic_Args " +
1178                                          "FROM lexicon_entries WHERE ID = ?");
1179                                 stmt.setInt(1, currentLsId);
1180                                
1181                                 ResultSet rs = sql.select();
1182                                
1183                                 if (rs.next())
1184                                 {
1185                                         int    thisLsId      = rs.getInt("ID");
1186                                         String thisStructure = rs.getString("Structure");
1187                                         int    thisNumSMRs   = rs.getInt("Syntactic_Args");
1188
1189                                         if (thisStructure != null)
1190                                         {
1191                                                 structure = thisStructure;
1192                                         }
1193                                         numSyntacticMacroroles = thisNumSMRs;
1194                                 }
1195                         }
1196                         catch (DatabaseException ex)
1197                         {
1198                                 %><%= ex %><%
1199                         }
1200                         finally
1201                         {
1202                                 sql.finish();
1203                         }
1204                        
1205                         %>
1206                         Selected lexicon entry logical structure:
1207                         <%=
1208                                 structure.equals("") ? "none" : structure
1209                                                 .replaceAll("<", "&lt;")
1210                                                 .replaceAll(">", "&gt;")
1211                         %>
1212                         <%
1213                 }
1214                 else if (selLsIdString != null && selLsIdString.equals("add"))
1215                 {
1216                         // Change button clicked and "Add..." selected,
1217                         // show LS entry box
1218                         %>
1219                 <form name="changels" method="POST">
1220                 Enter new logical structure:
1221                 <input name="newls"/>
1222                 <input type="submit" name="create" value="Create"/>
1223                 <input type="submit" name="cancel" value="Cancel"/>
1224                 </form>
1225                         <%
1226                 }
1227                 else
1228                 {
1229                         // Show LS selector box, Change button, and maybe Edit button
1230
1231                         %>
1232                 <table><tr><td>
1233                         <form name="changels" method="POST">
1234                         Choose logical structure:
1235                         <select name="lsid" onChange="enableEditButton();
1236                         return enableChangeButton(lssave,<%= currentLsId %>,lsid)">
1237                         <option value="0" <%= (currentLsId == 0) ? " SELECTED" : "" %>>Not specified
1238                         <%
1239
1240                         try
1241                         {
1242                                 PreparedStatement stmt = sql.prepareSelect
1243                                         ("SELECT ID,Structure,Syntactic_Args " +
1244                                          "FROM lexicon_entries WHERE Lexeme = ?");
1245                                 stmt.setString(1, predicate_text);
1246                                
1247                                 ResultSet rs = sql.select();
1248                                 while (rs.next())
1249                                 {
1250                                         int    thisLsId      = rs.getInt("ID");
1251                                         String thisStructure = rs.getString("Structure");
1252                                         int    thisNumSMRs   = rs.getInt("Syntactic_Args");
1253                                        
1254                                         if (thisLsId == currentLsId)
1255                                         {
1256                                                 if (thisStructure != null)
1257                                                 {
1258                                                         structure = thisStructure;
1259                                                 }
1260                                                 numSyntacticMacroroles = thisNumSMRs;
1261                                         }
1262                                        
1263                                         %>
1264                         <option value="<%=
1265                                 thisLsId
1266                         %>"<%=
1267                                 thisLsId == currentLsId ? " SELECTED" : ""
1268                         %>><%=
1269                                 thisStructure == null
1270                                 ? "(undefined structure "+thisLsId+")"
1271                                 : (thisStructure
1272                                                 .replaceAll("<", "&lt;")
1273                                                 .replaceAll(">", "&gt;"))
1274                         %>
1275                                         <%
1276                                 }
1277                         }
1278                         catch (DatabaseException ex)
1279                         {
1280                                 %><%= ex %><%
1281                         }
1282                         finally
1283                         {
1284                                 sql.finish();
1285                         }
1286                
1287                         %>
1288                         <option value="add" <%=
1289                                 selLsIdString != null && selLsIdString.equals("add")
1290                                 ? " SELECTED" : ""
1291                         %>>Add new...
1292                         </select>
1293                         <input type="submit" name="lssave" value="Change">
1294                         </form>
1295                         <script type="text/javascript"><!--
1296                         enableChangeButton(document.forms.changels.lssave,<%= currentLsId %>,
1297                                                            document.forms.changels.lsid);
1298                         //--></script>
1299                 </td>
1300                         <%
1301                        
1302                         if (selLsIdString == null || ! selLsIdString.equals("0"))
1303                         {
1304                                 %>
1305                 <td>
1306                         <form name="editls" method="get" action="lexicon.jsp">
1307                         <input type="hidden" name="lsid" value="<%= currentLsId %>">
1308                         <input type="submit" name="submit" value="Edit...">
1309                         </form>
1310                 </td>
1311                                 <%
1312                         }
1313
1314                         %>
1315                 </table>
1316                         <%
1317                 }
1318                 %>
1319                 </p>
1320                                
1321                 <script type="text/javascript"><!--
1322                         enableEditButton();
1323                 //--></script>
1324                
1325                 <p>Linked logical structure:
1326                 <%
1327
1328                 for (Enumeration e = variables.keys(); e.hasMoreElements();)
1329                 {
1330                         String variable = (String)( e.nextElement() );
1331                         MatchedObject value = (MatchedObject)
1332                                 ( variables.get(variable) );
1333                         String value_text = "";
1334                         SheafConstIterator sci = value.getSheaf().const_iterator();
1335                        
1336                         while (sci.hasNext())
1337                         {
1338                                 MatchedObject word = sci.next().const_iterator().next();
1339                                 value_text += HebrewConverter.wordTranslitToHtml(word, generator);
1340                                 if (sci.hasNext())
1341                                 {
1342                                         value_text += " ";
1343                                 }
1344                         }
1345                        
1346                         structure = structure.replaceAll
1347                                 ("<" + variable + ">", value_text);
1348                 }
1349                
1350                 %>
1351                 <%= structure.replaceAll("<","&lt;").replaceAll(">","&gt;") %></p>
1352                 <%     
1353
1354                 String currentStruct = clause.getEMdFValue("logical_structure")
1355                         .getString();
1356                 if (! currentStruct.equals(structure) && emdros.canWriteTo(clause))
1357                 {
1358                         Change ch = emdros.createChange(EmdrosChange.UPDATE,
1359                                 "clause", new int[]{navigator.getClauseId()});
1360                         ch.setString("logical_structure", structure);
1361                         ch.execute();
1362                 }
1363
1364                 %><h3>Notes</h3><%
1365                
1366                 if (request.getParameter("nc") != null &&
1367                         request.getParameter("nt") != null)
1368                 {
1369                         String newNoteText = request.getParameter("nt");
1370                        
1371                         EmdrosChange ch = (EmdrosChange)(
1372                                 emdros.createChange(EmdrosChange.CREATE,
1373                                         "note", new int[]{navigator.getClauseId()}));
1374                         ch.setString("text", newNoteText);
1375                         ch.execute();
1376                 }
1377        
1378                 if (request.getParameter("nu") != null &&
1379                         request.getParameter("ni") != null &&
1380                         request.getParameter("nt") != null)
1381                 {
1382                         String updateNoteIdString = request.getParameter("ni");
1383                         int updateNoteId = Integer.parseInt(updateNoteIdString);
1384                         String newNoteText = request.getParameter("nt");
1385                        
1386                         EmdrosChange ch = (EmdrosChange)(
1387                                 emdros.createChange(EmdrosChange.UPDATE,
1388                                         "note", new int [] {updateNoteId}));
1389                         ch.setString("text", newNoteText);
1390                         ch.execute();
1391                 }
1392        
1393                 if (request.getParameter("nd") != null &&
1394                         request.getParameter("ni") != null)
1395                 {
1396                         String deleteNoteIdString = request.getParameter("ni");
1397                         int deleteNoteId = Integer.parseInt(deleteNoteIdString);
1398                        
1399                         EmdrosChange ch = (EmdrosChange)(
1400                                 emdros.createChange(EmdrosChange.DELETE,
1401                                         "note", new int[]{deleteNoteId}));
1402                         ch.execute();
1403        
1404                         %><table border><%
1405                        
1406                         boolean foundNotes = false;
1407        
1408                         String editNoteIdString = request.getParameter("ni");
1409                         int editNoteId = -1;
1410                         if (editNoteIdString != null)
1411                         {
1412                                 editNoteId = Integer.parseInt(editNoteIdString);
1413                         }
1414                
1415                         Sheaf clauseSheaf = emdros.getSheaf
1416                                 ("SELECT ALL OBJECTS IN { "+min_m+" - "+max_m+"} "+
1417                                  "WHERE [clause self = "+navigator.getClauseId()+
1418                                  " [note GET text]"+
1419                                  "]");
1420        
1421                         SheafConstIterator sci = clauseSheaf.const_iterator();
1422                         while (sci.hasNext())
1423                         {
1424                                 Straw straw = sci.next();
1425                                 clause = straw.const_iterator().next();
1426                                
1427                                 Sheaf noteSheaf = clause.getSheaf();
1428                                 SheafConstIterator nsci = noteSheaf.const_iterator();
1429                                 while (nsci.hasNext())
1430                                 {
1431                                         Straw ns = nsci.next();
1432                                         MatchedObject note = ns.const_iterator().next();
1433                                
1434                                         String noteText = note.getEMdFValue("text").getString();
1435                                         if (!foundNotes)
1436                                         {
1437                                                 foundNotes = true;
1438                                         }
1439                                        
1440                                         %><tr><%
1441        
1442                                         if (request.getParameter("ne") != null &&
1443                                                 editNoteId == note.getID_D())
1444                                         {
1445                                                 %>
1446         <form method="POST" action="clause.jsp">
1447         <input type="hidden" name="ni" value="<%= note.getID_D() %>" />
1448         <td>
1449                 <input name="nt" size="80" value="<%=
1450                 noteText.replaceAll("<", "&lt;").replaceAll(">", "&gt;")
1451         %>" />
1452         </td>
1453         <td>
1454                 <input type="submit" name="nu" value="Update" />
1455                 <input type="submit" name="nd" value="Delete" />
1456         </td>
1457         </form>
1458                                                 <%
1459                                         }
1460                                         else
1461                                         {
1462                                                 %>                                     
1463         <td><%= noteText.replaceAll("<", "&lt;").replaceAll(">", "&gt;") %></td>
1464         <td>
1465                 <a href="clause.jsp?ni=<%= note.getID_D() %>&ne=1">Edit</a>
1466         </td>
1467                                                 <%
1468                                         }
1469        
1470                                         %></tr><%
1471                                 }
1472                         }
1473                        
1474                         if (!foundNotes)
1475                         {
1476                                 %><tr><td>No notes for this clause</td></tr><%
1477                         }
1478                 }
1479                        
1480                 %>
1481 </table>
1482
1483 <p><form method="POST">
1484 <table>
1485 <tr>
1486 <td>Add note:</td>
1487 <td><input name="nt" size="80"></td>
1488 <td><input type="submit" name="nc" value="Create"></td>
1489 </tr>
1490 </table>
1491 </form></p>
1492        
1493 <p><a href="gen-export.jsp?clause=<%= navigator.getClauseId() %>">Download clause in
1494         GEN format for LTC</a>.</p>
1495
1496 <%
1497                 if (emdros.canWriteTo(clause))
1498                 {
1499                         if (request.getParameter("publish") != null)
1500                         {
1501                                 Change ch = sql.createChange(SqlChange.INSERT,
1502                                         "user_text_access", null);
1503                                 ch.setInt("Monad_First", clause.getMonads().first());
1504                                 ch.setInt("Monad_Last",  clause.getMonads().last());
1505                                 ch.setString("User_Name",   "anonymous");
1506                                 ch.setInt("Write_Access", 0);
1507                                 ch.execute();
1508
1509                                 ch = emdros.createChange(EmdrosChange.UPDATE, "clause",
1510                                         new int[]{clause.getID_D()});
1511                                 ch.setInt("published", 1);
1512                                 ch.setString("predicate", predicate_text);
1513                                 ch.execute();
1514                         }
1515                         else if (request.getParameter("unpublish") != null)
1516                         {
1517                                 Change ch = sql.createChange(SqlChange.DELETE,
1518                                         "user_text_access",
1519                                         "Monad_First = " + clause.getMonads().first() + " AND " +
1520                                         "Monad_Last  = " + clause.getMonads().last()  + " AND " +
1521                                         "User_Name   = \"anonymous\"");
1522                                 ch.execute();
1523        
1524                                 ch = emdros.createChange(EmdrosChange.UPDATE, "clause",
1525                                         new int[]{clause.getID_D()});
1526                                 ch.setInt("published", 0);
1527                                 ch.execute();
1528                         }
1529                
1530                         boolean isPublished = sql.getSingleInteger("SELECT COUNT(1) " +
1531                                 "FROM user_text_access " +
1532                                 "WHERE Monad_First = " + clause.getMonads().first() +
1533                                 " AND  Monad_Last  = " + clause.getMonads().last()  +
1534                                 " AND  User_Name   = \"anonymous\"") > 0;
1535                
1536                         %>
1537                         <form method="POST">
1538                                 <% if (isPublished) { %>
1539                                 <input type="submit" name="unpublish" value="Unpublish" />
1540                                 <% } else { %>
1541                                 <input type="submit" name="publish" value="Publish" />
1542                                 <% } %>
1543                         </form>
1544                         <%
1545                 }
1546         }
1547 %>
1548        
1549 <hr>
1550         <%= session.getAttribute("book") %>,
1551 Chapter <%= session.getAttribute("chapterNum") %>,
1552 Verse   <%= session.getAttribute("verseNum") %>,
1553 Clause  <%= session.getAttribute("clauseId") %>
1554 </form>
1555
1556 <%@ include file="include/footer.jsp" %>
Note: See TracBrowser for help on using the browser.