[jsword-devel] SimpleOsisParser - parsing whole chapter refs
DM Smith
dmsmith at crosswire.org
Sat Feb 7 05:51:11 MST 2015
I've committed this change to JSword.
Thanks!
In Him,
DM
> On Sep 11, 2014, at 5:27 PM, Martin Denham <mjdenham at gmail.com> wrote:
>
> There was a more flexible way to create this parser. The previous was rather fussy about the ids passed in. This new version (attached) should handle all combinations:
>
> @Test
> public void testChapterParsing() {
> assertEquals("Gen.1", osisParser.parseOsisRef(testV11n, "Gen.1").getOsisRef());
> assertEquals("Mark.10", osisParser.parseOsisRef(testV11n, "Mark.10").getOsisRef());
> assertEquals("Gen.1-Gen.3", osisParser.parseOsisRef(testV11n, "Gen.1-Gen.3").getOsisRef());
> assertEquals("Obad", osisParser.parseOsisRef(testV11n, "Obad.1").getOsisRef());
> assertEquals("Obad", osisParser.parseOsisRef(testV11n, "Obad").getOsisRef());
> assertEquals("Gen", osisParser.parseOsisRef(testV11n, "Gen").getOsisRef());
> }
>
> @Test
> public void testMixedLengthParsing() {
> assertEquals("Gen-Exod.1", osisParser.parseOsisRef(testV11n, "Gen-Exod.1").getOsisRef());
> assertEquals("Gen.2-Gen.3", osisParser.parseOsisRef(testV11n, "Gen.2.1-Gen.3").getOsisRef());
> assertEquals("Gen.1-Gen.3", osisParser.parseOsisRef(testV11n, "Gen-Gen.3").getOsisRef());
> assertEquals("Gen.1-Gen.3.4", osisParser.parseOsisRef(testV11n, "Gen-Gen.3.4").getOsisRef());
> assertEquals("Gen.3.4-Exod", osisParser.parseOsisRef(testV11n, "Gen.3.4-Exod").getOsisRef());
> }
>
> Comments?
>
> Cheers
> Martin
>
>
> On 2 September 2014 18:02, Martin Denham <mjdenham at gmail.com <mailto:mjdenham at gmail.com>> wrote:
> Hi DM,
>
> There is a unit test attached to the previous e-mail that covers the scenarios you have mentioned:
> @Test
> public void testChapterParsing() {
> assertEquals("Gen.1", SimpleOsisParser.parseOsisRef(testV11n, "Gen.1").getOsisRef());
> assertEquals("Mark.10", SimpleOsisParser.parseOsisRef(testV11n, "Mark.10").getOsisRef());
> assertEquals("Gen.1-Gen.3", SimpleOsisParser.parseOsisRef(testV11n, "Gen.1-Gen.3").getOsisRef());
> assertEquals("Obad", SimpleOsisParser.parseOsisRef(testV11n, "Obad.1").getOsisRef());
> }
>
> One assumption is that chapters start with verse 1, although this could probably be changed to assume they start with verse 0 if that is correct.
>
> Cheers
> Martin
>
>
> On 1 September 2014 16:22, DM Smith <dmsmith at crosswire.org <mailto:dmsmith at crosswire.org>> wrote:
> Meant to respond to your first email. This is needed. Hope to review it soon. Work is crazy.
>
> The challenge with interpreting Gen.1 is that you have to know if it stands alone is the left part of a range or the right part of the range. When it stands alone it refers to the whole chapter, when it is the first part of a range it means the first verse of the chapter and if is the end of the range then it is the last verse of the range.
>
> We also have the complication that of what the first verse or the whole chapter means. Does it include verse 0?
>
> Since the start and the end of an OSIS range have to be valid OSIS refs the parsing of a range is much easier than user input ranges which might be like Gen 1:2-5. The -5 is ambiguous and has to be interpreted in context of what stands in front of it.
>
> -- DM
>
> On Aug 30, 2014, at 3:05 PM, Martin Denham <mjdenham at gmail.com <mailto:mjdenham at gmail.com>> wrote:
>
>> I have taken a stab at adding the above functionality to SimpleOsisParser so that it can also parse refs like 'Gen.1', 'Gen.1-Gen.3', 'Obad.1'. I would like to make the methods non-static but tried to make as few changes as possible to the existing code but it may be that this enhancement necessitates some refactoring.
>>
>> Can somebody review the attached code and say if it is acceptable?
>>
>> Martin
>>
>>
>> On 30 August 2014 15:23, Martin Denham <mjdenham at gmail.com <mailto:mjdenham at gmail.com>> wrote:
>> Hi,
>>
>> Are there any plans to extend the SimpleOsisParser to be able to parse chapter references like "Gen.1" instead of just verse references e.g. "Gen.1.1" or verse range references e.g. "Gen.1.1-Gen.1.3"?
>>
>> The following fails so I can't parse a reference to the whole of Genesis 1 easily:
>>
>> assertEquals("Gen.1", SimpleOsisParser.parseOsisRef(testV11n, "Gen.1").getOsisRef());
>>
>> other than by entering "Gen.1.1-Gen.1.31" which, funnily enough, returns the Osis I originally tried to enter "Gen.1".
>>
>> Martin
>>
>> <SimpleOsisParser.java><SimpleOsisIDParserTest.java>_______________________________________________
>> jsword-devel mailing list
>> jsword-devel at crosswire.org <mailto:jsword-devel at crosswire.org>
>> http://www.crosswire.org/mailman/listinfo/jsword-devel <http://www.crosswire.org/mailman/listinfo/jsword-devel>
>
>
> _______________________________________________
> jsword-devel mailing list
> jsword-devel at crosswire.org <mailto:jsword-devel at crosswire.org>
> http://www.crosswire.org/mailman/listinfo/jsword-devel <http://www.crosswire.org/mailman/listinfo/jsword-devel>
>
>
>
> <OsisParser.java><OsisParserTest.java>_______________________________________________
> 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/20150207/76c36831/attachment-0001.html>
More information about the jsword-devel
mailing list