Changeset 60

Show
Ignore:
Timestamp:
01/02/07 14:19:45 (2 years ago)
Author:
chris
Message:

- Display parse tree in browser

Files:

Legend:

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

    r50 r60  
    66<%@ page import="com.qwirx.lex.ontology.*" %> 
    77<%@ page import="com.qwirx.lex.wordnet.*" %> 
     8<%@ page import="com.qwirx.lex.parser.*" %> 
    89<%@ page import="net.didion.jwnl.data.POS" %> 
    910<%@ page import="net.didion.jwnl.data.Synset" %> 
     
    171172        } 
    172173         
     174        BorderTableRenderer rend = new BorderTableRenderer(); 
     175         
    173176        MatchedObject clause = null; 
    174177        { 
     
    195198                String predicate_text = ""; 
    196199                StringBuffer hebrewText = new StringBuffer(); 
    197                  
    198                 /* Prescan to find the predicate lexeme */ 
     200                List morphEdges = new ArrayList(); 
     201                 
     202                /* Prescan to find the predicate lexeme and populate the chart */ 
    199203                 
    200204                { 
     
    239243                                                                boolean lastMorpheme, String desc) 
    240244                                                        { 
    241                                                                 String raw = m_word.getEMdFValue(surface).getString(); 
     245                                                                String raw = m_word.getEMdFValue(surface).getString(); 
    242246 
    243247                                                                String hebrew = HebrewConverter.toHebrew(raw); 
     
    307311                                                        hfc.convert("graphical_verbal_ending", true, 
    308312                                                                person + gender + number); 
     313                                                                 
     314                                                        morphEdges.add(new MorphEdge("V/TNS", word 
     315                                                                .getEMdFValue("graphical_preformative") 
     316                                                                .getString(), morphEdges.size())); 
     317                                                        morphEdges.add(new MorphEdge("V/STM", word 
     318                                                                .getEMdFValue("graphical_root_formation") 
     319                                                                .getString(), morphEdges.size())); 
     320                                                        morphEdges.add(new MorphEdge("V/LEX", word 
     321                                                                .getEMdFValue("graphical_lexeme") 
     322                                                                .getString(), morphEdges.size())); 
     323                                                        morphEdges.add(new MorphEdge("V/PGN", word 
     324                                                                .getEMdFValue("graphical_verbal_ending") 
     325                                                                .getString(), morphEdges.size())); 
    309326                                                } 
    310327                                                else if (psp.equals("noun") 
     
    314331                                                        hfc.convert("graphical_nominal_ending", true, 
    315332                                                                gender + number + "." + state); 
     333 
     334                                                        String type = "HEAD/NCOM"; 
     335                                                        if (psp.equals("proper_noun")) 
     336                                                        { 
     337                                                                type = "HEAD/NPROP"; 
     338                                                        } 
     339                                                         
     340                                                        morphEdges.add(new MorphEdge(type, word 
     341                                                                .getEMdFValue("graphical_lexeme") 
     342                                                                .getString(), morphEdges.size())); 
     343                                                        morphEdges.add(new MorphEdge("MARK/N", word 
     344                                                                .getEMdFValue("graphical_nominal_ending") 
     345                                                                .getString(), morphEdges.size())); 
    316346                                                } 
    317347                                                else 
    318348                                                { 
    319349                                                        hfc.convert("graphical_lexeme", true, psp); 
     350                                                         
     351                                                        String type; 
     352                                                        if (psp.equals("adjective")) 
     353                                                        { 
     354                                                                type = "ADJ"; 
     355                                                        } 
     356                                                        else if (psp.equals("adverb")) 
     357                                                        { 
     358                                                                type = "ADV"; 
     359                                                        } 
     360                                                        else if (psp.equals("article")) 
     361                                                        { 
     362                                                                type = "DET"; 
     363                                                        } 
     364                                                        else if (psp.equals("conjunction")) 
     365                                                        { 
     366                                                                type = "CONJ"; 
     367                                                        } 
     368                                                        else if (psp.equals("demonstrative_pronoun")) 
     369                                                        { 
     370                                                                type = "PRON/DEM"; 
     371                                                        } 
     372                                                        else if (psp.equals("interjection")) 
     373                                                        { 
     374                                                                type = "INTJ"; 
     375                                                        } 
     376                                                        else if (psp.equals("interrogative")) 
     377                                                        { 
     378                                                                type = "INTR"; 
     379                                                        } 
     380                                                        else if (psp.equals("interrogative_pronoun")) 
     381                                                        { 
     382                                                                type = "PRON/INT"; 
     383                                                        } 
     384                                                        else if (psp.equals("negative")) 
     385                                                        { 
     386                                                                type = "NEG"; 
     387                                                        } 
     388                                                        else if (psp.equals("personal_pronoun")) 
     389                                                        { 
     390                                                                type = "PRON/PERS"; 
     391                                                        } 
     392                                                        else if (psp.equals("preposition")) 
     393                                                        { 
     394                                                                type = "P"; 
     395                                                        } 
     396                                                        else 
     397                                                        { 
     398                                                                throw new IllegalArgumentException("Unknown " + 
     399                                                                        "part of speech: " + psp); 
     400                                                        } 
     401                                                         
     402                                                        morphEdges.add(new MorphEdge(type, word 
     403                                                                .getEMdFValue("graphical_lexeme") 
     404                                                                .getString(), morphEdges.size())); 
    320405                                                }        
    321406                                                 
     
    336421                        %></span></p><% 
    337422         
    338                         %><%= root.toHtml(new BorderTableRenderer()) %><% 
     423                        %><%= root.toHtml(rend) %><% 
    339424                } 
    340425                         
     
    11461231                </table> 
    11471232                </p> 
     1233         
     1234                <% 
     1235                 
     1236                { 
     1237                        Parser p = new Parser(sql); 
     1238                        p.setVerbose(true); 
     1239                        List sentences = p.parseFor(morphEdges, "SENTENCE"); 
     1240                         
     1241                        if (sentences.size() == 0) 
     1242                        { 
     1243                                %> 
     1244                <p> 
     1245                        Parse failed. Click  
     1246                        <a href="parsedebug.jsp?clause=<%= clauseId %>">here</a> 
     1247                        to fix it. 
     1248                </p>  
     1249                                <% 
     1250                        } 
     1251                        else 
     1252                        { 
     1253                                for (int i = 0; i < sentences.size() && i < 3; i++) 
     1254                                { 
     1255                                        Edge sentence = (Edge)( sentences.get(i) ); 
     1256                                         
     1257                                        %><%= sentence.toTree().toHtml(rend) %><% 
     1258                                } 
     1259                                 
     1260                                %><p> 
     1261                                Click  
     1262                                <a href="parsedebug.jsp?clause=<%= clauseId %>">here</a> 
     1263                                to see and edit all <%= sentences.size() %> parses. 
     1264                                </p><% 
     1265                        } 
     1266                } 
     1267                 
     1268                %> 
    11481269 
    11491270                <p> 
     
    13291450                } 
    13301451        } 
    1331  
    1332         TreeNode clauseNode  = new TreeNode("Clause"); 
    1333         TreeNode coreNode    = null; 
    1334         TreeNode nucleusNode = null; 
    1335         TreeNode leftPeripheryNode  = null; 
    1336         TreeNode rightPeripheryNode = null; 
    1337  
    1338         SheafConstIterator phrases = null; 
    1339          
    1340         if (clause != null) 
    1341         { 
    1342                 phrases = clause.getSheaf().const_iterator(); 
    1343         } 
    1344          
    1345         while (phrases != null && phrases.hasNext())  
    1346         { 
    1347                 MatchedObject phrase = 
    1348                         phrases.next().const_iterator().next(); 
    1349  
    1350                 String function_name = (String)( phrase_functions.get( 
    1351                         phrase.getEMdFValue("function").toString()) 
    1352                 ); 
    1353  
    1354                 String phrase_type = (String)( phrase_types.get( 
    1355                         phrase.getEMdFValue("phrase_type").toString()) 
    1356                 ); 
    1357                  
    1358                 TreeNode phraseNode = new TreeNode(phrase_type); 
    1359                 TreeNode phraseFunc = phraseNode.createChild(function_name); 
    1360                  
    1361                 SheafConstIterator words = phrase.getSheaf().const_iterator(); 
    1362                 while (words.hasNext())  
    1363                 { 
    1364                         MatchedObject word = 
    1365                                 words.next().const_iterator().next(); 
    1366                          
    1367                         String lexeme =  
    1368                                 word.getEMdFValue("lexeme").getString() 
    1369                                 .replaceAll("<", "&lt;") 
    1370                                 .replaceAll(">", "&gt;"); 
    1371                          
    1372                         TreeNode wordNode = phraseFunc.createChild(lexeme); 
    1373                 } 
    1374          
    1375                 if (phrase_type.equals("VP") && nucleusNode == null) 
    1376                 { 
    1377                         if (coreNode == null) 
    1378                         { 
    1379                                 coreNode = clauseNode.createChild("Core"); 
    1380                         } 
    1381                          
    1382                         nucleusNode = coreNode.createChild("Nucleus"); 
    1383                         nucleusNode.add(phraseNode); 
    1384                 } 
    1385                 else if (phrase_type.equals("NP") || 
    1386                                  phrase_type.equals("IrPronNP") || 
    1387                                  phrase_type.equals("PersPronNP") || 
    1388                                  phrase_type.equals("DemPronNP") || 
    1389                                  phrase_type.equals("PropNP") || 
    1390                                  (phrase_type.equals("PP") && ! function_name.equals("Time"))) 
    1391                 { 
    1392                         if (coreNode == null) 
    1393                         { 
    1394                                 coreNode = clauseNode.createChild("Core"); 
    1395                         } 
    1396                          
    1397                         TreeNode argument = coreNode.createChild("Argument"); 
    1398                         argument.add(phraseNode); 
    1399                 } 
    1400                 else 
    1401                 { 
    1402                         TreeNode periphery; 
    1403                          
    1404                         if (coreNode == null) 
    1405                         { 
    1406                                 if (leftPeripheryNode == null) 
    1407                                 { 
    1408                                         leftPeripheryNode = clauseNode.createChild("Periphery"); 
    1409                                 } 
    1410                                 periphery = leftPeripheryNode; 
    1411                         } 
    1412                         else 
    1413                         { 
    1414                                 if (rightPeripheryNode == null) 
    1415                                 { 
    1416                                         rightPeripheryNode = clauseNode.createChild("Periphery"); 
    1417                                 } 
    1418                                 periphery = rightPeripheryNode; 
    1419                         } 
    1420                          
    1421                         TreeNode other = periphery.createChild(""); 
    1422                         other.add(phraseNode); 
    1423                 } 
    1424         } 
    14251452         
    14261453%> 
    1427  
    1428 <%= clauseNode.toHtml(new BorderTableRenderer()) %> 
    14291454 
    14301455<h2>Notes</h2> 
  • lex/trunk/src/com/qwirx/lex/parser/MorphEdge.java

    r57 r60  
    104104    public TreeNode toTree() 
    105105    { 
    106         TreeNode morph = new TreeNode(m_Symbol); 
     106        String label = m_Symbol.replaceAll("/(.*)", "<sub>$1</sub>"); 
     107        TreeNode morph = new TreeNode(label); 
     108 
    107109        morph.createChild(HebrewConverter.toHtml( 
    108110            HebrewConverter.toTranslit(m_Surface))); 
     111         
    109112        return morph; 
    110113    } 
  • lex/trunk/src/com/qwirx/lex/parser/RuleEdge.java

    r57 r60  
    388388    public TreeNode toTree() 
    389389    { 
    390         TreeNode mine = new TreeNode(symbol()); 
     390        String label = symbol(); 
     391        label = label.replaceAll("/(.*)", "<sub>$1</sub>"); 
     392        TreeNode mine = new TreeNode(label); 
     393         
    391394        for (int i = 0; i < parts.length; i++) 
    392395        { 
    393396            mine.add(parts[i].toTree()); 
    394397        } 
     398         
    395399        return mine; 
    396400    }