[jsword-svn] r1400 - in trunk: bibledesktop/src/main/resources/xsl/cswing jsword/src/main/java/org/crosswire/jsword/book jsword/src/main/java/org/crosswire/jsword/book/basic jsword/src/main/java/org/crosswire/jsword/examples jsword/src/main/java/org/crosswire/jsword/index/lucene jsword/src/test/java/org/crosswire/jsword/book jsword/src/test/java/org/crosswire/jsword/book/test jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage jsword-limbo/src/main/java/org/crosswire/jsword/book jsword-limbo/src/main/java/org/crosswire/jsword/book/raw jsword-limbo/src/main/java/org/crosswire/jsword/book/search/ser
dmsmith at www.crosswire.org
dmsmith at www.crosswire.org
Wed Jun 13 08:28:09 MST 2007
Author: dmsmith
Date: 2007-06-13 08:28:09 -0700 (Wed, 13 Jun 2007)
New Revision: 1400
Modified:
trunk/bibledesktop/src/main/resources/xsl/cswing/simple.xsl
trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/PassageListCellRenderer.java
trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/StudyTool.java
trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/raw/RawBook.java
trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/search/ser/SerIndex.java
trunk/jsword/src/main/java/org/crosswire/jsword/book/BookData.java
trunk/jsword/src/main/java/org/crosswire/jsword/book/BookMetaData.java
trunk/jsword/src/main/java/org/crosswire/jsword/book/OSISUtil.java
trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/AbstractPassageBook.java
trunk/jsword/src/main/java/org/crosswire/jsword/examples/APIExamples.java
trunk/jsword/src/main/java/org/crosswire/jsword/examples/StrongsAnalysis.java
trunk/jsword/src/main/java/org/crosswire/jsword/index/lucene/LuceneIndex.java
trunk/jsword/src/test/java/org/crosswire/jsword/book/BooksTest.java
trunk/jsword/src/test/java/org/crosswire/jsword/book/ReadEverything.java
trunk/jsword/src/test/java/org/crosswire/jsword/book/test/Speed.java
Log:
Improved performance by using osis fragments rather than whole documents.
Modified: trunk/bibledesktop/src/main/resources/xsl/cswing/simple.xsl
===================================================================
--- trunk/bibledesktop/src/main/resources/xsl/cswing/simple.xsl 2007-06-13 14:15:36 UTC (rev 1399)
+++ trunk/bibledesktop/src/main/resources/xsl/cswing/simple.xsl 2007-06-13 15:28:09 UTC (rev 1400)
@@ -123,7 +123,7 @@
<xsl:variable name="keyf" select="jsword:org.crosswire.jsword.passage.PassageKeyFactory.instance()"/>
<!--=======================================================================-->
- <xsl:template match="/osis">
+ <xsl:template match="/">
<html dir="{$direction}">
<head>
<base href="{$baseURL}"/>
@@ -206,6 +206,15 @@
<!--=======================================================================-->
<!--
+ == A proper OSIS document has osis as it's root.
+ == We dig deeper for it's content.
+ -->
+ <xsl:template match="osis">
+ <xsl:apply-templates/>
+ </xsl:template>
+
+ <!--=======================================================================-->
+ <!--
== An OSIS document may contain more that one work.
== Each work is held in an osisCorpus element.
== If there is only one work, then this element will (should) be absent.
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/BookData.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/BookData.java 2007-06-13 14:15:36 UTC (rev 1399)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/BookData.java 2007-06-13 15:28:09 UTC (rev 1400)
@@ -32,6 +32,7 @@
import org.jdom.Content;
import org.jdom.Document;
import org.jdom.Element;
+import org.jdom.Namespace;
import org.jdom.Text;
/**
@@ -86,7 +87,7 @@
// TODO(DMS): Determine the proper representation of the OSISWork name for multiple books.
osis = OSISUtil.createOsisFramework(getFirstBook().getBookMetaData());
Element text = osis.getChild(OSISUtil.OSIS_ELEMENT_OSISTEXT);
- Element div = getOsisContent();
+ Element div = getOsisFragment();
text.addContent(div);
}
@@ -94,14 +95,16 @@
}
/**
- * Check that a BookData is valid.
- * Currently, this does nothing, and isn't used. it was broken when we used
- * JAXB, however it wasn't much use then becuase JAXB did a lot to keep the
- * document valid anyway. Under JDOM there is more point, but I don't think
- * JDOM supports this out of the box.
+ * Accessor for the root OSIS element
*/
- public void validate()
+ public Element getOsisFragment() throws BookException
{
+ if (fragment == null)
+ {
+ fragment = getOsisContent();
+ }
+
+ return fragment;
}
/**
@@ -110,7 +113,14 @@
*/
public SAXEventProvider getSAXEventProvider() throws BookException
{
- return new JDOMSAXEventProvider(new Document(getOsis()));
+ // If the fragment is already in a document, then use that.
+ Element frag = getOsisFragment();
+ Document doc = frag.getDocument();
+ if (doc == null)
+ {
+ doc = new Document(frag);
+ }
+ return new JDOMSAXEventProvider(doc);
}
/**
@@ -199,12 +209,14 @@
buf.append(book.getInitials());
cell.addContent(OSISUtil.factory().createText(buf.toString()));
+ cell.setAttribute(OSISUtil.OSIS_ATTR_LANG, prevBook.getProperty(BookMetaData.KEY_XML_LANG), Namespace.XML_NAMESPACE);
row.addContent(cell);
cell = OSISUtil.factory().createHeaderCell();
}
}
cell.addContent(OSISUtil.factory().createText(book.getInitials()));
+ cell.setAttribute(OSISUtil.OSIS_ATTR_LANG, book.getProperty(BookMetaData.KEY_XML_LANG), Namespace.XML_NAMESPACE);
row.addContent(cell);
iters[i] = book.getOsisIterator(key, true);
@@ -295,4 +307,9 @@
* The complete osis container for the element
*/
private Element osis;
+
+ /**
+ * Just the element
+ */
+ private Element fragment;
}
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/BookMetaData.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/BookMetaData.java 2007-06-13 14:15:36 UTC (rev 1399)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/BookMetaData.java 2007-06-13 15:28:09 UTC (rev 1400)
@@ -260,6 +260,11 @@
String KEY_LANGUAGE = "Language"; //$NON-NLS-1$
/**
+ * The key for the name in the properties map
+ */
+ String KEY_XML_LANG = "Lang"; //$NON-NLS-1$
+
+ /**
* The key for the initials in the properties map
*/
String KEY_INITIALS = "Initials"; //$NON-NLS-1$
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/OSISUtil.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/OSISUtil.java 2007-06-13 14:15:36 UTC (rev 1399)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/OSISUtil.java 2007-06-13 15:28:09 UTC (rev 1400)
@@ -569,6 +569,11 @@
content = root.getChild(OSISUtil.OSIS_ELEMENT_OSISTEXT);
}
+ if (OSISUtil.OSIS_ELEMENT_OSISTEXT.equals(root.getName()))
+ {
+ content = root.getChild(OSISUtil.OSIS_ELEMENT_DIV);
+ }
+
// At this point we are at something interesting, possibly null.
// If this was a semantically valid OSIS document then it is a div.
// As long as this node has one child dig deeper.
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/AbstractPassageBook.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/AbstractPassageBook.java 2007-06-13 14:15:36 UTC (rev 1399)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/AbstractPassageBook.java 2007-06-13 15:28:09 UTC (rev 1400)
@@ -150,7 +150,7 @@
public void setDocument(Key key, BookData bdata) throws BookException
{
// For all of the sections
- Iterator sit = OSISUtil.getFragment(bdata.getOsis()).iterator();
+ Iterator sit = OSISUtil.getFragment(bdata.getOsisFragment()).iterator();
while (sit.hasNext())
{
Element div = (Element) sit.next();
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/examples/APIExamples.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/examples/APIExamples.java 2007-06-13 14:15:36 UTC (rev 1399)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/examples/APIExamples.java 2007-06-13 15:28:09 UTC (rev 1400)
@@ -82,7 +82,7 @@
Key key = bible.getKey("Gen 1 1"); //$NON-NLS-1$
BookData data = new BookData(bible, key);
- String text = OSISUtil.getCanonicalText(data.getOsis());
+ String text = OSISUtil.getCanonicalText(data.getOsisFragment());
System.out.println("The plain text of Gen 1:1 is " + text); //$NON-NLS-1$
}
@@ -140,7 +140,7 @@
System.out.println("The first Key in the default dictionary is " + first); //$NON-NLS-1$
BookData data = new BookData(dict, keys);
- System.out.println("And the text against that key is " + OSISUtil.getPlainText(data.getOsis())); //$NON-NLS-1$
+ System.out.println("And the text against that key is " + OSISUtil.getPlainText(data.getOsisFragment())); //$NON-NLS-1$
}
/**
@@ -249,7 +249,7 @@
{
Verse verse = (Verse) iter.next();
BookData data = new BookData(bible, verse);
- System.out.println('|' + BibleInfo.getBookName(verse.getBook()) + '|' + verse.getChapter() + '|' + verse.getVerse() + '|' + OSISUtil.getCanonicalText(data.getOsis()));
+ System.out.println('|' + BibleInfo.getBookName(verse.getBook()) + '|' + verse.getChapter() + '|' + verse.getVerse() + '|' + OSISUtil.getCanonicalText(data.getOsisFragment()));
}
}
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/examples/StrongsAnalysis.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/examples/StrongsAnalysis.java 2007-06-13 14:15:36 UTC (rev 1399)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/examples/StrongsAnalysis.java 2007-06-13 15:28:09 UTC (rev 1400)
@@ -66,7 +66,7 @@
try
{
- osis = data.getOsis();
+ osis = data.getOsisFragment();
}
catch (BookException e)
{
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/index/lucene/LuceneIndex.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/index/lucene/LuceneIndex.java 2007-06-13 14:15:36 UTC (rev 1399)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/index/lucene/LuceneIndex.java 2007-06-13 15:28:09 UTC (rev 1400)
@@ -376,7 +376,7 @@
try
{
- osis = data.getOsis();
+ osis = data.getOsisFragment();
}
catch (BookException e)
{
@@ -386,6 +386,7 @@
// Do the actual indexing
text = OSISUtil.getCanonicalText(osis);
+ doc = null;
if (text != null && text.length() > 0)
{
doc = new Document();
Modified: trunk/jsword/src/test/java/org/crosswire/jsword/book/BooksTest.java
===================================================================
--- trunk/jsword/src/test/java/org/crosswire/jsword/book/BooksTest.java 2007-06-13 14:15:36 UTC (rev 1399)
+++ trunk/jsword/src/test/java/org/crosswire/jsword/book/BooksTest.java 2007-06-13 15:28:09 UTC (rev 1400)
@@ -140,7 +140,7 @@
{
Book bible = bibles[i];
BookData data = new BookData(bible, gen11[i]);
- assertNotNull(data.getOsis());
+ assertNotNull(data.getOsisFragment());
}
}
Modified: trunk/jsword/src/test/java/org/crosswire/jsword/book/ReadEverything.java
===================================================================
--- trunk/jsword/src/test/java/org/crosswire/jsword/book/ReadEverything.java 2007-06-13 14:15:36 UTC (rev 1399)
+++ trunk/jsword/src/test/java/org/crosswire/jsword/book/ReadEverything.java 2007-06-13 15:28:09 UTC (rev 1400)
@@ -135,7 +135,7 @@
//log.debug("reading: "+bmd.getInitials()+"/"+key.getText());
BookData data = new BookData(book, key);
- if (data.getOsis() == null)
+ if (data.getOsisFragment() == null)
{
log.warn("No output from: "+book.getInitials()+", "+key.getName()); //$NON-NLS-1$ //$NON-NLS-2$
}
Modified: trunk/jsword/src/test/java/org/crosswire/jsword/book/test/Speed.java
===================================================================
--- trunk/jsword/src/test/java/org/crosswire/jsword/book/test/Speed.java 2007-06-13 14:15:36 UTC (rev 1399)
+++ trunk/jsword/src/test/java/org/crosswire/jsword/book/test/Speed.java 2007-06-13 15:28:09 UTC (rev 1400)
@@ -117,7 +117,7 @@
*/
private void dummyDisplay(Passage ref) throws BookException
{
- new BookData(book, ref).getOsis();
+ new BookData(book, ref).getOsisFragment();
}
/**
Modified: trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/PassageListCellRenderer.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/PassageListCellRenderer.java 2007-06-13 14:15:36 UTC (rev 1399)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/PassageListCellRenderer.java 2007-06-13 15:28:09 UTC (rev 1400)
@@ -90,7 +90,7 @@
if (text == null)
{
BookData bdata = new BookData(bible, range);
- String simple = OSISUtil.getCanonicalText(bdata.getOsis());
+ String simple = OSISUtil.getCanonicalText(bdata.getOsisFragment());
text = "<html><b>" + range.getName() + "</b> " + simple; //$NON-NLS-1$ //$NON-NLS-2$
hash.put(range, text);
}
Modified: trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/StudyTool.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/StudyTool.java 2007-06-13 14:15:36 UTC (rev 1399)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/StudyTool.java 2007-06-13 15:28:09 UTC (rev 1400)
@@ -55,43 +55,39 @@
Map reply = new HashMap();
// Loop through all the divs in this BookData
- Iterator oit = OSISUtil.getFragment(data.getOsis()).iterator();
- while (oit.hasNext())
+ Element div = data.getOsisFragment();
+
+ // Get all the w elements in this div
+ Iterator dit = OSISUtil.getDeepContent(div, OSISUtil.OSIS_ELEMENT_W).iterator();
+ while (dit.hasNext())
{
- Element div = (Element) oit.next();
+ // LATER(joe): This only looks at L1 content, we need a deep scan for 'W's.
+ Object ele = dit.next();
+ Element w = (Element) ele;
+ String content = OSISUtil.getPlainText(w);
- // And loop over the content in this div
- Iterator dit = OSISUtil.getDeepContent(div, OSISUtil.OSIS_ELEMENT_W).iterator();
- while (dit.hasNext())
+ // There will be many words in the passage in question,
+ // but not all of them will be translations of our word
+ if (content.indexOf(word) != -1)
{
- // LATER(joe): This only looks at L1 content, we need a deep scan for 'W's.
- Object ele = dit.next();
- Element w = (Element) ele;
- String content = OSISUtil.getPlainText(w);
+ Strongs strongs = new Strongs(w);
- // There will be many words in the passage in question,
- // but not all of them will be translations of our word
- if (content.indexOf(word) != -1)
+ Translation trans = (Translation) reply.get(strongs);
+ if (trans == null)
{
- Strongs strongs = new Strongs(w);
-
- Translation trans = (Translation) reply.get(strongs);
- if (trans == null)
+ try
{
- try
- {
- trans = new Translation(word, strongs, bible.getKey(null));
- }
- catch (NoSuchKeyException ex)
- {
- log.warn("Failed to create key", ex); //$NON-NLS-1$
- }
-
- reply.put(strongs, trans);
+ trans = new Translation(word, strongs, bible.getKey(null));
}
+ catch (NoSuchKeyException ex)
+ {
+ log.warn("Failed to create key", ex); //$NON-NLS-1$
+ }
- trans.getKey().addAll(OSISUtil.getVerse(w));
+ reply.put(strongs, trans);
}
+
+ trans.getKey().addAll(OSISUtil.getVerse(w));
}
}
@@ -111,44 +107,40 @@
Map reply = new HashMap();
// Loop through all the divs in this BookData
- Iterator oit = OSISUtil.getFragment(data.getOsis()).iterator();
- while (oit.hasNext())
+ Element div = data.getOsisFragment();
+
+ // Get all the w elements in this div
+ Iterator dit = OSISUtil.getDeepContent(div, OSISUtil.OSIS_ELEMENT_W).iterator();
+ while (dit.hasNext())
{
- Element div = (Element) oit.next();
+ // see note above on deep scanning for W
+ Object ele = dit.next();
+ Element w = (Element) ele;
+ Strongs strongs = new Strongs(w);
- // And loop over the content in this div
- Iterator dit = OSISUtil.getDeepContent(div, OSISUtil.OSIS_ELEMENT_W).iterator();
- while (dit.hasNext())
+ // There will be many strongs number in the passage in
+ // question, but not all of them will be translations of our
+ // strongs number
+ if (strongs.equals(number))
{
- // see note above on deep scanning for W
- Object ele = dit.next();
- Element w = (Element) ele;
- Strongs strongs = new Strongs(w);
+ String translated = OSISUtil.getPlainText(w);
- // There will be many strongs number in the passage in
- // question, but not all of them will be translations of our
- // strongs number
- if (strongs.equals(number))
+ Translation trans = (Translation) reply.get(translated);
+ if (trans == null)
{
- String translated = OSISUtil.getPlainText(w);
-
- Translation trans = (Translation) reply.get(translated);
- if (trans == null)
+ try
{
- try
- {
- trans = new Translation(translated, number, bible.getKey(null));
- }
- catch (NoSuchKeyException ex)
- {
- log.warn("Failed to create key", ex); //$NON-NLS-1$
- }
-
- reply.put(translated, trans);
+ trans = new Translation(translated, number, bible.getKey(null));
}
+ catch (NoSuchKeyException ex)
+ {
+ log.warn("Failed to create key", ex); //$NON-NLS-1$
+ }
- trans.getKey().addAll(OSISUtil.getVerse(w));
+ reply.put(translated, trans);
}
+
+ trans.getKey().addAll(OSISUtil.getVerse(w));
}
}
Modified: trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/raw/RawBook.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/raw/RawBook.java 2007-06-13 14:15:36 UTC (rev 1399)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/raw/RawBook.java 2007-06-13 15:28:09 UTC (rev 1400)
@@ -401,7 +401,7 @@
public void setDocument(Verse verse, BookData bdata) throws BookException
{
// For all of the sections
- Iterator sit = OSISUtil.getFragment(bdata.getOsis()).iterator();
+ Iterator sit = bdata.getOsisFragment().getContent().iterator();
while (sit.hasNext())
{
Element div = (Element) sit.next();
Modified: trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/search/ser/SerIndex.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/search/ser/SerIndex.java 2007-06-13 14:15:36 UTC (rev 1399)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/jsword/book/search/ser/SerIndex.java 2007-06-13 15:28:09 UTC (rev 1400)
@@ -275,7 +275,7 @@
else
{
BookData data = new BookData(book, sublist);
- String text = OSISUtil.getPlainText(data.getOsis());
+ String text = OSISUtil.getPlainText(data.getOsisFragment());
String[] words = SentenceUtil.getWords(text);
for (int i = 0; i < words.length; i++)
More information about the jsword-svn
mailing list