Changeset 262

Show
Ignore:
Timestamp:
01/05/08 19:38:11 (1 year ago)
Author:
chris
Message:

Remove wordnet and ontology database.

Move hebrew text to a line above morpheme table.

Move translation into table as bottom line.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lex/trunk/jsp/clause.jsp

    r259 r262  
    55<%@ page import="java.net.*" %> 
    66<%@ page import="java.sql.*" %> 
    7 <%@ page import="com.qwirx.lex.ontology.*" %> 
    8 <%@ page import="com.qwirx.lex.wordnet.*" %> 
    97<%@ page import="com.qwirx.lex.parser.*" %> 
    108<%@ page import="com.qwirx.lex.morph.*" %> 
     
    6058<%@ include file="auth.jsp" %> 
    6159 
     60<%@ include file="navclause.jsp" %> 
     61 
    6262<% 
    63  
    64         Wordnet wordnet = Wordnet.getInstance(); 
    65  
    66 %><%@ include file="navclause.jsp" %><% 
    6763 
    6864        Map phrase_functions = emdros.getEnumerationConstants 
     
    153149        else  
    154150        { 
    155                 OntologyDb ontology = Lex.getOntologyDb(); 
    156                  
    157151                String predicate_text = ""; 
    158152                StringBuffer hebrewText = new StringBuffer(); 
    159153                List morphEdges = new ArrayList(); 
    160154                HebrewMorphemeGenerator generator = new HebrewMorphemeGenerator(); 
     155                BookData swordVerse = null; 
    161156                 
    162157                /* Prescan to find the predicate lexeme and populate the chart */ 
    163158                 
    164159                { 
    165                         TreeNode root = new TreeNode("root"); 
    166  
     160                        List<String[]> columns = new ArrayList<String[]>(); 
    167161                        SheafConstIterator phrases = clause.getSheaf().const_iterator(); 
    168162                        boolean isFirstWord = true; 
     
    189183                                        class HebrewFeatureConverter implements MorphemeHandler 
    190184                                        { 
    191                                                 private TreeNode m_root
     185                                                private List<String[]> m_Columns
    192186                                                private MatchedObject m_word; 
    193187                                                private StringBuffer m_hebrew; 
     
    196190                                                boolean m_IsMorpheme; 
    197191                                                 
    198                                                 public HebrewFeatureConverter(TreeNode root
     192                                                public HebrewFeatureConverter(List<String[]> columns
    199193                                                        MatchedObject word, StringBuffer hebrew, 
    200194                                                        List morphs, boolean isFirstWord, 
    201195                                                        boolean isLastWord) 
    202196                                                { 
    203                                                         m_root   = root
     197                                                        m_Columns = columns
    204198                                                        m_word   = word; 
    205199                                                        m_hebrew = hebrew; 
     
    252246                                                        } 
    253247 
    254                                                         TreeNode node = m_root.createChild(translit); 
    255                                                         // node = node.createChild(raw); 
    256248                                                        if (desc == null) desc = ""; 
    257                                                         node.createChild(desc); 
    258  
     249 
     250                                                        m_Columns.add(new String[]{translit, desc}); 
     251                                                         
    259252                                                        if (lastMorpheme && !m_IsLastWord) 
    260253                                                        { 
    261254                                                                // blank cell between words 
    262                                                                 m_root.createChild(""); 
     255                                                                m_Columns.add(new String[]{"",""}); 
    263256                                                        } 
    264257                                                         
     
    269262 
    270263                                        HebrewFeatureConverter hfc =  
    271                                                 new HebrewFeatureConverter(root, word, hebrewText, 
     264                                                new HebrewFeatureConverter(columns, word, hebrewText, 
    272265                                                        morphEdges, isFirstWord, 
    273266                                                        !phrases.hasNext() && !words.hasNext()); 
     
    278271                                        if (!hfc.isMorpheme()) 
    279272                                        {                                
    280                                                 hebrewText.append(" ");                                                 
     273                                                hebrewText.append(" "); 
    281274                                        } 
    282275                                         
     
    289282                        } 
    290283                         
    291                         root.setLabel("<span class=\"hebrew\">" + 
    292                                 HebrewConverter.toHtml(hebrewText.toString()) +  
    293                                 "</span>"); 
    294          
    295                         %><%= root.toHtml(rend) %><% 
    296                 } 
    297  
    298                 BookData swordVerse = null; 
    299                 try 
    300                 { 
    301                         swordVerse = KJV.getVerse(emdros, selBook, selChapNum, 
    302                                 selVerseNum); 
    303                         %><p><em><%=  
    304                                 OSISUtil.getCanonicalText(swordVerse.getOsisFragment()) 
    305                         %></em></p><% 
    306                 } 
    307                 catch (Exception e) 
    308                 { 
    309                         %><p>KJV Gloss not found (<%= e %>)</p><% 
    310                 }                
    311                          
     284                        %> 
     285 
     286                        <span class="hebrew"><%=  
     287                                HebrewConverter.toHtml(hebrewText.toString()) 
     288                        %></span> 
     289 
     290                        <table>  
     291                                <% for (int row = 0; row < 2; row++) { %> 
     292                                <tr> 
     293                                        <% 
     294                                        for (Iterator<String[]> i = columns.iterator(); 
     295                                                i.hasNext();)  
     296                                        { 
     297                                        %> 
     298                                                <% String [] rows = i.next(); %> 
     299                                                <td><%= rows[row] %></td>        
     300                                        <% 
     301                                        } 
     302                                        %> 
     303                                </tr> 
     304                                <% } %> 
     305                                <tr> 
     306                                        <td colspan="<%= columns.size() %>"><% 
     307                                        try 
     308                                        { 
     309                                                swordVerse = KJV.getVerse(emdros, selBook, selChapNum, 
     310                                                        selVerseNum); 
     311                                                %><em><%=  
     312                                                        OSISUtil.getCanonicalText(swordVerse.getOsisFragment()) 
     313                                                %></em><% 
     314                                        } 
     315                                        catch (Exception e) 
     316                                        { 
     317                                                %>KJV Gloss not found (<%= e %>)<% 
     318                                        }                
     319                                        %></td> 
     320                                </tr>    
     321                        </table> 
     322                        <% 
     323                } 
     324 
    312325                %> 
    313326                <p>Predicate text is: <%=  
     
    439452                } 
    440453 
    441                 // "ewng" stands for "edit WordNet gloss" 
    442                 String ewngString = request.getParameter("ewng"); 
    443                 int ewngId = -1; 
    444                 if (ewngString != null) { 
    445                         ewngId = Integer.parseInt(ewngString); 
    446                 } 
    447  
    448                 // "swns" stands for "select WordNet sense" 
    449                 String swnsString = request.getParameter("swns"); 
    450                 int swnsId = -1; 
    451                 if (swnsString != null) { 
    452                         swnsId = Integer.parseInt(swnsString); 
    453                 } 
    454                  
    455454                for (int objectNum = 0; objectNum < object_types.length;  
    456455                        objectNum++)  
     
    542541                                                } 
    543542 
    544                                                 // wordnet gloss 
    545                                                 { 
    546                                                         String wordnetGloss = word 
    547                                                                 .getEMdFValue("wordnet_gloss") 
    548                                                                 .getString(); 
    549                                                         Long wordnetSynset = new Long(word 
    550                                                                 .getEMdFValue("wordnet_synset") 
    551                                                                 .getInt()); 
    552                                                                  
    553                                                         if (wordnetGloss == null || 
    554                                                                 wordnetGloss.equals("")) 
    555                                                         { 
    556                                                                 OntologyDb.OntologyEntry entry =  
    557                                                                         ontology.getWordByLexeme( 
    558                                                                                 word.getEMdFValue("lexeme") 
    559                                                                                 .getString()); 
    560                                                                 if (entry != null) 
    561                                                                 { 
    562                                                                         wordnetGloss  = entry.m_EnglishGloss; 
    563                                                                 } 
    564                                                                 else 
    565                                                                 { 
    566                                                                         wordnetGloss  = null; 
    567                                                                 } 
    568                                                                  
    569                                                                 if (entry != null &&  
    570                                                                         wordnetSynset.longValue() == 0) 
    571                                                                 { 
    572                                                                         wordnetSynset = entry.m_Synset; 
    573                                                                 } 
    574                                                         } 
    575  
    576                                                         if (ewngId == wid && 
    577                                                                 request.getParameter("ewngs") != null)  
    578                                                         { 
    579                                                                 wordnetGloss = request.getParameter("gloss"); 
    580                                                                 Change ch = emdros.createChange( 
    581                                                                                 EmdrosChange.UPDATE,  
    582                                                                                 "word", new int[] {wid}); 
    583                                                                 ch.setString("wordnet_gloss", wordnetGloss); 
    584                                                                 ch.execute(); 
    585                                                                 ewngId = -1; 
    586                                                         } 
    587                                                          
    588                                                         POS wordnetPos = null; 
    589                                                          
    590                                                         if (part_of_speech.equals("verb")) 
    591                                                         { 
    592                                                                 wordnetPos = POS.VERB; 
    593                                                         } 
    594                                                         else if (part_of_speech.equals("noun")) 
    595                                                         { 
    596                                                                 wordnetPos = POS.NOUN; 
    597                                                         } 
    598                                                         else if (part_of_speech.equals("adjective")) 
    599                                                         { 
    600                                                                 wordnetPos = POS.ADJECTIVE; 
    601                                                         } 
    602                                                         else if (part_of_speech.equals("adverb")) 
    603                                                         { 
    604                                                                 wordnetPos = POS.ADVERB; 
    605                                                         } 
    606                                                                  
    607                                                         Synset [] senses = null; 
    608                                                         if (wordnetPos != null && wordnetGloss != null) 
    609                                                         { 
    610                                                                 senses = wordnet.getSenses(wordnetPos,  
    611                                                                         wordnetGloss); 
    612                                                         } 
    613                                                          
    614                                                         Cell wordnetCell = new Cell(); 
    615                                                         cell.subcells.add(wordnetCell); 
    616                                                          
    617                                                         if (wordnetPos == null) 
    618                                                         { 
    619                                                                 wordnetCell.html = ""; 
    620                                                         } 
    621                                                         else if (ewngId == wid && canWriteToWord)  
    622                                                         { 
    623                                                                 if (wordnetGloss == null) 
    624                                                                 { 
    625                                                                         wordnetGloss = ""; 
    626                                                                 } 
    627                                                                  
    628                                                                 wordnetCell.html = "<form method=\"post\">\n" + 
    629                                                                         "<input type=\"hidden\" name=\"ewng\"" + 
    630                                                                         " value=\"" + wid + "\">\n" + 
    631                                                                         "<input name=\"gloss\" size=\"10\" value=\"" + 
    632                                                                         wordnetGloss.replaceAll("<", "&lt;") 
    633                                                                                 .replaceAll(">", "&gt;") + 
    634                                                                         "\">\n" + 
    635                                                                         "<input type=\"submit\" name=\"ewngs\""+ 
    636                                                                         " value=\"Save\">\n" + 
    637                                                                         "</form>"; 
    638                                                         }  
    639                                                         else if (wordnetGloss == null) 
    640                                                         { 
    641                                                                 wordnetCell.html = "[<a href=\"clause.jsp?" + 
    642                                                                         "ewng=" + wid + "\">Add</a>]"; 
    643                                                         } 
    644                                                         else 
    645                                                         { 
    646                                                                 wordnetCell.html = wordnetGloss + " ["; 
    647                                                                  
    648                                                                 if (canWriteToWord) 
    649                                                                 { 
    650                                                                         wordnetCell.html +=  
    651                                                                                 "<a href=\"clause.jsp?" + 
    652                                                                                 "ewng=" + wid + "\">edit</a>|"; 
    653                                                                 } 
    654                                                                  
    655                                                                 wordnetCell.html += "<a href=\"" + 
    656                                                                         "http://www.wordreference.com/definition/" + 
    657                                                                         URLEncoder.encode(wordnetGloss) + 
    658                                                                         "\">lookup</a>]"; 
    659                                                         } 
    660  
    661                                                         if (swnsId == wid && 
    662                                                                 request.getParameter("swnss") != null)  
    663                                                         { 
    664                                                                 wordnetSynset = new Long( 
    665                                                                         request.getParameter("wns")); 
    666                                                                 Change ch = emdros.createChange( 
    667                                                                                 EmdrosChange.UPDATE,  
    668                                                                                 "word", new int[] {wid}); 
    669                                                                 ch.setInt("wordnet_synset",  
    670                                                                         wordnetSynset.longValue()); 
    671                                                                 ch.execute(); 
    672                                                                 swnsId = -1; 
    673                                                         } 
    674  
    675                                                         Cell glossCell = new Cell(); 
    676                                                         cell.subcells.add(glossCell); 
    677                                                          
    678                                                         if (wordnetPos == null) 
    679                                                         { 
    680                                                                 glossCell.html = ""; 
    681                                                         } 
    682                                                         else if (wordnetGloss == null) 
    683                                                         {        
    684                                                                 glossCell.html = "(no word to look up in Wordnet)"; 
    685                                                         } 
    686                                                         else if (senses == null) 
    687                                                         { 
    688                                                                 glossCell.html = "(no match in Wordnet)"; 
    689                                                         } 
    690                                                         else if (swnsId == wid && canWriteToWord) 
    691                                                         { 
    692                                                                 glossCell.html = "<form method=\"post\">\n" + 
    693                                                                         "<input type=\"hidden\" name=\"swns\"" + 
    694                                                                         " value=\"" + wid + "\">\n"; 
    695                                                                  
    696                                                                 for (int i = 0; i < senses.length; i++) 
    697                                                                 { 
    698                                                                         Long key = (Long)(senses[i].getKey()); 
    699                                                                         glossCell.html +=  
    700                                                                                 "<input type=\"radio\" name=\"wns\"" + 
    701                                                                                 " value=\"" + key.longValue() + "\"" + 
    702                                                                                 (key.longValue() == 
    703                                                                                 wordnetSynset.longValue() ? " checked" : "") + 
    704                                                                                 " />" + 
    705                                                                                 senses[i].getGloss() 
    706                                                                                         .replaceAll("<", "&lt;") 
    707                                                                                         .replaceAll(">", "&gt;") + 
    708                                                                                 "<br>\n"; 
    709                                                                 } 
    710                                                                  
    711                                                                 glossCell.html +=  
    712                                                                         "<input type=\"submit\" name=\"swnss\""+ 
    713                                                                         " value=\"Save\">\n" + 
    714                                                                         "</form>"; 
    715                                                         } 
    716                                                         else if (wordnetSynset == null) 
    717                                                         { 
    718                                                                 glossCell.html = "(no Wordnet sense selected)"; 
    719                                                         } 
    720                                                         else 
    721                                                         { 
    722                                                                 Synset sense = null; 
    723                                                                  
    724                                                                 for (int i = 0; i < senses.length; i++) 
    725                                                                 { 
    726                                                                         Long key = (Long)(senses[i].getKey()); 
    727                                                                         if (key.longValue() == 
    728                                                                                 wordnetSynset.longValue()) 
    729                                                                         { 
    730                                                                                 sense = senses[i]; 
    731                                                                                 break; 
    732                                                                         } 
    733                                                                 } 
    734                                                                  
    735                                                                 if (sense == null) 
    736                                                                 { 
    737                                                                         glossCell.html =  
    738                                                                                 "(invalid Wordnet sense selected)"; 
    739                                                                 } 
    740                                                                 else 
    741                                                                 { 
    742                                                                         glossCell.html = sense.getGloss(); 
    743                                                                 } 
    744                                                         } 
    745                                                          
    746                                                         if (wordnetPos != null && swnsId != wid &&  
    747                                                                 canWriteToWord) 
    748                                                         { 
    749                                                                 glossCell.html +=  
    750                                                                                 " [<a href=\"clause.jsp?swns=" + wid + 
    751                                                                                 "\">change</a>]"; 
    752                                                         } 
    753                                                 } 
    754  
    755543                                                // DiB lookup 
    756544                                                {