Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.eireneh.bible.book.raw
Class RawBible  view RawBible download RawBible.java

java.lang.Object
  extended bycom.eireneh.bible.book.AbstractBible
      extended bycom.eireneh.bible.book.VersewiseBible
          extended bycom.eireneh.bible.book.raw.RawBible
All Implemented Interfaces:
com.eireneh.bible.book.Bible, com.eireneh.bible.book.Book

public class RawBible
extends com.eireneh.bible.book.VersewiseBible

RawBible is a custom Bible. It is designed to be:

As a result of this is can be very slow, or very memory hungry. I guess that the technology developed here could be useful as a delivery format, but the timings I am getting from my benchmarks say "start again".

There is a question mark over how this format will handle rich text. The dictionary lookup scheme can be very space efficient but I'm not sure how to embed strongs numbers with the same efficiency.

The algorithm I have implemented here is not perfect. To get a list of the verses it gets 'wrong' see generate.log. There are 2 reasons for problems. The RawBible does not take note of double spaces. And we incorrectly capitalize hyphenated words at the beginning of sentances.

This is in part converted from the VB code that I wrote ages ago that does asimilar job.

 Public Sub WritePassage(sText As String, lPassageID As Long, bLang As Byte, lBibleID As Long)

   Static bItalic As Boolean

   Dim mWordInsts As Collection

   Dim iNext As Long
   Dim iTemp As Long
   Dim iLast As Long
   Dim bDash As Boolean
   Dim sWord As String
   Dim bThisItalic As Boolean
   Dim iStart As Long
   Dim iEnd As Long
   Dim sNote As String
   Dim mNotes As Collection
   Dim vNoteStr As Variant
   Dim iNumNotes As Long
   Dim lWordInstID As Long

   Set mWordInsts = New Collection
   iNext = 1
   iTemp = 1
   iLast = 1
   bDash = False
   iNumNotes = 1

   ' For each real word in the verse
   Do

     ' If this word contains a "{" then it is part of a comment
     ' and not a word. We need to strip out sets of comments
     Set mNotes = New Collection
     Do
       ' Decide how long this word is
       iNext = InStr(iLast, sText, " ")
       iTemp = InStr(iLast, sText, "--")
       If iTemp = iLast Then iTemp = 0
       If iTemp <> 0 And iTemp < iNext Then
         iNext = iTemp
         bDash = True
       Else
         bDash = False
       End If

       ' If this is the end add in the rest otherwise just add in this word
       If iNext = 0 Then
         sWord = Mid$(sText, iLast, Len(sText) - iLast + 1)
       Else
         sWord = Mid$(sText, iLast, iNext - iLast)
       End If


       ' Strip out the notes
       ' If this word is not a comment
       iStart = InStr(iLast, sText, "{")
       If iStart = 0 Then Exit Do
       If iStart > iLast Then Exit Do

       ' Check we have a start and an end
       iEnd = InStr(iLast, sText, "}")

       ' Add the note in
       sNote = Mid$(sText, iStart + 1, iEnd - iStart - 1)
       mNotes.Add sNote

       ' Adjust where we are looking for words
       iLast = iEnd + 2
       If iLast > Len(sText) Then
         iNext = 0
         sWord = ""
         Exit Do
       End If
     Loop

     ' Are there any notes to add?
     If mNotes.Count <> 0 Then
       ' If there is no previous word to add to then create one
       If mWordInsts.Count = 0 Then
         lWordInstID = WriteWordInst(lPassageID, 1, lBibleID)
         SetWordInstItalic lWordInstID, bItalic
         mWordInsts.Add lWordInstID
       End If

       ' So add the notes to the previous word
       For Each vNoteStr In mNotes
         sNote = vNoteStr
         WriteNote mWordInsts.Item(mWordInsts.Count), iNumNotes, sNote
         iNumNotes = iNumNotes + 1
       Next
     End If
     Set mNotes = Nothing


     ' Italics
     ' Do we have a start italic char
     If InStr(sWord, "[") Then
       bItalic = True
       sWord = RemoveChar(sWord, "[")
     End If

     ' Remember the state for this letter
     bThisItalic = bItalic

     ' do we have an end italic char
     If InStr(sWord, "]") Then
       bItalic = False
       sWord = RemoveChar(sWord, "]")
     End If


     ' Actually add the word in
     If sWord <> "" Then
       AddWord mWordInsts, sWord, lPassageID, bLang, lBibleID, bThisItalic
     End If


     ' Add one an extra one to the last used only for a Space split
     If bDash Then
       iLast = iNext
     Else
       iLast = iNext + 1
     End If

   Loop Until iNext = 0
   Set mWordInsts = Nothing

 End Sub
 
Distribution Licence:
Project B is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
The License is available on the internet here, by writing to Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, Or locally at the Licence link below.
The copyright to this program is held by it's authors.

Version:
D0.I0.T0

Field Summary
private  com.eireneh.bible.passage.Passage[] cache
          The cache of word searches
private  Insts case_insts
          The source of Case Instances
private  boolean create
          Are we in create mode?
private  java.net.URL dir
          The directory that the data files are stored in
protected static com.eireneh.util.Logger log
          The log stream
private  boolean memory
          Are we cacheing or in on disk mode
static int MODE_READ_DISK
          Constant for read-only, data on disk mode
static int MODE_READ_MEMORY
          Constant for read-only, data in memory mode
static int MODE_WRITE
          Constant for create mode
private  java.lang.String name
          The name of this version
private  ParaInstsMem para_insts
          The source of Para Instances
private  Insts punc_insts
          The source of Punctuation Instances
private  Items punc_items
          The source of Punctuation
private  boolean started
          Has init() been called?
private  com.eireneh.bible.book.Version version
          The Version of the Bible that this produces
private  Insts word_insts
          The Source of Word Instances
private  Items word_items
          The Source of Words
 
Fields inherited from class com.eireneh.bible.book.VersewiseBible
 
Fields inherited from class com.eireneh.bible.book.AbstractBible
listeners, percent
 
Constructor Summary
RawBible(java.lang.String name, java.net.URL url, int mode)
          Create a new set of resources based on a URL.
 
Method Summary
protected  void append(com.eireneh.bible.book.BibleEle doc, com.eireneh.bible.passage.VerseRange range)
          Part of the Bible interface - Get the text for this reference.
protected  void createSearchCache()
          Create a cache to speed up searches.
protected  void deleteSearchCache()
          Create a cache to speed up searches.
 void destroy()
          Shut the Bible down.
 com.eireneh.bible.passage.Passage findPassage(java.lang.String word)
          For a given word find a list of references to it
 void flush()
          Flush the data written to disk
 void foundPassage(java.lang.String word, com.eireneh.bible.passage.Passage ref)
          Save a list of found words.
 java.net.URL getBaseURL()
          The directory that holds the RawBible files
 void getDocument(com.eireneh.bible.book.BibleEle doc, com.eireneh.bible.passage.Passage ref)
          Create an XML document for the specified Verses
 com.eireneh.bible.book.BibleDriver getDriver()
          What driver is controlling this Bible?
 int getMode()
          Does this Bible cache everything in memory or leave it on disk and then read it at query time.
 java.lang.String getName()
          Meta-Information: What name can I use to get this Bible in a call to Bibles.getBible(name);
 java.lang.String[] getStartsWith(java.lang.String word)
          Find a list of words that start with the given word
 java.lang.String getText(com.eireneh.bible.passage.VerseRange range)
          Create an String for the specified Verses
 com.eireneh.bible.book.Version getVersion()
          Meta-Information: What version of the Bible is this?
protected  WordInstsMem getWordData()
          Accessor for the Verse/Words arrays.
protected  WordItemsMem getWords()
          Accessor for the list of Words.
 void init()
          Lazy initialization
 java.util.Enumeration listWords()
          Retrieval: Get a list of the words used by this Version.
 void setDocument(com.eireneh.bible.book.BibleEle doc)
          Write the XML to disk.
 void setMode(int mode)
          Does this Bible cache everything in memory or leave it on disk and then read it at query time.
 void setVersion(com.eireneh.bible.book.Version version)
          Setup the Version information
 
Methods inherited from class com.eireneh.bible.book.VersewiseBible
generate, generatePassages, generateText, getProperties
 
Methods inherited from class com.eireneh.bible.book.AbstractBible
addProgressListener, fireProgressMade, getElement, getPropertiesURL, removeProgressListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_READ_MEMORY

public static final int MODE_READ_MEMORY
Constant for read-only, data in memory mode

See Also:
Constant Field Values

MODE_READ_DISK

public static final int MODE_READ_DISK
Constant for read-only, data on disk mode

See Also:
Constant Field Values

MODE_WRITE

public static final int MODE_WRITE
Constant for create mode

See Also:
Constant Field Values

dir

private java.net.URL dir
The directory that the data files are stored in


create

private boolean create
Are we in create mode?


started

private boolean started
Has init() been called?


word_items

private Items word_items
The Source of Words


word_insts

private Insts word_insts
The Source of Word Instances


punc_items

private Items punc_items
The source of Punctuation


punc_insts

private Insts punc_insts
The source of Punctuation Instances


case_insts

private Insts case_insts
The source of Case Instances


para_insts

private ParaInstsMem para_insts
The source of Para Instances


name

private java.lang.String name
The name of this version


cache

private com.eireneh.bible.passage.Passage[] cache
The cache of word searches


memory

private boolean memory
Are we cacheing or in on disk mode


version

private com.eireneh.bible.book.Version version
The Version of the Bible that this produces


log

protected static com.eireneh.util.Logger log
The log stream

Constructor Detail

RawBible

public RawBible(java.lang.String name,
                java.net.URL url,
                int mode)
         throws com.eireneh.bible.book.BookException
Create a new set of resources based on a URL.

Method Detail

getMode

public int getMode()
Does this Bible cache everything in memory or leave it on disk and then read it at query time.


setMode

public void setMode(int mode)
             throws com.eireneh.bible.book.BookException
Does this Bible cache everything in memory or leave it on disk and then read it at query time. I wonder if this is an over complex and redundant function? Maybe it is something to simplify at some point.


init

public void init()
          throws com.eireneh.bible.book.BookException
Lazy initialization


destroy

public void destroy()
             throws com.eireneh.bible.book.BookException
Shut the Bible down.


getDriver

public com.eireneh.bible.book.BibleDriver getDriver()
What driver is controlling this Bible?


getName

public java.lang.String getName()
Meta-Information: What name can I use to get this Bible in a call to Bibles.getBible(name);


getVersion

public com.eireneh.bible.book.Version getVersion()
Meta-Information: What version of the Bible is this?


setVersion

public void setVersion(com.eireneh.bible.book.Version version)
Setup the Version information


getText

public java.lang.String getText(com.eireneh.bible.passage.VerseRange range)
                         throws com.eireneh.bible.book.BookException
Create an String for the specified Verses


getDocument

public void getDocument(com.eireneh.bible.book.BibleEle doc,
                        com.eireneh.bible.passage.Passage ref)
                 throws com.eireneh.bible.book.BookException
Create an XML document for the specified Verses


findPassage

public com.eireneh.bible.passage.Passage findPassage(java.lang.String word)
                                              throws com.eireneh.bible.book.BookException
For a given word find a list of references to it


listWords

public java.util.Enumeration listWords()
                                throws com.eireneh.bible.book.BookException
Retrieval: Get a list of the words used by this Version. This is not vital for normal display, however it is very useful for various things, not least of which is new Version generation. However if you are only looking to display from this Bible then you could skip this one.


setDocument

public void setDocument(com.eireneh.bible.book.BibleEle doc)
                 throws com.eireneh.bible.book.BookException
Write the XML to disk. Now this code limits us to only having para marks at the start of verses, and in the NIV there are marks in the middle of verses. However all the data sources that I have (ex-OLB) have the same limitation so I'm not to bothered just yet.


foundPassage

public void foundPassage(java.lang.String word,
                         com.eireneh.bible.passage.Passage ref)
                  throws com.eireneh.bible.book.BookException
Save a list of found words. This has been dome already


flush

public void flush()
           throws com.eireneh.bible.book.BookException
Flush the data written to disk


getBaseURL

public java.net.URL getBaseURL()
The directory that holds the RawBible files


getWords

protected WordItemsMem getWords()
Accessor for the list of Words. For testing only


getWordData

protected WordInstsMem getWordData()
Accessor for the Verse/Words arrays. For testing only


append

protected void append(com.eireneh.bible.book.BibleEle doc,
                      com.eireneh.bible.passage.VerseRange range)
               throws com.eireneh.bible.book.BookException
Part of the Bible interface - Get the text for this reference. Fetch the Bible text for a single reference from a PassageID and a Bible


createSearchCache

protected void createSearchCache()
                          throws com.eireneh.bible.book.BookException
Create a cache to speed up searches.


deleteSearchCache

protected void deleteSearchCache()
                          throws com.eireneh.bible.book.BookException
Create a cache to speed up searches.


getStartsWith

public java.lang.String[] getStartsWith(java.lang.String word)
                                 throws com.eireneh.bible.book.BookException
Find a list of words that start with the given word