Changeset 259

Show
Ignore:
Timestamp:
01/05/08 15:29:23 (4 years ago)
Author:
chris
Message:

Add a context listener to try to shut everything down when the context
is removed, to try to solve/reduce memory leaks.

Add shutdown ability to Wordnet database, Emdros database pools,
ontology database.

Specify that emdros methods can throw EmdrosException?, as required
by Emdros 2.0.6.

Remove HebrewMorphemeGenerator? dependency on Emdros.

Generate word glosses from lexicon rather than ontology database
and Wordnet.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lex/trunk/.settings/org.eclipse.core.resources.prefs

    r216 r259  
    1 #Fri Dec 28 01:47:54 CET 2007 
     1#Wed Jan 02 17:36:47 CET 2008 
    22eclipse.preferences.version=1 
     3encoding//jsp/attributes.jsp=UTF-8 
    34encoding//jsp/auth.jsp=UTF-8 
    45encoding//jsp/clause.jsp=UTF-8 
     
    67encoding//jsp/dump.jsp=UTF-8 
    78encoding//jsp/error.jsp=UTF-8 
     9encoding//jsp/export.jsp=UTF-8 
     10encoding//jsp/footer.jsp=UTF-8 
    811encoding//jsp/gen-export.jsp=UTF-8 
    9 encoding//jsp/header.jsp=UTF-8 
     12encoding//jsp/header2.jsp=UTF-8 
    1013encoding//jsp/index.jsp=UTF-8 
    1114encoding//jsp/login.jsp=UTF-8 
     
    1316encoding//jsp/navclause.jsp=UTF-8 
    1417encoding//jsp/parse.jsp=UTF-8 
     18encoding//jsp/published.jsp=UTF-8 
    1519encoding//jsp/rules.jsp=UTF-8 
     20encoding//jsp/search.jsp=UTF-8 
    1621encoding/<project>=UTF-8 
  • lex/trunk/jsp/clause.jsp

    r256 r259  
    99<%@ page import="com.qwirx.lex.parser.*" %> 
    1010<%@ page import="com.qwirx.lex.morph.*" %> 
     11<%@ page import="com.qwirx.lex.lexicon.*" %> 
    1112<%@ page import="com.qwirx.crosswire.kjv.KJV" %> 
    1213<%@ page import="org.crosswire.jsword.book.*" %> 
     
    129130            } 
    130131        } 
    131          
     132 
    132133        BorderTableRenderer rend = new BorderTableRenderer(); 
    133134         
     
    157158                StringBuffer hebrewText = new StringBuffer(); 
    158159                List morphEdges = new ArrayList(); 
    159                 HebrewMorphemeGenerator generator = new HebrewMorphemeGenerator(emdros); 
     160                HebrewMorphemeGenerator generator = new HebrewMorphemeGenerator(); 
    160161                 
    161162                /* Prescan to find the predicate lexeme and populate the chart */ 
     
    272273                                                        !phrases.hasNext() && !words.hasNext()); 
    273274                                                 
    274                                         generator.parse(word, hfc, true); 
     275                                        generator.parse(word, hfc, true, sql); 
    275276                                        isFirstWord = false; 
    276277                                         
     
    460461                         
    461462                        SheafConstIterator phrases = clause.getSheaf().const_iterator(); 
    462                         while (phrases.hasNext()) { 
     463                        while (phrases.hasNext()) 
     464                        { 
    463465                                MatchedObject phrase = 
    464466                                        phrases.next().const_iterator().next(); 
     
    480482                                                words.next().const_iterator().next(); 
    481483                                        column++; 
    482                                         boolean canWriteToWord = emdros.canWriteTo(word); 
    483484                                         
    484485                                        if (type.equals("word")) 
    485486                                        { 
    486                                                 String lexeme = HebrewConverter.wordTranslitToHtml(word,  
    487                                                         generator); 
    488                                                 String part_of_speech = (String) 
    489                                                         parts_of_speech.get(word.getEMdFValue("phrase_dependent_part_of_speech") 
    490                                                                 .toString()); 
     487                                                Lexeme lexeme = Lexeme.findOrBuild(sql, word); 
     488                                                 
     489                                                String part_of_speech = word.getFeatureAsString( 
     490                                                        word.getEMdFValueIndex( 
     491                                                                "phrase_dependent_part_of_speech")); 
     492                                                boolean canWriteToWord = emdros.canWriteTo(word); 
    491493                                                         
    492494                                                Cell cell = new Cell(); 
    493                                                 cell.label = lexeme
     495                                                cell.label = lexeme.getTranslit()
    494496                                                cell.columns = 1; 
    495497                                                word_row.addElement(cell); 
    496498                                                 
    497499                                                int wid = word.getID_D(); 
    498                                                  
    499                                                 PreparedStatement stmt = sql.prepareSelect( 
    500                                                         "SELECT ID, Gloss FROM lexicon_entries "+ 
    501                                                         "WHERE Lexeme = ?"); 
    502                                                 stmt.setString(1, lexeme); 
    503                                                 ResultSet rs = sql.select(); 
    504                                                 String lexiconGloss = ""; 
    505                                                 int lexId = -1; 
    506                                                 if (rs.next())  
    507                                                 { 
    508                                                         lexId = rs.getInt(1); 
    509                                                         lexiconGloss = rs.getString(2); 
    510                                                         if (lexiconGloss == null) lexiconGloss = ""; 
    511                                                 } 
    512                                                 sql.finish(); 
    513                                                  
     500 
    514501                                                // lexicon gloss 
    515502                                                { 
     
    520507                                                                request.getParameter("ewgs") != null)  
    521508                                                        { 
    522                                                                 lexiconGloss = request.getParameter("gloss"); 
    523                                                                 Change ch; 
    524                                                                 if (lexId == -1)  
    525                                                                 { 
    526                                                                         ch = sql.createChange( 
    527                                                                                 SqlChange.INSERT, "lexicon_entries", null); 
    528                                                                         ch.setString("Lexeme", lexeme); 
    529                                                                 }  
    530                                                                 else  
    531                                                                 { 
    532                                                                         ch = sql.createChange( 
    533                                                                                 SqlChange.UPDATE, "lexicon_entries",  
    534                                                                                 "ID = "+lexId); 
    535                                                                 } 
    536                                                                 ch.setString("Gloss", lexiconGloss); 
    537                                                                 ch.execute(); 
     509                                                                lexeme.setGloss(request.getParameter("gloss")); 
     510                                                                lexeme.save(); 
     511                                                                lexeme = Lexeme.load(sql, word); 
    538512                                                                ewgId = -1; 
    539513                                                        } 
     514                                                         
     515                                                        String lexiconGloss = lexeme.getGloss(); 
    540516                                                         
    541517                                                        if (ewgId == wid)  
    542518                                                        { 
     519                                                                if (lexiconGloss == null) 
     520                                                                { 
     521                                                                        lexiconGloss = ""; 
     522                                                                } 
    543523                                                                glossCell.html = "<form method=\"post\">\n" + 
    544524                                                                        "<input type=\"hidden\" name=\"ewg\"" + 
    545525                                                                        " value=\"" + wid + "\">\n" + 
    546526                                                                        "<input name=\"gloss\" size=\"10\" value=\"" + 
    547                                                                         lexiconGloss.replaceAll("<", "&lt;") 
    548                                                                                 .replaceAll(">", "&gt;") + 
     527                                                                        HebrewConverter.toHtml(lexiconGloss) + 
    549528                                                                        "\">\n" + 
    550529                                                                        "<input type=\"submit\" name=\"ewgs\""+ 
     
    554533                                                        else  
    555534                                                        { 
     535                                                                if (lexiconGloss == null) 
     536                                                                { 
     537                                                                        lexiconGloss = "(gloss)"; 
     538                                                                } 
    556539                                                                glossCell.html = "<a href=\"clause.jsp?ewg=" +  
    557                                                                         wid + "\">" +  
    558                                                                         (lexiconGloss.equals("") ? "(gloss)" :  
    559                                                                                 lexiconGloss) + 
    560                                                                         "</a>"; 
     540                                                                        wid + "\">" + lexiconGloss + "</a>"; 
    561541                                                        } 
    562542                                                } 
  • lex/trunk/jsp/gen-export.jsp

    r257 r259  
    6868                        "attachment; filename=export.gen"); 
    6969                response.getWriter().print( 
    70                         new GenExporter(emdros).export(clause, verseData)); 
     70                        new GenExporter().export(clause, verseData, sql)); 
    7171        } 
    7272        finally 
  • lex/trunk/jsp/header2.jsp

    r247 r259  
    7878        try 
    7979        { 
    80                 emdros = Lex.getEmdrosDatabase(username, hostname); 
     80                emdros = Lex.getEmdrosDatabase(username, hostname, sql); 
    8181                int min_m = emdros.getMinM(), max_m = emdros.getMaxM(); 
    8282                int real_min_m = min_m, real_max_m = max_m; 
  • lex/trunk/jsp/navclause.jsp

    r245 r259  
    3333                } 
    3434        }  
    35          
     35 
    3636        { 
    3737                boolean foundBook = false; 
     
    8282                                if (min_m < new_min_m) min_m = new_min_m; 
    8383                                if (max_m > new_max_m) max_m = new_max_m; 
     84                                if (min_m > max_m) max_m = min_m + 1; 
    8485                                // System.out.println("book restricts to " + min_m + "-" + max_m); 
    8586                        } 
     
    170171                                int new_min_m = Integer.parseInt(monad_row.getColumn(2));        
    171172                                int new_max_m = Integer.parseInt(monad_row.getColumn(3));        
     173                                System.out.println("before chapter was " + min_m + "-" + max_m); 
    172174                                if (min_m < new_min_m) min_m = new_min_m; 
    173175                                if (max_m > new_max_m) max_m = new_max_m; 
    174                                 // System.out.println("chapter restricts to " + min_m + "-" + max_m); 
     176                                if (min_m > max_m) max_m = min_m + 1; 
     177                                System.out.println("chapter restricts to " + min_m + "-" + max_m); 
    175178                        } 
    176179                         
     
    196199<% 
    197200        int selVerseNum = 1; 
     201        System.out.println("4"); 
    198202         
    199203        { 
     
    261265<% 
    262266        int selClauseId = 0; 
     267                System.out.println("5"); 
    263268         
    264269        { 
     
    280285                boolean foundSelectedClause = false; 
    281286                int defaultClauseId = 0; 
    282                 HebrewMorphemeGenerator generator = new HebrewMorphemeGenerator(emdros); 
     287                HebrewMorphemeGenerator generator = new HebrewMorphemeGenerator(); 
    283288         
    284289                Sheaf sheaf = emdros.getSheaf 
  • lex/trunk/jsp/parse.jsp

    r239 r259  
    263263                "                    type_id, macrorole_number "+ 
    264264                "          [word GET lexeme, phrase_dependent_part_of_speech, "+ 
    265                 "                    tense, wordnet_gloss, wordnet_synset, " + 
     265                "                    tense, stem, wordnet_gloss, wordnet_synset, " + 
    266266                "                    graphical_preformative, " + 
    267267                "                    graphical_locative, " + 
     
    305305                { 
    306306                        TreeNode root = new TreeNode("root"); 
    307                         HebrewMorphemeGenerator gen = new HebrewMorphemeGenerator(emdros); 
     307                        HebrewMorphemeGenerator gen = new HebrewMorphemeGenerator(); 
    308308                         
    309309                        { 
     
    364364                                                        morphEdges); 
    365365                                                 
    366                                                 gen.parse(word, hfc, true); 
     366                                                gen.parse(word, hfc, true, sql); 
    367367                                                 
    368368                                                hebrewText.append(" ");                                          
  • lex/trunk/jsp/published.jsp

    r254 r259  
    4545                <table class="search_results"> 
    4646                        <tr> 
    47                                 <th>Reference</th> 
    4847                                <th>Verb</th> 
    4948                                <th>Logical Structure</th> 
     49                                <th>Reference</th> 
    5050                        </tr> 
    5151                <% 
     
    5757                        %> 
    5858                        <tr> 
    59                                 <td><a href="result.getLinkUrl()"><%= result.getLocation() %></a></td> 
    60                                 <td><%= HebrewConverter.toHebrew(result.getPredicate()) %></td> 
    61                                 <td><%= HebrewConverter.toHtml(result.getLogicalStructure()) %></td> 
     59                                <td><%= 
     60                                        HebrewConverter.toHebrew(result.getPredicate()) 
     61                                %></td> 
     62                                <td><%= 
     63                                        HebrewConverter.toHtml(result.getLogicalStructure()) 
     64                                %></td> 
     65                                <td><a href="<%= result.getLinkUrl() %>"><%= 
     66                                        result.getLocation() 
     67                                %></a></td> 
    6268                        </tr> 
    6369                        <% 
  • lex/trunk/jsp/WEB-INF/web.xml

    r26 r259  
    11<?xml version="1.0" encoding="ISO-8859-1"?> 
     2 
    23<!DOCTYPE web-app 
    3     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
    4     "http://java.sun.com/dtd/web-app_2_3.dtd"> 
     4  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
     5  "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd"> 
    56 
    67<web-app> 
    78        <display-name>Lex</display-name> 
    89        <description>Lex</description> 
     10 
     11        <!-- lifecycle listeners --> 
     12         
     13        <listener> 
     14            <listener-class>com.qwirx.lex.LexContextListener</listener-class> 
     15        </listener> 
    916         
    1017        <!-- Filters --> 
  • lex/trunk/src/com/qwirx/crosswire/kjv/KJV.java

    r249 r259  
    77import java.util.List; 
    88import java.util.Map; 
    9 import java.util.Set; 
    10 import java.util.TreeSet; 
    119 
    1210import jemdros.Table; 
  • lex/trunk/src/com/qwirx/db/sql/SqlDatabase.java

    r213 r259  
    3232public class SqlDatabase implements Database 
    3333{ 
    34         private Connection conn; 
     34        private Connection m_Connection; 
    3535        private PreparedStatement stmt; 
    3636        private ResultSet rs; 
     
    4242        throws DatabaseException 
    4343    { 
    44                 this.conn = conn; 
     44                this.m_Connection = conn; 
    4545                this.username = username; 
    4646                this.database = database; 
     
    8888                } 
    8989        } 
    90          
     90     
     91    public Connection getConnection() 
     92    { 
     93        return m_Connection; 
     94    } 
     95     
    9196        public void executeDirect(String sql) throws DatabaseException  
    9297    { 
     
    9499        { 
    95100            long startTime = System.currentTimeMillis(); 
    96                         PreparedStatement s = conn.prepareStatement(sql); 
     101                        PreparedStatement s = m_Connection.prepareStatement(sql); 
    97102                        s.executeUpdate(); 
    98103                        s.close(); 
     
    121126                try  
    122127        { 
    123                         stmt = conn.prepareStatement(sql); 
     128                        stmt = m_Connection.prepareStatement(sql); 
    124129                }  
    125130        catch (SQLException e)  
     
    184189        { 
    185190                return new SqlChange(username, database,  
    186                         (SqlChange.Type)type, table, (String)conditions, conn); 
     191                        (SqlChange.Type)type, table, (String)conditions, m_Connection); 
    187192        } 
    188193         
    189194        public void close() throws SQLException 
    190195        { 
    191                 conn.close(); 
     196                m_Connection.close(); 
    192197        } 
    193198         
  • lex/trunk/src/com/qwirx/lex/emdros/EmdrosDatabase.java

    r234 r259  
    1818import jemdros.BadMonadsException; 
    1919import jemdros.EmdrosEnv; 
     20import jemdros.EmdrosException; 
    2021import jemdros.FlatSheaf; 
    2122import jemdros.MatchedObject; 
     
    4647{ 
    4748        private EmdrosEnv env; 
    48         private Connection conn
     49        private Connection m_LogDatabase
    4950        private String username, userhost, database; 
    5051    private static final Logger m_LOG = Logger.getLogger(EmdrosDatabase.class); 
     
    5253        public EmdrosDatabase(String dbHost, String dbName, String dbUser, 
    5354        String dbPass, String logUser, String logFrom, Connection logDb)  
    54     throws DatabaseException 
     55    throws DatabaseException, EmdrosException 
    5556    { 
    5657        env = new EmdrosEnv(eOutputKind.kOKConsole,  
     
    6364        } 
    6465 
    65         this.conn = logDb; 
     66        m_LogDatabase = logDb; 
    6667        this.username = logUser; 
    6768        this.userhost = logUser + "@" + logFrom; 
     
    7273    { 
    7374        return env.connectionOk(); 
     75    } 
     76     
     77    public void setLogConnection(Connection logDb) 
     78    { 
     79        m_LogDatabase = logDb; 
    7480    } 
    7581     
     
    301307     
    302308    public SetOfMonads intersect(SetOfMonads set, int min_m, int max_m) 
    303     { 
     309    throws EmdrosException 
     310    { 
     311        System.out.println(set.toString()); 
     312        System.out.println(min_m + " : " + max_m); 
    304313        return SetOfMonads.intersect(set, new SetOfMonads(min_m, max_m)); 
    305314    } 
    306315     
    307316        public Change createChange(ChangeType changeType, String objectType,  
    308                         Object objectIds) throws DatabaseException 
     317                        Object objectIds) 
     318    throws DatabaseException 
    309319        { 
    310320        int [] id_ds = (int [])objectIds; 
     
    319329            } 
    320330        } 
    321         catch (DatabaseException e) 
     331        catch (Exception e) 
    322332        { 
    323333            throw new DatabaseException("Failed to determine object access", 
     
    326336         
    327337                return new EmdrosChange(username+"@"+userhost, database,  
    328                         (EmdrosChange.Type)changeType, objectType, conn, this,  
     338                        (EmdrosChange.Type)changeType, objectType, m_LogDatabase, this,  
    329339                        id_ds); 
    330340        } 
     
    394404 
    395405    public SetOfMonads getVisibleMonads() 
    396     throws SQLException 
    397     { 
    398         PreparedStatement stmt = conn.prepareStatement 
     406    throws SQLException, EmdrosException 
     407    { 
     408        PreparedStatement stmt = m_LogDatabase.prepareStatement 
    399409        ( 
    400410            "SELECT Monad_First, Monad_Last " + 
     
    437447 
    438448    public boolean canWriteTo(String objectType, int objectId) 
    439     throws DatabaseException 
     449    throws DatabaseException, EmdrosException 
    440450    { 
    441451        return canWriteTo(objectType, new int[]{objectId}); 
     
    443453     
    444454    public boolean canWriteTo(String objectType, int[] objectIds) 
    445     throws DatabaseException 
     455    throws DatabaseException, EmdrosException 
    446456    { 
    447457        String query = "GET MONADS FROM OBJECTS WITH ID_DS = "; 
     
    493503        try 
    494504        { 
    495             stmt = conn.prepareStatement(query); 
     505            stmt = m_LogDatabase.prepareStatement(query); 
    496506            stmt.setString(1, username); 
    497507            rs = stmt.executeQuery(); 
  • lex/trunk/src/com/qwirx/lex/GenExporter.java

    r220 r259  
    22 
    33import java.io.IOException; 
     4import java.sql.SQLException; 
    45 
     6import jemdros.EmdrosException; 
    57import jemdros.MatchedObject; 
    68import jemdros.SheafConstIterator; 
     
    1113 
    1214import com.qwirx.db.DatabaseException; 
    13 import com.qwirx.lex.emdros.EmdrosDatabase; 
     15import com.qwirx.db.sql.SqlDatabase; 
    1416import com.qwirx.lex.hebrew.HebrewConverter; 
    1517import com.qwirx.lex.morph.HebrewMorphemeGenerator; 
     
    1820public class GenExporter 
    1921{ 
    20     private HebrewMorphemeGenerator m_Generator; 
    21      
    22     public GenExporter(EmdrosDatabase emdros) 
    23     throws IOException, DatabaseException, SAXException 
    24     { 
    25         m_Generator = new HebrewMorphemeGenerator(emdros); 
    26     } 
    27      
    28     public String export(MatchedObject object, BookData verse) 
    29     throws IOException, BookException 
     22    public String export(MatchedObject object, BookData verse, SqlDatabase sql) 
     23    throws IOException, BookException, SAXException,  
     24        DatabaseException, SQLException, EmdrosException 
    3025    { 
    3126        StringBuffer buf = new StringBuffer(); 
     
    4439            "\n"); 
    4540         
    46         exportObject(object, verse, buf); 
     41        exportObject(object, verse, buf, sql); 
    4742         
    4843        return buf.toString(); 
     
    6358            boolean lastMorpheme, String desc, 
    6459            String morphNode) 
     60        throws EmdrosException 
    6561        { 
    6662            String raw = m_Word.getEMdFValue(surface).getString(); 
     
    8278 
    8379    private void exportObject(MatchedObject object, BookData verse, 
    84         StringBuffer buf) 
    85     throws IOException, BookException 
     80        StringBuffer buf, SqlDatabase sql) 
     81    throws IOException, BookException, SAXException, 
     82        DatabaseException, SQLException, EmdrosException 
    8683    { 
    8784        if (object.getObjectTypeName().equals("word")) 
     
    9087                new HebrewFeatureConverter(object, buf); 
    9188             
    92             m_Generator.parse(object, hfc, true); 
     89            new HebrewMorphemeGenerator().parse(object, hfc, true, sql); 
    9390        } 
    9491         
     
    9996            { 
    10097                MatchedObject child = straws.next().const_iterator().next(); 
    101                 exportObject(child, verse, buf); 
     98                exportObject(child, verse, buf, sql); 
    10299            } 
    103100        } 
  • lex/trunk/src/com/qwirx/lex/hebrew/HebrewConverter.java

    r241 r259  
    11package com.qwirx.lex.hebrew; 
    22 
    3 import java.io.IOException; 
    4  
    5 import org.xml.sax.SAXException; 
    6  
     3import jemdros.EmdrosException; 
    74import jemdros.MatchedObject; 
    85 
    9 import com.qwirx.db.DatabaseException; 
    106import com.qwirx.lex.emdros.EmdrosDatabase; 
    117import com.qwirx.lex.morph.HebrewMorphemeGenerator; 
     
    271267            String substr = input.substring(i); 
    272268            char c = input.charAt(i); 
     269             
     270            /* 
    273271            char c2 = 0xffff; 
    274272            if (i < input.length() - 1) 
     
    276274                c2 = input.charAt(i + 1); 
    277275            } 
     276            */ 
    278277 
    279278            if (substr.matches("[BGDKPT]\\.[@AEIOUW;:].*")) 
     
    382381    } 
    383382     
    384     static class Transliterator implements MorphemeHandler 
     383    public static class Transliterator implements MorphemeHandler 
    385384    { 
    386385        private MatchedObject m_Word; 
     
    393392        } 
    394393         
    395         public void convert(String surface,  
    396             boolean lastMorpheme, String desc, 
     394        public void convert(String surface, boolean lastMorpheme, String desc, 
    397395            String morphNode) 
     396        throws EmdrosException 
    398397        { 
    399398            String raw = m_Word.getEMdFValue(surface).getString(); 
     
    414413        } 
    415414         
    416         public void convert(String surface,  
    417             boolean lastMorpheme, String desc, 
     415        public void convert(String surface, boolean lastMorpheme, String desc, 
    418416            String morphNode) 
     417        throws EmdrosException 
    419418        { 
    420419            String raw = m_Word.getEMdFValue(surface).getString(); 
     
    425424 
    426425    public static String wordToHtml(MatchedObject word, EmdrosDatabase emdros) 
    427     throws IOException, DatabaseException, SAXException 
    428     { 
    429         return wordTranslitToHtml(word, new HebrewMorphemeGenerator(emdros)); 
     426    throws EmdrosException 
     427    { 
     428        return wordTranslitToHtml(word, new HebrewMorphemeGenerator()); 
    430429    } 
    431430 
    432431    public static String wordTranslitToHtml(MatchedObject word,  
    433432        HebrewMorphemeGenerator generator) 
     433    throws EmdrosException 
    434434    { 
    435435        StringBuffer out = new StringBuffer(); 
    436436        Transliterator xlit = new Transliterator(word, out); 
    437         generator.parse(word, xlit, false); 
     437        generator.parse(word, xlit, false, (String)null); 
    438438        return toHtml(out.toString()); 
    439439    } 
     
    441441    public static String wordHebrewToHtml(MatchedObject word,  
    442442        HebrewMorphemeGenerator generator) 
     443    throws EmdrosException 
    443444    { 
    444445        StringBuffer out = new StringBuffer(); 
    445446        Hebrewator xlit = new Hebrewator(word, out); 
    446         generator.parse(word, xlit, false); 
     447        generator.parse(word, xlit, false, (String)null); 
    447448        return toHtml(out.toString()); 
    448449    } 
  • lex/trunk/src/com/qwirx/lex/hebrew/HebrewEnglishDatabase.java

    r189 r259  
    159159        return m_Instance; 
    160160    } 
     161     
     162    public synchronized static void delete() 
     163    { 
     164        m_Instance = null; 
     165    } 
    161166} 
  • lex/trunk/src/com/qwirx/lex/Lex.java

    r250 r259  
    1010import java.net.URL; 
    1111import java.sql.Connection; 
    12 import java.sql.DriverManager; 
    1312import java.sql.SQLException; 
    1413import java.util.Hashtable; 
     14import java.util.Iterator; 
    1515import java.util.Map; 
     16import java.util.Properties; 
    1617import java.util.Stack; 
    1718 
     
    2021import org.xml.sax.SAXException; 
    2122 
     23import com.mysql.jdbc.Driver; 
    2224import com.qwirx.db.DatabaseException; 
    2325import com.qwirx.db.sql.DbColumn; 
     
    117119            return emdrosDb; 
    118120        } 
     121         
     122        public void clear() 
     123        { 
     124            for (Iterator<EmdrosDatabase> i = m_Pool.iterator(); i.hasNext();) 
     125            { 
     126                EmdrosDatabase db = i.next(); 
     127                db.delete(); 
     128                i.remove(); 
     129            } 
     130        } 
    119131    } 
    120132     
     
    125137 
    126138        public static final EmdrosDatabase getEmdrosDatabase(String user,  
    127         String host)  
     139        String host, SqlDatabase logDatabase)  
    128140        throws Exception  
    129141    { 
     
    140152        EmdrosDatabase db = pool.get(); 
    141153        m_Ledger.put(db, pool); 
     154        db.setLogConnection(logDatabase.getConnection()); 
    142155        return db; 
    143156        } 
     
    146159    { 
    147160        EmdrosDatabasePool pool = m_Ledger.get(db); 
     161        if (pool == null) 
     162        { 
     163            db.delete(); 
     164            return; 
     165        } 
     166         
    148167        pool.put(db); 
     168        m_Ledger.remove(db); 
     169    } 
     170     
     171    public static final void emptyPools() 
     172    { 
     173        for (Iterator<String> i = m_EmdrosPools.keySet().iterator(); 
     174            i.hasNext();) 
     175        { 
     176            String key = i.next(); 
     177            EmdrosDatabasePool pool = m_EmdrosPools.get(key); 
     178            pool.clear(); 
     179            i.remove(); 
     180        } 
    149181    } 
    150182         
     
    163195                Preloader.load(); 
    164196         
    165                 Class.forName("com.mysql.jdbc.Driver").newInstance(); 
    166  
    167197        URL url = Lex.class.getResource("/com/qwirx/crosswire/kjv"); 
    168198        assert(url != null); 
     
    185215 
    186216        String dsn = "jdbc:mysql://localhost:3306/lex?user=emdf" + 
    187             "&password=changeme&useServerPrepStmts=false"; 
     217            "&password=changeme&useServerPrepStmts=false" + 
     218            "&jdbcCompliantTruncation=false"; 
    188219        Connection dbconn; 
    189220         
    190221                try { 
    191                         dbconn = DriverManager.getConnection(dsn); 
     222                        dbconn = new Driver().connect(dsn, new Properties()); 
    192223 
    193224                        new DbTable("object_types", 
  • lex/trunk/src/com/qwirx/lex/lexicon/Lexeme.java

    r142 r259  
    1414import java.util.Vector; 
    1515 
     16import jemdros.EmdrosException; 
     17import jemdros.MatchedObject; 
     18 
    1619import com.qwirx.db.Change; 
    1720import com.qwirx.db.DatabaseException; 
    1821import com.qwirx.db.sql.SqlChange; 
    1922import com.qwirx.db.sql.SqlDatabase; 
     23import com.qwirx.lex.hebrew.HebrewConverter.Transliterator; 
     24import com.qwirx.lex.morph.HebrewMorphemeGenerator; 
    2025 
    2126public class Lexeme implements Comparable  
     
    4954     
    5055    public int    id, parentId, numSyntacticArgs; 
    51     public String label, desc, surface
     56    public String label, desc, surface, m_Gloss
    5257    public Lexeme parent; 
    5358    public List   children  = new Vector(); 
     
    229234        return true; 
    230235    } 
     236     
     237    public String getTranslit() throws EmdrosException 
     238    { 
     239        assert(m_WordObject != null); 
     240        StringBuffer out = new StringBuffer(); 
     241        Transliterator xlit = new Transliterator(m_WordObject, out); 
     242        new HebrewMorphemeGenerator().parse(m_WordObject, xlit, false,  
     243            (String)null); 
     244        return out.toString(); 
     245    } 
     246     
     247    public String getGloss() 
     248    { 
     249        return m_Gloss; 
     250    } 
     251     
     252    public void setGloss(String gloss) 
     253    { 
     254        this.m_Gloss = gloss;  
     255    } 
     256     
     257    public int getID() 
     258    { 
     259        return id; 
     260    } 
    231261 
    232262    private static Lexeme load(SqlDatabase sqldb, ResultSet rs)  
     
    237267        l.id       = rs.getInt("ID"); 
    238268        l.surface  = rs.getString("Lexeme"); 
     269        l.m_Gloss    = rs.getString("Gloss"); 
    239270        l.label    = rs.getString("Domain_Label"); 
    240271        l.desc     = rs.getString("Domain_Desc"); 
     
    261292    private static String getColumnList()  
    262293    { 
    263         return "ID,Lexeme,Structure,Domain_Label,Domain_Desc,"+ 
     294        return "ID,Lexeme,Gloss,Structure,Domain_Label,Domain_Desc,"+ 
    264295            "Domain_Parent_ID,Syntactic_Args, Caused, "+ 
    265296            "Punctual, Has_Result_State, Telic, Predicate, "+ 
     
    296327    } 
    297328     
     329    private MatchedObject m_WordObject = null; 
     330 
     331    public static Lexeme load(SqlDatabase sqldb, MatchedObject word) 
     332    throws DatabaseException, SQLException, EmdrosException 
     333    { 
     334        Lexeme result = null; 
     335         
     336        try  
     337        { 
     338            PreparedStatement stmt = sqldb.prepareSelect 
     339                ("SELECT " + getColumnList() + " " + 
     340                 "FROM lexicon_entries " + 
     341                 "WHERE Lexeme = ?"); 
     342            stmt.setString(1, word.getEMdFValue("lexeme").getString()); 
     343            ResultSet rs = sqldb.select(); 
     344             
     345            if (!rs.next())  
     346            { 
     347                return null; 
     348            } 
     349             
     350            result = load(sqldb, rs); 
     351        }  
     352        finally  
     353        { 
     354            sqldb.finish(); 
     355        } 
     356         
     357        result.m_WordObject = word; 
     358        return result; 
     359    } 
     360 
     361    public static Lexeme findOrBuild(SqlDatabase sqldb, MatchedObject word) 
     362    throws DatabaseException, SQLException, EmdrosException 
     363    { 
     364        Lexeme result = load(sqldb, word); 
     365 
     366        if (result == null) 
     367        { 
     368            result = new Lexeme(sqldb); 
     369            result.m_WordObject = word; 
     370            result.surface = word.getEMdFValue("lexeme").getString(); 
     371        } 
     372         
     373        return result; 
     374    } 
     375 
    298376    public static Lexeme getTreeRoot(SqlDatabase sqldb)  
    299377    throws DatabaseException, SQLException 
     
    358436            ch = m_sqldb.createChange(SqlChange.INSERT, "lexicon_entries",  
    359437                null); 
     438            ch.setString("Lexeme", surface); 
    360439        } 
    361440        else 
     
    365444        } 
    366445 
     446        ch.setString("Gloss",      m_Gloss); 
    367447        ch.setString("Structure",  getLogicalStructure()); 
    368448        ch.setString("Caused",     isCaused()   ? "1" : "0"); 
  • lex/trunk/src/com/qwirx/lex/morph/HebrewMorphemeGenerator.java

    r256 r259  
    11package com.qwirx.lex.morph; 
    22 
    3 import java.io.IOException; 
     3import java.sql.SQLException; 
    44import java.util.ArrayList; 
    55import java.util.Arrays; 
    66import java.util.Iterator; 
    77import java.util.List; 
    8 import java.util.Map; 
    9  
    10 import jemdros.EMdFValue; 
     8 
     9import jemdros.EmdrosException; 
    1110import jemdros.MatchedObject; 
    1211 
    13 import org.xml.sax.SAXException; 
    14  
    1512import com.qwirx.db.DatabaseException; 
    16 import com.qwirx.lex.Lex; 
    17 import com.qwirx.lex.emdros.EmdrosDatabase; 
    18 import com.qwirx.lex.ontology.OntologyDb; 
     13import com.qwirx.db.sql.SqlDatabase; 
     14import com.qwirx.lex.lexicon.Lexeme; 
    1915 
    2016public class HebrewMorphemeGenerator 
    2117{ 
    22     private static Map m_Persons, m_Genders, m_Numbers, m_States,  
    23         m_PartsOfSpeech, m_Tenses; 
    24     private OntologyDb m_Ontology; 
    25      
    26     public HebrewMorphemeGenerator(EmdrosDatabase emdros) 
    27     throws DatabaseException, IOException, SAXException 
     18    public void parse(MatchedObject word, MorphemeHandler handler, 
     19        boolean generateGloss, SqlDatabase sql) 
     20    throws SQLException, DatabaseException, EmdrosException 
    2821    { 
    29         if (m_Persons == null) 
    30         { 
    31             m_Persons = emdros.getEnumerationConstants("person_e", false); 
    32         } 
    33          
    34         if (m_Genders == null) 
    35         { 
    36             m_Genders = emdros.getEnumerationConstants("gender_e", false); 
    37         } 
    38          
    39         if (m_Numbers == null) 
    40         { 
    41             m_Numbers = emdros.getEnumerationConstants("number_e", false); 
    42         } 
    43          
    44         if (m_States == null) 
    45         { 
    46             m_States = emdros.getEnumerationConstants("state_e", false); 
    47         } 
    48          
    49         if (m_PartsOfSpeech == null) 
    50         { 
    51             m_PartsOfSpeech = emdros.getEnumerationConstants("part_of_speech_e", 
    52                 false); 
    53         } 
    54  
    55         if (m_Tenses == null) 
    56         { 
    57             m_Tenses = emdros.getEnumerationConstants("tense_e", false); 
    58         } 
    59  
    60         /* 
    61         if (m_Stems == null) 
    62         { 
    63             m_Stems = emdros.getEnumerationConstants("verbal_stem_t", false); 
    64              
    65         } 
    66         */ 
    67  
    68         if (m_Ontology == null) 
    69         { 
    70             m_Ontology = Lex.getOntologyDb(); 
    71         } 
     22        String gloss = null; 
     23         
     24        if (generateGloss) 
     25        { 
     26            Lexeme lexeme = Lexeme.load(sql, word); 
     27            if (lexeme != null) 
     28            { 
     29                gloss = lexeme.getGloss(); 
     30            } 
     31        } 
     32         
     33        parse(word, handler, generateGloss, gloss); 
    7234    } 
    7335     
    7436    public void parse(MatchedObject word, MorphemeHandler handler, 
    75         boolean generateGloss) 
     37        boolean generateGloss, String gloss) 
     38    throws EmdrosException 
    7639    { 
    7740        if (!word.getObjectTypeName().equals("word")) 
     
    11578        } 
    11679         
    117         EMdFValue pspValue = word.getEMdFValue("phrase_dependent_part_of_speech"); 
    118         String pspCode = pspValue.toString(); 
    119         String psp = (String)m_PartsOfSpeech.get(pspCode); 
     80        String psp = word.getFeatureAsString( 
     81            word.getEMdFValueIndex("phrase_dependent_part_of_speech")); 
    12082        
    121         String gloss = null; 
    12283        String verbEnding = null; 
    12384        String nounEnding = null;  
     
    12586        if (generateGloss) 
    12687        { 
    127             String person = (String)m_Persons.get
    128                 word.getEMdFValue("person").toString()); 
     88            String person = word.getFeatureAsString
     89                word.getEMdFValueIndex("person")); 
    12990            if      (person.equals("first_person"))  person = "1"; 
    13091            else if (person.equals("second_person")) person = "2"; 
     
    153114            } 
    154115             
    155             String state = (String)m_States.get
    156                 word.getEMdFValue("state").toString()); 
     116            String state = word.getFeatureAsString
     117                word.getEMdFValueIndex("state")); 
    157118            if      (state.equals("construct")) { state = "CS"; } 
    158119            else if (state.equals("absolute"))  { state = "AB"; } 
    159              
    160             gloss = word.getEMdFValue("wordnet_gloss").getString(); 
    161              
    162             if (gloss.equals("")) 
    163             { 
    164                 String lexeme = word.getEMdFValue("lexeme") 
    165                     .getString(); 
    166                      
    167                 OntologyDb.OntologyEntry entry =  
    168                     m_Ontology.getWordByLexeme(lexeme); 
    169                      
    170                 if (entry != null) 
    171                 { 
    172                     gloss = entry.m_EnglishGloss; 
    173                 } 
    174                 else 
    175                 { 
    176                     gloss = null; 
    177                 } 
    178             } 
    179120             
    180121            verbEnding = person + gender + number; 
  • lex/trunk/src/com/qwirx/lex/morph/MorphemeHandler.java

    r79 r259  
    11package com.qwirx.lex.morph; 
     2 
     3import jemdros.EmdrosException; 
    24 
    35public interface MorphemeHandler 
    46{ 
    5     public void convert(String surface,  
    6         boolean lastMorpheme, String desc, 
    7         String morphNode)
     7    public void convert(String surface, boolean lastMorpheme, String desc, 
     8        String morphNode) 
     9    throws EmdrosException
    810} 
  • lex/trunk/src/com/qwirx/lex/ontology/OntologyDb.java

    r208 r259  
    4343    private static OntologyDb m_Instance = null; 
    4444     
    45     public static OntologyDb getInstance() throws IOException, SAXException 
     45    public synchronized static OntologyDb getInstance() 
     46    throws IOException, SAXException 
    4647    { 
    4748        if (m_Instance == null) 
     
    5152         
    5253        return m_Instance; 
     54    } 
     55     
     56    public synchronized static void delete() 
     57    { 
     58        m_Instance = null; 
    5359    } 
    5460         
  • lex/trunk/src/com/qwirx/lex/parser/MorphEdge.java

    r220 r259  
    153153    public String getHtmlSurface() 
    154154    { 
    155         return HebrewConverter.toHtml(m_Surface)
     155        return m_Surface
    156156    } 
    157157     
  • lex/trunk/src/com/qwirx/lex/Search.java

    r248 r259  
    11package com.qwirx.lex; 
    22 
    3 import java.io.IOException; 
    43import java.sql.SQLException; 
    54import java.util.ArrayList; 
     
    98import java.util.Map; 
    109 
     10import jemdros.EmdrosException; 
    1111import jemdros.FlatSheaf; 
    1212import jemdros.FlatSheafConstIterator; 
     
    2424import jemdros.TableRow; 
    2525 
    26 import org.xml.sax.SAXException; 
    27  
    2826import com.qwirx.db.DatabaseException; 
    2927import com.qwirx.lex.emdros.EmdrosDatabase; 
     
    5856     
    5957    public List<SearchResult> basic(String query)  
    60     throws DatabaseException, IOException, SAXException, SQLException, 
    61         TableException 
     58    throws DatabaseException, SQLException, TableException, EmdrosException 
    6259    { 
    6360        return advanced("[word " + 
     
    6865     
    6966    private void addToMonadSet(Sheaf sheaf, SetOfMonads set) 
     67    throws EmdrosException 
    7068    { 
    7169        if (sheaf == null) 
     
    9088     
    9189    public List<SearchResult> advanced(String query)  
    92     throws DatabaseException, IOException, SAXException, SQLException, 
    93         TableException 
     90    throws DatabaseException, SQLException, TableException, EmdrosException 
    9491    {     
    9592        HebrewMorphemeGenerator generator =  
    96             new HebrewMorphemeGenerator(m_Emdros); 
     93            new HebrewMorphemeGenerator(); 
    9794         
    9895        Sheaf sheaf = m_Emdros.getSheaf 
     
    124121            while (clause_iter.hasNext()) 
    125122            { 
     123                MatchedObject clause = 
     124                    clause_iter.next().const_iterator().next(); 
     125 
    126126                m_ResultCount++; 
    127127                if (m_ResultCount > m_MaxResults) continue; // just count them 
    128128                 
    129                 MatchedObject clause = 
    130                     clause_iter.next().const_iterator().next(); 
    131129                ResultBase base = new ResultBase(); 
    132130                base.monads = clause.getMonads(); 
  • lex/trunk/src/com/qwirx/lex/wordnet/Wordnet.java

    r26 r259  
    1919    private static Wordnet ms_Instance; 
    2020     
    21     public static Wordnet getInstance() throws IOException, JWNLException 
     21    public synchronized static Wordnet getInstance() 
     22    throws IOException, JWNLException 
    2223    { 
    2324        if (ms_Instance == null) 
     
    2728         
    2829        return ms_Instance; 
     30    } 
     31     
     32    public synchronized static void delete() 
     33    { 
     34        ms_Instance = null; 
     35        JWNL.shutdown(); 
    2936    } 
    3037     
  • lex/trunk/test/com/qwirx/lex/EmdrosDatabaseTest.java

    r190 r259  
    1111import java.util.Iterator; 
    1212 
     13import jemdros.EmdrosException; 
    1314import jemdros.Table; 
    1415import jemdros.TableIterator; 
     
    4041    { 
    4142                logDb  = Lex.getSqlDatabase("test"); 
    42                 emdros = Lex.getEmdrosDatabase("test", "localhost"); 
     43                emdros = Lex.getEmdrosDatabase("test", "localhost", logDb); 
    4344        } 
    4445         
     
    137138        public void checkCurrentValues(int objectID_D, String objectType,  
    138139                        ChangedRow cr)  
    139         throws DatabaseException  
     140        throws DatabaseException, EmdrosException 
    140141        { 
    141142                StringBuffer query = new StringBuffer("GET FEATURES "); 
  • lex/trunk/test/com/qwirx/lex/GenExporterTest.java

    r257 r259  
    127127    public void testGenExportCode() throws Exception 
    128128    { 
    129         EmdrosDatabase emdros = Lex.getEmdrosDatabase("test", "localhost"); 
     129        EmdrosDatabase emdros = Lex.getEmdrosDatabase("test", "localhost", 
     130            Lex.getSqlDatabase("test")); 
    130131         
    131132        Sheaf sheaf = emdros.getSheaf 
     
    156157 
    157158        assertEquals(NEHEMIAH_2_11b_EXPORT,  
    158             new GenExporter(emdros).export(clause, verse)); 
     159            new GenExporter().export(clause, verse, Lex.getSqlDatabase("test"))); 
    159160    } 
    160161     
     
    173174    public void testCrashJavaWithGetStringOnFeature2() throws Exception 
    174175    { 
    175         EmdrosDatabase emdros = Lex.getEmdrosDatabase("test", "localhost"); 
     176        EmdrosDatabase emdros = Lex.getEmdrosDatabase("test", "localhost", 
     177            Lex.getSqlDatabase("test")); 
    176178         
    177179        Sheaf sheaf = emdros.getSheaf 
  • lex/trunk/test/com/qwirx/lex/JswordExamples.java

    r251 r259  
    9494        SwordBookPath.setAugmentPath(files); 
    9595         
    96         m_Emdros = Lex.getEmdrosDatabase("test", "localhost"); 
     96        m_Emdros = Lex.getEmdrosDatabase("test", "localhost",  
     97            Lex.getSqlDatabase("test")); 
    9798    } 
    9899     
  • lex/trunk/test/com/qwirx/lex/LexemeTest.java

    r190 r259  
    99import java.util.Vector; 
    1010 
     11import jemdros.EmdrosException; 
    1112import jemdros.MatchedObject; 
    1213import jemdros.Sheaf; 
     
    3940        super(name); 
    4041        sql    = Lex.getSqlDatabase   ("test"); 
    41         emdros = Lex.getEmdrosDatabase("test", "localhost"); 
     42        emdros = Lex.getEmdrosDatabase("test", "localhost", sql); 
    4243    } 
    4344     
     
    384385     
    385386    private String getEvaluatedLogicalStructure(int emdrosClauseId) 
    386     throws DatabaseException 
     387    throws DatabaseException, EmdrosException 
    387388    { 
    388389        Sheaf sheaf = emdros.getSheaf 
  • lex/trunk/test/com/qwirx/lex/SearchTest.java

    r236 r259  
    99import jemdros.SheafConstIterator; 
    1010import jemdros.Straw; 
    11 import jemdros.StrawConstIterator; 
    1211import junit.framework.TestCase; 
    1312 
     
    2827    public void setUp() throws Exception 
    2928    { 
    30         m_Emdros = Lex.getEmdrosDatabase("chris", "test"); 
     29        m_Emdros = Lex.getEmdrosDatabase("chris", "test", 
     30            Lex.getSqlDatabase("test")); 
    3131    } 
    3232     
     
    5858        Iterator<SearchResult> actualIterator = actualResults.iterator(); 
    5959         
    60         HebrewMorphemeGenerator generator =  
    61             new HebrewMorphemeGenerator(m_Emdros); 
     60        HebrewMorphemeGenerator generator = new HebrewMorphemeGenerator(); 
    6261         
    6362        Sheaf sheaf = m_Emdros.getSheaf 
     
    8180        while (sci.hasNext()) 
    8281        { 
     82            Straw straw = sci.next(); 
     83 
    8384            count++; 
    8485            if (count > limit) continue; 
    8586 
    86             Straw straw = sci.next(); 
    8787            MatchedObject clause = straw.const_iterator().next(); 
    8888            clauses.add(new Integer(clause.getID_D())); 
     
    254254        i.assertSimple("a", "Databases",  
    255255            new Attributes().clazz("db_jsp").href(null)); 
    256         i.assertSimple("a", "Text",  
     256        i.assertSimple("a", "Published",  
     257            new Attributes().clazz("published_jsp").href("published.jsp")); 
     258        i.assertSimple("a", "Browse",  
    257259            new Attributes().clazz("clause_jsp").href("clause.jsp")); 
    258260        i.assertSimple("a", "Search",