Changeset 259
- Timestamp:
- 01/05/08 15:29:23 (4 years ago)
- Files:
-
- lex/trunk/.settings/org.eclipse.core.resources.prefs (modified) (3 diffs)
- lex/trunk/jsp/clause.jsp (modified) (8 diffs)
- lex/trunk/jsp/gen-export.jsp (modified) (1 diff)
- lex/trunk/jsp/header.jsp (deleted)
- lex/trunk/jsp/header2.jsp (modified) (1 diff)
- lex/trunk/jsp/navclause.jsp (modified) (6 diffs)
- lex/trunk/jsp/parse.jsp (modified) (3 diffs)
- lex/trunk/jsp/published.jsp (modified) (2 diffs)
- lex/trunk/jsp/WEB-INF/web.xml (modified) (1 diff)
- lex/trunk/src/com/qwirx/crosswire/kjv/KJV.java (modified) (1 diff)
- lex/trunk/src/com/qwirx/db/sql/SqlDatabase.java (modified) (6 diffs)
- lex/trunk/src/com/qwirx/lex/emdros/EmdrosDatabase.java (modified) (12 diffs)
- lex/trunk/src/com/qwirx/lex/GenExporter.java (modified) (8 diffs)
- lex/trunk/src/com/qwirx/lex/hebrew/HebrewConverter.java (modified) (8 diffs)
- lex/trunk/src/com/qwirx/lex/hebrew/HebrewEnglishDatabase.java (modified) (1 diff)
- lex/trunk/src/com/qwirx/lex/Lex.java (modified) (8 diffs)
- lex/trunk/src/com/qwirx/lex/LexContextListener.java (added)
- lex/trunk/src/com/qwirx/lex/lexicon/Lexeme.java (modified) (8 diffs)
- lex/trunk/src/com/qwirx/lex/morph/HebrewMorphemeGenerator.java (modified) (4 diffs)
- lex/trunk/src/com/qwirx/lex/morph/MorphemeHandler.java (modified) (1 diff)
- lex/trunk/src/com/qwirx/lex/ontology/OntologyDb.java (modified) (2 diffs)
- lex/trunk/src/com/qwirx/lex/parser/MorphEdge.java (modified) (1 diff)
- lex/trunk/src/com/qwirx/lex/Search.java (modified) (7 diffs)
- lex/trunk/src/com/qwirx/lex/wordnet/Wordnet.java (modified) (2 diffs)
- lex/trunk/test/com/qwirx/lex/EmdrosDatabaseTest.java (modified) (3 diffs)
- lex/trunk/test/com/qwirx/lex/GenExporterTest.java (modified) (3 diffs)
- lex/trunk/test/com/qwirx/lex/JswordExamples.java (modified) (1 diff)
- lex/trunk/test/com/qwirx/lex/LexemeTest.java (modified) (3 diffs)
- lex/trunk/test/com/qwirx/lex/SearchTest.java (modified) (5 diffs)
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 20071 #Wed Jan 02 17:36:47 CET 2008 2 2 eclipse.preferences.version=1 3 encoding//jsp/attributes.jsp=UTF-8 3 4 encoding//jsp/auth.jsp=UTF-8 4 5 encoding//jsp/clause.jsp=UTF-8 … … 6 7 encoding//jsp/dump.jsp=UTF-8 7 8 encoding//jsp/error.jsp=UTF-8 9 encoding//jsp/export.jsp=UTF-8 10 encoding//jsp/footer.jsp=UTF-8 8 11 encoding//jsp/gen-export.jsp=UTF-8 9 encoding//jsp/header .jsp=UTF-812 encoding//jsp/header2.jsp=UTF-8 10 13 encoding//jsp/index.jsp=UTF-8 11 14 encoding//jsp/login.jsp=UTF-8 … … 13 16 encoding//jsp/navclause.jsp=UTF-8 14 17 encoding//jsp/parse.jsp=UTF-8 18 encoding//jsp/published.jsp=UTF-8 15 19 encoding//jsp/rules.jsp=UTF-8 20 encoding//jsp/search.jsp=UTF-8 16 21 encoding/<project>=UTF-8 lex/trunk/jsp/clause.jsp
r256 r259 9 9 <%@ page import="com.qwirx.lex.parser.*" %> 10 10 <%@ page import="com.qwirx.lex.morph.*" %> 11 <%@ page import="com.qwirx.lex.lexicon.*" %> 11 12 <%@ page import="com.qwirx.crosswire.kjv.KJV" %> 12 13 <%@ page import="org.crosswire.jsword.book.*" %> … … 129 130 } 130 131 } 131 132 132 133 BorderTableRenderer rend = new BorderTableRenderer(); 133 134 … … 157 158 StringBuffer hebrewText = new StringBuffer(); 158 159 List morphEdges = new ArrayList(); 159 HebrewMorphemeGenerator generator = new HebrewMorphemeGenerator( emdros);160 HebrewMorphemeGenerator generator = new HebrewMorphemeGenerator(); 160 161 161 162 /* Prescan to find the predicate lexeme and populate the chart */ … … 272 273 !phrases.hasNext() && !words.hasNext()); 273 274 274 generator.parse(word, hfc, true );275 generator.parse(word, hfc, true, sql); 275 276 isFirstWord = false; 276 277 … … 460 461 461 462 SheafConstIterator phrases = clause.getSheaf().const_iterator(); 462 while (phrases.hasNext()) { 463 while (phrases.hasNext()) 464 { 463 465 MatchedObject phrase = 464 466 phrases.next().const_iterator().next(); … … 480 482 words.next().const_iterator().next(); 481 483 column++; 482 boolean canWriteToWord = emdros.canWriteTo(word);483 484 484 485 if (type.equals("word")) 485 486 { 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); 491 493 492 494 Cell cell = new Cell(); 493 cell.label = lexeme ;495 cell.label = lexeme.getTranslit(); 494 496 cell.columns = 1; 495 497 word_row.addElement(cell); 496 498 497 499 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 514 501 // lexicon gloss 515 502 { … … 520 507 request.getParameter("ewgs") != null) 521 508 { 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); 538 512 ewgId = -1; 539 513 } 514 515 String lexiconGloss = lexeme.getGloss(); 540 516 541 517 if (ewgId == wid) 542 518 { 519 if (lexiconGloss == null) 520 { 521 lexiconGloss = ""; 522 } 543 523 glossCell.html = "<form method=\"post\">\n" + 544 524 "<input type=\"hidden\" name=\"ewg\"" + 545 525 " value=\"" + wid + "\">\n" + 546 526 "<input name=\"gloss\" size=\"10\" value=\"" + 547 lexiconGloss.replaceAll("<", "<") 548 .replaceAll(">", ">") + 527 HebrewConverter.toHtml(lexiconGloss) + 549 528 "\">\n" + 550 529 "<input type=\"submit\" name=\"ewgs\""+ … … 554 533 else 555 534 { 535 if (lexiconGloss == null) 536 { 537 lexiconGloss = "(gloss)"; 538 } 556 539 glossCell.html = "<a href=\"clause.jsp?ewg=" + 557 wid + "\">" + 558 (lexiconGloss.equals("") ? "(gloss)" : 559 lexiconGloss) + 560 "</a>"; 540 wid + "\">" + lexiconGloss + "</a>"; 561 541 } 562 542 } lex/trunk/jsp/gen-export.jsp
r257 r259 68 68 "attachment; filename=export.gen"); 69 69 response.getWriter().print( 70 new GenExporter( emdros).export(clause, verseData));70 new GenExporter().export(clause, verseData, sql)); 71 71 } 72 72 finally lex/trunk/jsp/header2.jsp
r247 r259 78 78 try 79 79 { 80 emdros = Lex.getEmdrosDatabase(username, hostname );80 emdros = Lex.getEmdrosDatabase(username, hostname, sql); 81 81 int min_m = emdros.getMinM(), max_m = emdros.getMaxM(); 82 82 int real_min_m = min_m, real_max_m = max_m; lex/trunk/jsp/navclause.jsp
r245 r259 33 33 } 34 34 } 35 35 36 36 { 37 37 boolean foundBook = false; … … 82 82 if (min_m < new_min_m) min_m = new_min_m; 83 83 if (max_m > new_max_m) max_m = new_max_m; 84 if (min_m > max_m) max_m = min_m + 1; 84 85 // System.out.println("book restricts to " + min_m + "-" + max_m); 85 86 } … … 170 171 int new_min_m = Integer.parseInt(monad_row.getColumn(2)); 171 172 int new_max_m = Integer.parseInt(monad_row.getColumn(3)); 173 System.out.println("before chapter was " + min_m + "-" + max_m); 172 174 if (min_m < new_min_m) min_m = new_min_m; 173 175 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); 175 178 } 176 179 … … 196 199 <% 197 200 int selVerseNum = 1; 201 System.out.println("4"); 198 202 199 203 { … … 261 265 <% 262 266 int selClauseId = 0; 267 System.out.println("5"); 263 268 264 269 { … … 280 285 boolean foundSelectedClause = false; 281 286 int defaultClauseId = 0; 282 HebrewMorphemeGenerator generator = new HebrewMorphemeGenerator( emdros);287 HebrewMorphemeGenerator generator = new HebrewMorphemeGenerator(); 283 288 284 289 Sheaf sheaf = emdros.getSheaf lex/trunk/jsp/parse.jsp
r239 r259 263 263 " type_id, macrorole_number "+ 264 264 " [word GET lexeme, phrase_dependent_part_of_speech, "+ 265 " tense, wordnet_gloss, wordnet_synset, " +265 " tense, stem, wordnet_gloss, wordnet_synset, " + 266 266 " graphical_preformative, " + 267 267 " graphical_locative, " + … … 305 305 { 306 306 TreeNode root = new TreeNode("root"); 307 HebrewMorphemeGenerator gen = new HebrewMorphemeGenerator( emdros);307 HebrewMorphemeGenerator gen = new HebrewMorphemeGenerator(); 308 308 309 309 { … … 364 364 morphEdges); 365 365 366 gen.parse(word, hfc, true );366 gen.parse(word, hfc, true, sql); 367 367 368 368 hebrewText.append(" "); lex/trunk/jsp/published.jsp
r254 r259 45 45 <table class="search_results"> 46 46 <tr> 47 <th>Reference</th>48 47 <th>Verb</th> 49 48 <th>Logical Structure</th> 49 <th>Reference</th> 50 50 </tr> 51 51 <% … … 57 57 %> 58 58 <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> 62 68 </tr> 63 69 <% lex/trunk/jsp/WEB-INF/web.xml
r26 r259 1 1 <?xml version="1.0" encoding="ISO-8859-1"?> 2 2 3 <!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"> 5 6 6 7 <web-app> 7 8 <display-name>Lex</display-name> 8 9 <description>Lex</description> 10 11 <!-- lifecycle listeners --> 12 13 <listener> 14 <listener-class>com.qwirx.lex.LexContextListener</listener-class> 15 </listener> 9 16 10 17 <!-- Filters --> lex/trunk/src/com/qwirx/crosswire/kjv/KJV.java
r249 r259 7 7 import java.util.List; 8 8 import java.util.Map; 9 import java.util.Set;10 import java.util.TreeSet;11 9 12 10 import jemdros.Table; lex/trunk/src/com/qwirx/db/sql/SqlDatabase.java
r213 r259 32 32 public class SqlDatabase implements Database 33 33 { 34 private Connection conn;34 private Connection m_Connection; 35 35 private PreparedStatement stmt; 36 36 private ResultSet rs; … … 42 42 throws DatabaseException 43 43 { 44 this. conn = conn;44 this.m_Connection = conn; 45 45 this.username = username; 46 46 this.database = database; … … 88 88 } 89 89 } 90 90 91 public Connection getConnection() 92 { 93 return m_Connection; 94 } 95 91 96 public void executeDirect(String sql) throws DatabaseException 92 97 { … … 94 99 { 95 100 long startTime = System.currentTimeMillis(); 96 PreparedStatement s = conn.prepareStatement(sql);101 PreparedStatement s = m_Connection.prepareStatement(sql); 97 102 s.executeUpdate(); 98 103 s.close(); … … 121 126 try 122 127 { 123 stmt = conn.prepareStatement(sql);128 stmt = m_Connection.prepareStatement(sql); 124 129 } 125 130 catch (SQLException e) … … 184 189 { 185 190 return new SqlChange(username, database, 186 (SqlChange.Type)type, table, (String)conditions, conn);191 (SqlChange.Type)type, table, (String)conditions, m_Connection); 187 192 } 188 193 189 194 public void close() throws SQLException 190 195 { 191 conn.close();196 m_Connection.close(); 192 197 } 193 198 lex/trunk/src/com/qwirx/lex/emdros/EmdrosDatabase.java
r234 r259 18 18 import jemdros.BadMonadsException; 19 19 import jemdros.EmdrosEnv; 20 import jemdros.EmdrosException; 20 21 import jemdros.FlatSheaf; 21 22 import jemdros.MatchedObject; … … 46 47 { 47 48 private EmdrosEnv env; 48 private Connection conn;49 private Connection m_LogDatabase; 49 50 private String username, userhost, database; 50 51 private static final Logger m_LOG = Logger.getLogger(EmdrosDatabase.class); … … 52 53 public EmdrosDatabase(String dbHost, String dbName, String dbUser, 53 54 String dbPass, String logUser, String logFrom, Connection logDb) 54 throws DatabaseException 55 throws DatabaseException, EmdrosException 55 56 { 56 57 env = new EmdrosEnv(eOutputKind.kOKConsole, … … 63 64 } 64 65 65 this.conn= logDb;66 m_LogDatabase = logDb; 66 67 this.username = logUser; 67 68 this.userhost = logUser + "@" + logFrom; … … 72 73 { 73 74 return env.connectionOk(); 75 } 76 77 public void setLogConnection(Connection logDb) 78 { 79 m_LogDatabase = logDb; 74 80 } 75 81 … … 301 307 302 308 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); 304 313 return SetOfMonads.intersect(set, new SetOfMonads(min_m, max_m)); 305 314 } 306 315 307 316 public Change createChange(ChangeType changeType, String objectType, 308 Object objectIds) throws DatabaseException 317 Object objectIds) 318 throws DatabaseException 309 319 { 310 320 int [] id_ds = (int [])objectIds; … … 319 329 } 320 330 } 321 catch ( DatabaseException e)331 catch (Exception e) 322 332 { 323 333 throw new DatabaseException("Failed to determine object access", … … 326 336 327 337 return new EmdrosChange(username+"@"+userhost, database, 328 (EmdrosChange.Type)changeType, objectType, conn, this,338 (EmdrosChange.Type)changeType, objectType, m_LogDatabase, this, 329 339 id_ds); 330 340 } … … 394 404 395 405 public SetOfMonads getVisibleMonads() 396 throws SQLException 397 { 398 PreparedStatement stmt = conn.prepareStatement406 throws SQLException, EmdrosException 407 { 408 PreparedStatement stmt = m_LogDatabase.prepareStatement 399 409 ( 400 410 "SELECT Monad_First, Monad_Last " + … … 437 447 438 448 public boolean canWriteTo(String objectType, int objectId) 439 throws DatabaseException 449 throws DatabaseException, EmdrosException 440 450 { 441 451 return canWriteTo(objectType, new int[]{objectId}); … … 443 453 444 454 public boolean canWriteTo(String objectType, int[] objectIds) 445 throws DatabaseException 455 throws DatabaseException, EmdrosException 446 456 { 447 457 String query = "GET MONADS FROM OBJECTS WITH ID_DS = "; … … 493 503 try 494 504 { 495 stmt = conn.prepareStatement(query);505 stmt = m_LogDatabase.prepareStatement(query); 496 506 stmt.setString(1, username); 497 507 rs = stmt.executeQuery(); lex/trunk/src/com/qwirx/lex/GenExporter.java
r220 r259 2 2 3 3 import java.io.IOException; 4 import java.sql.SQLException; 4 5 6 import jemdros.EmdrosException; 5 7 import jemdros.MatchedObject; 6 8 import jemdros.SheafConstIterator; … … 11 13 12 14 import com.qwirx.db.DatabaseException; 13 import com.qwirx. lex.emdros.EmdrosDatabase;15 import com.qwirx.db.sql.SqlDatabase; 14 16 import com.qwirx.lex.hebrew.HebrewConverter; 15 17 import com.qwirx.lex.morph.HebrewMorphemeGenerator; … … 18 20 public class GenExporter 19 21 { 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 30 25 { 31 26 StringBuffer buf = new StringBuffer(); … … 44 39 "\n"); 45 40 46 exportObject(object, verse, buf );41 exportObject(object, verse, buf, sql); 47 42 48 43 return buf.toString(); … … 63 58 boolean lastMorpheme, String desc, 64 59 String morphNode) 60 throws EmdrosException 65 61 { 66 62 String raw = m_Word.getEMdFValue(surface).getString(); … … 82 78 83 79 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 86 83 { 87 84 if (object.getObjectTypeName().equals("word")) … … 90 87 new HebrewFeatureConverter(object, buf); 91 88 92 m_Generator.parse(object, hfc, true);89 new HebrewMorphemeGenerator().parse(object, hfc, true, sql); 93 90 } 94 91 … … 99 96 { 100 97 MatchedObject child = straws.next().const_iterator().next(); 101 exportObject(child, verse, buf );98 exportObject(child, verse, buf, sql); 102 99 } 103 100 } lex/trunk/src/com/qwirx/lex/hebrew/HebrewConverter.java
r241 r259 1 1 package com.qwirx.lex.hebrew; 2 2 3 import java.io.IOException; 4 5 import org.xml.sax.SAXException; 6 3 import jemdros.EmdrosException; 7 4 import jemdros.MatchedObject; 8 5 9 import com.qwirx.db.DatabaseException;10 6 import com.qwirx.lex.emdros.EmdrosDatabase; 11 7 import com.qwirx.lex.morph.HebrewMorphemeGenerator; … … 271 267 String substr = input.substring(i); 272 268 char c = input.charAt(i); 269 270 /* 273 271 char c2 = 0xffff; 274 272 if (i < input.length() - 1) … … 276 274 c2 = input.charAt(i + 1); 277 275 } 276 */ 278 277 279 278 if (substr.matches("[BGDKPT]\\.[@AEIOUW;:].*")) … … 382 381 } 383 382 384 static class Transliterator implements MorphemeHandler383 public static class Transliterator implements MorphemeHandler 385 384 { 386 385 private MatchedObject m_Word; … … 393 392 } 394 393 395 public void convert(String surface, 396 boolean lastMorpheme, String desc, 394 public void convert(String surface, boolean lastMorpheme, String desc, 397 395 String morphNode) 396 throws EmdrosException 398 397 { 399 398 String raw = m_Word.getEMdFValue(surface).getString(); … … 414 413 } 415 414 416 public void convert(String surface, 417 boolean lastMorpheme, String desc, 415 public void convert(String surface, boolean lastMorpheme, String desc, 418 416 String morphNode) 417 throws EmdrosException 419 418 { 420 419 String raw = m_Word.getEMdFValue(surface).getString(); … … 425 424 426 425 public static String wordToHtml(MatchedObject word, EmdrosDatabase emdros) 427 throws IOException, DatabaseException, SAXException428 { 429 return wordTranslitToHtml(word, new HebrewMorphemeGenerator( emdros));426 throws EmdrosException 427 { 428 return wordTranslitToHtml(word, new HebrewMorphemeGenerator()); 430 429 } 431 430 432 431 public static String wordTranslitToHtml(MatchedObject word, 433 432 HebrewMorphemeGenerator generator) 433 throws EmdrosException 434 434 { 435 435 StringBuffer out = new StringBuffer(); 436 436 Transliterator xlit = new Transliterator(word, out); 437 generator.parse(word, xlit, false );437 generator.parse(word, xlit, false, (String)null); 438 438 return toHtml(out.toString()); 439 439 } … … 441 441 public static String wordHebrewToHtml(MatchedObject word, 442 442 HebrewMorphemeGenerator generator) 443 throws EmdrosException 443 444 { 444 445 StringBuffer out = new StringBuffer(); 445 446 Hebrewator xlit = new Hebrewator(word, out); 446 generator.parse(word, xlit, false );447 generator.parse(word, xlit, false, (String)null); 447 448 return toHtml(out.toString()); 448 449 } lex/trunk/src/com/qwirx/lex/hebrew/HebrewEnglishDatabase.java
r189 r259 159 159 return m_Instance; 160 160 } 161 162 public synchronized static void delete() 163 { 164 m_Instance = null; 165 } 161 166 } lex/trunk/src/com/qwirx/lex/Lex.java
r250 r259 10 10 import java.net.URL; 11 11 import java.sql.Connection; 12 import java.sql.DriverManager;13 12 import java.sql.SQLException; 14 13 import java.util.Hashtable; 14 import java.util.Iterator; 15 15 import java.util.Map; 16 import java.util.Properties; 16 17 import java.util.Stack; 17 18 … … 20 21 import org.xml.sax.SAXException; 21 22 23 import com.mysql.jdbc.Driver; 22 24 import com.qwirx.db.DatabaseException; 23 25 import com.qwirx.db.sql.DbColumn; … … 117 119 return emdrosDb; 118 120 } 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 } 119 131 } 120 132 … … 125 137 126 138 public static final EmdrosDatabase getEmdrosDatabase(String user, 127 String host )139 String host, SqlDatabase logDatabase) 128 140 throws Exception 129 141 { … … 140 152 EmdrosDatabase db = pool.get(); 141 153 m_Ledger.put(db, pool); 154 db.setLogConnection(logDatabase.getConnection()); 142 155 return db; 143 156 } … … 146 159 { 147 160 EmdrosDatabasePool pool = m_Ledger.get(db); 161 if (pool == null) 162 { 163 db.delete(); 164 return; 165 } 166 148 167 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 } 149 181 } 150 182 … … 163 195 Preloader.load(); 164 196 165 Class.forName("com.mysql.jdbc.Driver").newInstance();166 167 197 URL url = Lex.class.getResource("/com/qwirx/crosswire/kjv"); 168 198 assert(url != null); … … 185 215 186 216 String dsn = "jdbc:mysql://localhost:3306/lex?user=emdf" + 187 "&password=changeme&useServerPrepStmts=false"; 217 "&password=changeme&useServerPrepStmts=false" + 218 "&jdbcCompliantTruncation=false"; 188 219 Connection dbconn; 189 220 190 221 try { 191 dbconn = DriverManager.getConnection(dsn);222 dbconn = new Driver().connect(dsn, new Properties()); 192 223 193 224 new DbTable("object_types", lex/trunk/src/com/qwirx/lex/lexicon/Lexeme.java
r142 r259 14 14 import java.util.Vector; 15 15 16 import jemdros.EmdrosException; 17 import jemdros.MatchedObject; 18 16 19 import com.qwirx.db.Change; 17 20 import com.qwirx.db.DatabaseException; 18 21 import com.qwirx.db.sql.SqlChange; 19 22 import com.qwirx.db.sql.SqlDatabase; 23 import com.qwirx.lex.hebrew.HebrewConverter.Transliterator; 24 import com.qwirx.lex.morph.HebrewMorphemeGenerator; 20 25 21 26 public class Lexeme implements Comparable … … 49 54 50 55 public int id, parentId, numSyntacticArgs; 51 public String label, desc, surface ;56 public String label, desc, surface, m_Gloss; 52 57 public Lexeme parent; 53 58 public List children = new Vector(); … … 229 234 return true; 230 235 } 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 } 231 261 232 262 private static Lexeme load(SqlDatabase sqldb, ResultSet rs) … … 237 267 l.id = rs.getInt("ID"); 238 268 l.surface = rs.getString("Lexeme"); 269 l.m_Gloss = rs.getString("Gloss"); 239 270 l.label = rs.getString("Domain_Label"); 240 271 l.desc = rs.getString("Domain_Desc"); … … 261 292 private static String getColumnList() 262 293 { 263 return "ID,Lexeme, Structure,Domain_Label,Domain_Desc,"+294 return "ID,Lexeme,Gloss,Structure,Domain_Label,Domain_Desc,"+ 264 295 "Domain_Parent_ID,Syntactic_Args, Caused, "+ 265 296 "Punctual, Has_Result_State, Telic, Predicate, "+ … … 296 327 } 297 328 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 298 376 public static Lexeme getTreeRoot(SqlDatabase sqldb) 299 377 throws DatabaseException, SQLException … … 358 436 ch = m_sqldb.createChange(SqlChange.INSERT, "lexicon_entries", 359 437 null); 438 ch.setString("Lexeme", surface); 360 439 } 361 440 else … … 365 444 } 366 445 446 ch.setString("Gloss", m_Gloss); 367 447 ch.setString("Structure", getLogicalStructure()); 368 448 ch.setString("Caused", isCaused() ? "1" : "0"); lex/trunk/src/com/qwirx/lex/morph/HebrewMorphemeGenerator.java
r256 r259 1 1 package com.qwirx.lex.morph; 2 2 3 import java. io.IOException;3 import java.sql.SQLException; 4 4 import java.util.ArrayList; 5 5 import java.util.Arrays; 6 6 import java.util.Iterator; 7 7 import java.util.List; 8 import java.util.Map; 9 10 import jemdros.EMdFValue; 8 9 import jemdros.EmdrosException; 11 10 import jemdros.MatchedObject; 12 11 13 import org.xml.sax.SAXException;14 15 12 import com.qwirx.db.DatabaseException; 16 import com.qwirx.lex.Lex; 17 import com.qwirx.lex.emdros.EmdrosDatabase; 18 import com.qwirx.lex.ontology.OntologyDb; 13 import com.qwirx.db.sql.SqlDatabase; 14 import com.qwirx.lex.lexicon.Lexeme; 19 15 20 16 public class HebrewMorphemeGenerator 21 17 { 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 28 21 { 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); 72 34 } 73 35 74 36 public void parse(MatchedObject word, MorphemeHandler handler, 75 boolean generateGloss) 37 boolean generateGloss, String gloss) 38 throws EmdrosException 76 39 { 77 40 if (!word.getObjectTypeName().equals("word")) … … 115 78 } 116 79 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")); 120 82 121 String gloss = null;122 83 String verbEnding = null; 123 84 String nounEnding = null; … … 125 86 if (generateGloss) 126 87 { 127 String person = (String)m_Persons.get(128 word.getEMdFValue ("person").toString());88 String person = word.getFeatureAsString( 89 word.getEMdFValueIndex("person")); 129 90 if (person.equals("first_person")) person = "1"; 130 91 else if (person.equals("second_person")) person = "2"; … … 153 114 } 154 115 155 String state = (String)m_States.get(156 word.getEMdFValue ("state").toString());116 String state = word.getFeatureAsString( 117 word.getEMdFValueIndex("state")); 157 118 if (state.equals("construct")) { state = "CS"; } 158 119 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 else175 {176 gloss = null;177 }178 }179 120 180 121 verbEnding = person + gender + number; lex/trunk/src/com/qwirx/lex/morph/MorphemeHandler.java
r79 r259 1 1 package com.qwirx.lex.morph; 2 3 import jemdros.EmdrosException; 2 4 3 5 public interface MorphemeHandler 4 6 { 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; 8 10 } lex/trunk/src/com/qwirx/lex/ontology/OntologyDb.java
r208 r259 43 43 private static OntologyDb m_Instance = null; 44 44 45 public static OntologyDb getInstance() throws IOException, SAXException 45 public synchronized static OntologyDb getInstance() 46 throws IOException, SAXException 46 47 { 47 48 if (m_Instance == null) … … 51 52 52 53 return m_Instance; 54 } 55 56 public synchronized static void delete() 57 { 58 m_Instance = null; 53 59 } 54 60 lex/trunk/src/com/qwirx/lex/parser/MorphEdge.java
r220 r259 153 153 public String getHtmlSurface() 154 154 { 155 return HebrewConverter.toHtml(m_Surface);155 return m_Surface; 156 156 } 157 157 lex/trunk/src/com/qwirx/lex/Search.java
r248 r259 1 1 package com.qwirx.lex; 2 2 3 import java.io.IOException;4 3 import java.sql.SQLException; 5 4 import java.util.ArrayList; … … 9 8 import java.util.Map; 10 9 10 import jemdros.EmdrosException; 11 11 import jemdros.FlatSheaf; 12 12 import jemdros.FlatSheafConstIterator; … … 24 24 import jemdros.TableRow; 25 25 26 import org.xml.sax.SAXException;27 28 26 import com.qwirx.db.DatabaseException; 29 27 import com.qwirx.lex.emdros.EmdrosDatabase; … … 58 56 59 57 public List<SearchResult> basic(String query) 60 throws DatabaseException, IOException, SAXException, SQLException, 61 TableException 58 throws DatabaseException, SQLException, TableException, EmdrosException 62 59 { 63 60 return advanced("[word " + … … 68 65 69 66 private void addToMonadSet(Sheaf sheaf, SetOfMonads set) 67 throws EmdrosException 70 68 { 71 69 if (sheaf == null) … … 90 88 91 89 public List<SearchResult> advanced(String query) 92 throws DatabaseException, IOException, SAXException, SQLException, 93 TableException 90 throws DatabaseException, SQLException, TableException, EmdrosException 94 91 { 95 92 HebrewMorphemeGenerator generator = 96 new HebrewMorphemeGenerator( m_Emdros);93 new HebrewMorphemeGenerator(); 97 94 98 95 Sheaf sheaf = m_Emdros.getSheaf … … 124 121 while (clause_iter.hasNext()) 125 122 { 123 MatchedObject clause = 124 clause_iter.next().const_iterator().next(); 125 126 126 m_ResultCount++; 127 127 if (m_ResultCount > m_MaxResults) continue; // just count them 128 128 129 MatchedObject clause =130 clause_iter.next().const_iterator().next();131 129 ResultBase base = new ResultBase(); 132 130 base.monads = clause.getMonads(); lex/trunk/src/com/qwirx/lex/wordnet/Wordnet.java
r26 r259 19 19 private static Wordnet ms_Instance; 20 20 21 public static Wordnet getInstance() throws IOException, JWNLException 21 public synchronized static Wordnet getInstance() 22 throws IOException, JWNLException 22 23 { 23 24 if (ms_Instance == null) … … 27 28 28 29 return ms_Instance; 30 } 31 32 public synchronized static void delete() 33 { 34 ms_Instance = null; 35 JWNL.shutdown(); 29 36 } 30 37 lex/trunk/test/com/qwirx/lex/EmdrosDatabaseTest.java
r190 r259 11 11 import java.util.Iterator; 12 12 13 import jemdros.EmdrosException; 13 14 import jemdros.Table; 14 15 import jemdros.TableIterator; … … 40 41 { 41 42 logDb = Lex.getSqlDatabase("test"); 42 emdros = Lex.getEmdrosDatabase("test", "localhost" );43 emdros = Lex.getEmdrosDatabase("test", "localhost", logDb); 43 44 } 44 45 … … 137 138 public void checkCurrentValues(int objectID_D, String objectType, 138 139 ChangedRow cr) 139 throws DatabaseException 140 throws DatabaseException, EmdrosException 140 141 { 141 142 StringBuffer query = new StringBuffer("GET FEATURES "); lex/trunk/test/com/qwirx/lex/GenExporterTest.java
r257 r259 127 127 public void testGenExportCode() throws Exception 128 128 { 129 EmdrosDatabase emdros = Lex.getEmdrosDatabase("test", "localhost"); 129 EmdrosDatabase emdros = Lex.getEmdrosDatabase("test", "localhost", 130 Lex.getSqlDatabase("test")); 130 131 131 132 Sheaf sheaf = emdros.getSheaf … … 156 157 157 158 assertEquals(NEHEMIAH_2_11b_EXPORT, 158 new GenExporter( emdros).export(clause, verse));159 new GenExporter().export(clause, verse, Lex.getSqlDatabase("test"))); 159 160 } 160 161 … … 173 174 public void testCrashJavaWithGetStringOnFeature2() throws Exception 174 175 { 175 EmdrosDatabase emdros = Lex.getEmdrosDatabase("test", "localhost"); 176 EmdrosDatabase emdros = Lex.getEmdrosDatabase("test", "localhost", 177 Lex.getSqlDatabase("test")); 176 178 177 179 Sheaf sheaf = emdros.getSheaf lex/trunk/test/com/qwirx/lex/JswordExamples.java
r251 r259 94 94 SwordBookPath.setAugmentPath(files); 95 95 96 m_Emdros = Lex.getEmdrosDatabase("test", "localhost"); 96 m_Emdros = Lex.getEmdrosDatabase("test", "localhost", 97 Lex.getSqlDatabase("test")); 97 98 } 98 99 lex/trunk/test/com/qwirx/lex/LexemeTest.java
r190 r259 9 9 import java.util.Vector; 10 10 11 import jemdros.EmdrosException; 11 12 import jemdros.MatchedObject; 12 13 import jemdros.Sheaf; … … 39 40 super(name); 40 41 sql = Lex.getSqlDatabase ("test"); 41 emdros = Lex.getEmdrosDatabase("test", "localhost" );42 emdros = Lex.getEmdrosDatabase("test", "localhost", sql); 42 43 } 43 44 … … 384 385 385 386 private String getEvaluatedLogicalStructure(int emdrosClauseId) 386 throws DatabaseException 387 throws DatabaseException, EmdrosException 387 388 { 388 389 Sheaf sheaf = emdros.getSheaf lex/trunk/test/com/qwirx/lex/SearchTest.java
r236 r259 9 9 import jemdros.SheafConstIterator; 10 10 import jemdros.Straw; 11 import jemdros.StrawConstIterator;12 11 import junit.framework.TestCase; 13 12 … … 28 27 public void setUp() throws Exception 29 28 { 30 m_Emdros = Lex.getEmdrosDatabase("chris", "test"); 29 m_Emdros = Lex.getEmdrosDatabase("chris", "test", 30 Lex.getSqlDatabase("test")); 31 31 } 32 32 … … 58 58 Iterator<SearchResult> actualIterator = actualResults.iterator(); 59 59 60 HebrewMorphemeGenerator generator = 61 new HebrewMorphemeGenerator(m_Emdros); 60 HebrewMorphemeGenerator generator = new HebrewMorphemeGenerator(); 62 61 63 62 Sheaf sheaf = m_Emdros.getSheaf … … 81 80 while (sci.hasNext()) 82 81 { 82 Straw straw = sci.next(); 83 83 84 count++; 84 85 if (count > limit) continue; 85 86 86 Straw straw = sci.next();87 87 MatchedObject clause = straw.const_iterator().next(); 88 88 clauses.add(new Integer(clause.getID_D())); … … 254 254 i.assertSimple("a", "Databases", 255 255 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", 257 259 new Attributes().clazz("clause_jsp").href("clause.jsp")); 258 260 i.assertSimple("a", "Search",
