[jsword-devel] Valid module keys

Greg Hellings greg.hellings at gmail.com
Sat Jan 11 22:30:32 MST 2014


On Sat, Jan 11, 2014 at 9:30 PM, DM Smith <dmsmith at crosswire.org> wrote:

>
> On Jan 11, 2014, at 9:48 PM, Greg Hellings <greg.hellings at gmail.com>
> wrote:
>
> for (Key key : book.getKey(requestedReference)) {
>     BookData data = new BookData(book, key);
>
>     System.out.println(OSISUtil.getCanonicalText(data.getOSISFragment()));
> }
>
> This works fine for Bibles. I can iterate a single chapter, verse range,
> book, etc in a Bible. I can get out any entry in a Dictionary. I can even
> get the contents of a Gen Book if that sub-tree is only one level deep.
> E.g. I can get out Pilgrim's Progress 'SOURCE' section or 'TITLE' section.
> But I can't get out 'THE_AUTHOR'S_APOLOGY_FOR_HIS_BOOK' or 'PART_I'. Both
> of them throw a NoSuchKeyException, although getGlobalKeyList() returned a
> key whose OSIS ID claims to be equal to that string. Am I doing something
> wrong here, or breaking some sort of assumption about module types?
>
>
> From memory:
>
> The basic idea is that *a* key is either a leaf node or it can have (i.e.
> has) children.
>
> So given a top level key. You'll need to ask it if it has children. If it
> does then you need to get them with that key's iterator.
>
> This is true of every key: it implements hasChildren() which is a test
> that is needed before getting the children. And there are a variety of ways
> to get the children.
>
> 1) By iterator (it has multiple semantic depending on whether a Key is a
> single item, a list or a node in a tree)
> 2) by number (with key.getChildCount(), key.get(n)) (You can also reverse
> the call of get(n) with key.indexOf(c))
>
> You'll either need recursion or a stack to do a depth first processing of
> the tree. I don't think we've had a use case for having that in JSword. So
> far getting the children has been by user demand.
>

This will be useful once I get the actual key.


>
> The string that is used for a key in a gen book is a path from the root. I
> forget the representation of the path. I don't remember if there is a
> lookup given a path.
>

It's this presentation that is tripping me up. To continue using Pilgrim's
Progress as an example, the following call works:

Book book = Books.installed().getBook("Pilgrim");
Key baseKey = book.getKey("SOURCE");

This call, prints out the exception message,
"org.crosswire.jsword.passage.NoSuchKeyException: No entry for 'PART_I' in
Pilgrim.":

Book book = Books.installed().getBook("Pilgrim");
Key baseKey = book.getKey("PART_I");

However, when I iterate the results of getGlobalKeyList I see PART_I listed
as a sub-key of the module. I'm guessing that in BibleDesktop you're
expanding a tree in the UI whose nodes already have a reference to the Key
itself, so you don't need to retrieve an arbitrary key out of a GenBook?
I'm looking at this from the context of a web service where a request could
come in with any arbitrary key depth.

--Greg


>
> Given the above it is pretty easy. Split the path into a list. Match at
> the top level, iterate over the children until a match of the next level
> and repeat until last level is processed.
>
> Hope this helps.
>
> And welcome to the JSword world.
>
> BTW, you may want to look at o.c.j.bridge and o.c.j.examples. For the most
> part I try to keep these up as a simple tutorial. Bridge is meant to be a
> collection of useful programs in their own right.
>
> In Him,
> DM
>
>
> _______________________________________________
> jsword-devel mailing list
> jsword-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/jsword-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.crosswire.org/pipermail/jsword-devel/attachments/20140111/4d1b3e5f/attachment.html>


More information about the jsword-devel mailing list