Search in sources :

Example 6 with LookupOption

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

the class JSwordPassageServiceImpl method identifyStyleSheet.

/**
 * At the moment, we only support one stylesheet at the moment, so we only need to return one This may change, but
 * at that point we'll have a cleared view on requirements. For now, if one of the options triggers anything but the
 * default, then we return that. returns the stylesheet that should be used to generate the text
 *
 * @param options     the list of options that are currently applied to the passage
 * @param displayMode the display mode with wich to display the style sheet
 * @return the stylesheet (of stylesheets)
 */
private XslConversionType identifyStyleSheet(final List<LookupOption> options, final InterlinearMode displayMode) {
    // for interlinears, we automatically add that option
    if (displayMode == InterlinearMode.INTERLINEAR) {
        options.add(LookupOption.INTERLINEAR);
    }
    for (final LookupOption lo : options) {
        // trim() in BibleInformationServiceImpl
        if (!XslConversionType.DEFAULT.equals(lo.getStylesheet())) {
            if (XslConversionType.INTERLINEAR.equals(lo.getStylesheet())) {
                options.add(LookupOption.CHAPTER_VERSE);
                // FIXME: also remove headers, as not yet supported
                options.remove(LookupOption.HEADINGS);
            }
            return lo.getStylesheet();
        }
    }
    return XslConversionType.DEFAULT;
}
Also used : LookupOption(com.tyndalehouse.step.core.models.LookupOption)

Example 7 with LookupOption

use of com.tyndalehouse.step.core.models.LookupOption 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 8 with LookupOption

use of com.tyndalehouse.step.core.models.LookupOption 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 9 with LookupOption

use of com.tyndalehouse.step.core.models.LookupOption 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 10 with LookupOption

use of com.tyndalehouse.step.core.models.LookupOption 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)

Aggregations

LookupOption (com.tyndalehouse.step.core.models.LookupOption)20 ArrayList (java.util.ArrayList)11 OsisWrapper (com.tyndalehouse.step.core.models.OsisWrapper)7 Book (org.crosswire.jsword.book.Book)7 BookData (org.crosswire.jsword.book.BookData)6 SAXBuilder (org.jdom2.input.SAXBuilder)6 XMLOutputter (org.jdom2.output.XMLOutputter)6 Test (org.junit.Test)6 TrimmedLookupOption (com.tyndalehouse.step.core.models.TrimmedLookupOption)5 StringReader (java.io.StringReader)5 Document (org.jdom2.Document)5 Element (org.jdom2.Element)5 BibleBook (org.crosswire.jsword.versification.BibleBook)4 EnrichedLookupOption (com.tyndalehouse.step.core.models.EnrichedLookupOption)3 InterlinearMode (com.tyndalehouse.step.core.models.InterlinearMode)3 StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)2 JSwordPassageServiceImpl (com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl)2 HashSet (java.util.HashSet)2 AbstractPassageBook (org.crosswire.jsword.book.basic.AbstractPassageBook)2 Key (org.crosswire.jsword.passage.Key)2