Search in sources :

Example 6 with OsisWrapper

use of com.tyndalehouse.step.core.models.OsisWrapper in project step by STEPBible.

the class SubjectEntryServiceImpl method collectVersesFromReferences.

/**
 * Collects individual ranges
 *
 * @param verses                 the verses
 * @param inputVersions          the versions
 * @param references             the list of resultsInKJV that form the results
 * @param limitingScopeReference the limiting scope for the reference
 * @param context                the context to expand with the reference
 */
private boolean collectVersesFromReferences(final List<OsisWrapper> verses, final String[] inputVersions, final String references, final String limitingScopeReference, final int context) {
    final String originalMaster = inputVersions[0];
    Passage combinedScopeInKJVv11n = this.getCombinedBookScope(inputVersions);
    // now let's retain the verses that are of interest in the selected books
    Key resultsInKJV = null;
    try {
        resultsInKJV = this.versificationService.getBookFromVersion(JSwordPassageService.BEST_VERSIFICATION).getKey(references);
    } catch (NoSuchKeyException e) {
        throw new StepInternalException("Unable to parse resultsInKJV from Nave", e);
    }
    resultsInKJV.retainAll(combinedScopeInKJVv11n);
    trimResultsToInputSearchRange(inputVersions[0], limitingScopeReference, resultsInKJV);
    // then calculate what the best version order is
    GetBestVersionOrderAndKey getBestVersionOrderAndKey = new GetBestVersionOrderAndKey(inputVersions, resultsInKJV).invoke();
    Book book = getBestVersionOrderAndKey.getBook();
    String[] versions = getBestVersionOrderAndKey.getVersions();
    final Passage resultsInProperV11n = getBestVersionOrderAndKey.getVerseRanges();
    final Iterator<VerseRange> rangeIterator = resultsInProperV11n.rangeIterator(RestrictionType.NONE);
    final List<LookupOption> options = new ArrayList<LookupOption>();
    options.add(LookupOption.HIDE_XGEN);
    options.add(LookupOption.GREEK_ACCENTS);
    options.add(LookupOption.HEBREW_VOWELS);
    if (context > 0) {
        // add verse numbers
        // options.add(LookupOption.TINY_VERSE_NUMBERS);
        options.add(LookupOption.VERSE_NUMBERS);
    }
    final Versification av11n = this.versificationService.getVersificationForVersion(book);
    Verse lastVerse = null;
    while (rangeIterator.hasNext()) {
        final Key range = rangeIterator.next();
        // get the distance between the first verse in the range and the last verse
        if (lastVerse != null && isCloseVerse(av11n, lastVerse, range)) {
            final OsisWrapper osisWrapper = verses.get(verses.size() - 1);
            final StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(osisWrapper.getReference());
            stringBuilder.append("; ");
            stringBuilder.append(range.getName());
            osisWrapper.setFragment(true);
            try {
                osisWrapper.setReference(book.getKey(stringBuilder.toString()).getName());
            } catch (final NoSuchKeyException e) {
                // fail to get a key, let's log and continue
                LOGGER.warn("Unable to get key for reference: [{}]", osisWrapper.getReference());
                LOGGER.trace("Root cause is", e);
            }
        } else {
            final Key firstVerse = this.jsword.getFirstVersesFromRange(range, context);
            final OsisWrapper passage = this.jsword.peakOsisText(versions, firstVerse, options, InterlinearMode.INTERLEAVED_COMPARE.name());
            passage.setReference(range.getName());
            if (range.getCardinality() > 1) {
                passage.setFragment(true);
            }
            verses.add(passage);
        }
        // record last verse
        if (range instanceof VerseRange) {
            final VerseRange verseRange = (VerseRange) range;
            lastVerse = verseRange.getEnd();
        } else if (range instanceof Verse) {
            lastVerse = (Verse) range;
        }
    }
    return !getBestVersionOrderAndKey.versions[0].equals(originalMaster);
}
Also used : VerseRange(org.crosswire.jsword.passage.VerseRange) LookupOption(com.tyndalehouse.step.core.models.LookupOption) ArrayList(java.util.ArrayList) Versification(org.crosswire.jsword.versification.Versification) Passage(org.crosswire.jsword.passage.Passage) RangedPassage(org.crosswire.jsword.passage.RangedPassage) NoSuchKeyException(org.crosswire.jsword.passage.NoSuchKeyException) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) Book(org.crosswire.jsword.book.Book) Key(org.crosswire.jsword.passage.Key) VerseKey(org.crosswire.jsword.passage.VerseKey) Verse(org.crosswire.jsword.passage.Verse) OsisWrapper(com.tyndalehouse.step.core.models.OsisWrapper)

Example 7 with OsisWrapper

use of com.tyndalehouse.step.core.models.OsisWrapper in project step by STEPBible.

the class JSwordPassageServiceImplTest method testColorCoding.

/**
 * Test for bug TYNSTEP-378
 */
@Test
public void testColorCoding() {
    final List<LookupOption> options = new ArrayList<LookupOption>();
    options.add(LookupOption.COLOUR_CODE);
    final OsisWrapper osisText = this.jsi.getOsisText("KJV", "Gen.1.1", options, null, InterlinearMode.NONE);
    assertTrue(osisText.getValue().contains("In the beginning"));
}
Also used : LookupOption(com.tyndalehouse.step.core.models.LookupOption) ArrayList(java.util.ArrayList) OsisWrapper(com.tyndalehouse.step.core.models.OsisWrapper) Test(org.junit.Test)

Example 8 with OsisWrapper

use of com.tyndalehouse.step.core.models.OsisWrapper in project step by STEPBible.

the class JSwordPassageServiceImplTest method testInterleave.

/**
 * Justs shows XML on the stdout
 *
 * @throws BookException      an exceptioon
 * @throws NoSuchKeyException an exception
 * @throws IOException        an exception
 * @throws JDOMException      an exception
 */
@Test
public void testInterleave() throws BookException, NoSuchKeyException, JDOMException, IOException {
    final XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
    final String ref = "John 4:1";
    // do the test
    final String[] versions = new String[] { "Byz", "Tisch" };
    final BookData data = new BookData(new Book[] { Books.installed().getBook(versions[0]), Books.installed().getBook(versions[1]) }, Books.installed().getBook(versions[0]).getKey(ref), true);
    LOGGER.debug("Original is:\n {}", xmlOutputter.outputString(data.getOsisFragment()));
    final OsisWrapper interleavedVersions = this.jsi.getInterleavedVersions(versions, ref, new ArrayList<LookupOption>(), InterlinearMode.COLUMN_COMPARE, "en");
    final SAXBuilder sb = new SAXBuilder();
    final Document d = sb.build(new StringReader(interleavedVersions.getValue()));
    LOGGER.debug("\n {}", xmlOutputter.outputString(d));
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) SAXBuilder(org.jdom2.input.SAXBuilder) LookupOption(com.tyndalehouse.step.core.models.LookupOption) StringReader(java.io.StringReader) BookData(org.crosswire.jsword.book.BookData) Document(org.jdom2.Document) OsisWrapper(com.tyndalehouse.step.core.models.OsisWrapper) Test(org.junit.Test)

Example 9 with OsisWrapper

use of com.tyndalehouse.step.core.models.OsisWrapper in project step by STEPBible.

the class JSwordPassageServiceImplTest method testColorCodingInterlinear.

/**
 * Baseline for bug TYNSTEP-378, checking that in interlinear colour coding still works.
 */
@Test
public void testColorCodingInterlinear() {
    final List<LookupOption> options = new ArrayList<LookupOption>();
    options.add(LookupOption.COLOUR_CODE);
    options.add(LookupOption.INTERLINEAR);
    final OsisWrapper osisText = this.jsi.getOsisText("KJV", "Gen.1.1", options, "KJV", InterlinearMode.INTERLINEAR);
    assertTrue(osisText.getValue().contains("In the beginning"));
}
Also used : LookupOption(com.tyndalehouse.step.core.models.LookupOption) ArrayList(java.util.ArrayList) OsisWrapper(com.tyndalehouse.step.core.models.OsisWrapper) Test(org.junit.Test)

Example 10 with OsisWrapper

use of com.tyndalehouse.step.core.models.OsisWrapper in project step by STEPBible.

the class JSwordPassageServiceImplTest method testSegVariants.

/**
 * Justs shows XML on the stdout
 *
 * @throws BookException      an exceptioon
 * @throws NoSuchKeyException an exception
 * @throws IOException        an exception
 * @throws JDOMException      an exception
 */
@Test
public void testSegVariants() throws BookException, NoSuchKeyException, JDOMException, IOException {
    final XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
    final String ref = "Mat.9.4";
    final String version = "WHNU";
    final Book book = Books.installed().getBook(version);
    // do the test
    final BookData data = new BookData(book, book.getKey(ref));
    LOGGER.info("Original is:\n {}", xmlOutputter.outputString(data.getOsisFragment()));
    final OsisWrapper interleavedVersions = this.jsi.getOsisText(version, ref);
    final SAXBuilder sb = new SAXBuilder();
    final Document d = sb.build(new StringReader(interleavedVersions.getValue()));
    final String outputString = xmlOutputter.outputString(d);
    LOGGER.info(outputString);
    assertTrue(outputString.contains("ειδως"));
    assertTrue(outputString.contains("title=\"ιδων"));
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) SAXBuilder(org.jdom2.input.SAXBuilder) BibleBook(org.crosswire.jsword.versification.BibleBook) Book(org.crosswire.jsword.book.Book) StringReader(java.io.StringReader) BookData(org.crosswire.jsword.book.BookData) Document(org.jdom2.Document) OsisWrapper(com.tyndalehouse.step.core.models.OsisWrapper) Test(org.junit.Test)

Aggregations

OsisWrapper (com.tyndalehouse.step.core.models.OsisWrapper)13 LookupOption (com.tyndalehouse.step.core.models.LookupOption)7 ArrayList (java.util.ArrayList)6 StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)4 Book (org.crosswire.jsword.book.Book)4 Test (org.junit.Test)4 Key (org.crosswire.jsword.passage.Key)3 BibleBook (org.crosswire.jsword.versification.BibleBook)3 LocalisedException (com.tyndalehouse.step.core.exceptions.LocalisedException)2 EnrichedLookupOption (com.tyndalehouse.step.core.models.EnrichedLookupOption)2 InterlinearMode (com.tyndalehouse.step.core.models.InterlinearMode)2 TrimmedLookupOption (com.tyndalehouse.step.core.models.TrimmedLookupOption)2 StringReader (java.io.StringReader)2 TransformerException (javax.xml.transform.TransformerException)2 TransformingSAXEventProvider (org.crosswire.common.xml.TransformingSAXEventProvider)2 XMLUtil.writeToString (org.crosswire.common.xml.XMLUtil.writeToString)2 BookData (org.crosswire.jsword.book.BookData)2 BookException (org.crosswire.jsword.book.BookException)2 NoSuchKeyException (org.crosswire.jsword.passage.NoSuchKeyException)2 Passage (org.crosswire.jsword.passage.Passage)2