Search in sources :

Example 1 with InterlinearMode

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

the class BibleInformationServiceImpl method getPassageText.

/**
 * Gets the passage text.
 *
 * @param version            the version
 * @param reference          the reference
 * @param options            the options
 * @param interlinearVersion the interlinear version
 * @param interlinearMode    the interlinear mode
 * @return the passage text
 */
// TODO: this could be optimized. last call to get options is very  similar to 'getLookupOptions'
// as they share some of the same stuff.
@Override
@Timed(name = "passage-lookup", group = "service", rateUnit = TimeUnit.SECONDS, durationUnit = TimeUnit.MILLISECONDS)
public OsisWrapper getPassageText(final String version, final String reference, final String options, final String interlinearVersion, final String interlinearMode, final String userLanguage) {
    final List<String> extraVersions = getExtraVersionsFromString(interlinearVersion);
    final InterlinearMode desiredModeOfDisplay = this.optionsValidationService.getDisplayMode(interlinearMode, version, extraVersions);
    OsisWrapper passageText;
    final List<TrimmedLookupOption> removedOptions = new ArrayList<TrimmedLookupOption>(4);
    final List<LookupOption> inputLookupOptions = this.optionsValidationService.getLookupOptions(options);
    final InterlinearMode realModeOfDisplay = this.optionsValidationService.determineDisplayMode(inputLookupOptions, desiredModeOfDisplay, true);
    final Set<LookupOption> lookupOptions = this.optionsValidationService.trim(inputLookupOptions, version, extraVersions, desiredModeOfDisplay, realModeOfDisplay, removedOptions);
    if (INTERLINEAR != desiredModeOfDisplay && NONE != desiredModeOfDisplay) {
        // split the versions
        lookupOptions.add(LookupOption.VERSE_NUMBERS);
        final String[] versions = getInterleavedVersions(version, interlinearVersion);
        passageText = this.jswordPassage.getInterleavedVersions(versions, reference, new ArrayList<>(lookupOptions), desiredModeOfDisplay, userLanguage);
    } else {
        passageText = this.jswordPassage.getOsisText(version, reference, new ArrayList(lookupOptions), interlinearVersion, desiredModeOfDisplay);
    }
    passageText.setRemovedOptions(removedOptions);
    passageText.setPreviousChapter(this.jswordPassage.getSiblingChapter(passageText.getOsisId(), version, true));
    passageText.setNextChapter(this.jswordPassage.getSiblingChapter(passageText.getOsisId(), version, false));
    passageText.setOptions(this.optionsValidationService.optionsToString(this.optionsValidationService.getAvailableFeaturesForVersion(version, extraVersions, interlinearMode, realModeOfDisplay).getOptions()));
    // the passage lookup wasn't made with the removed options, however, the client needs to think these were selected.
    passageText.setSelectedOptions(this.optionsValidationService.optionsToString(lookupOptions) + getRemovedOptions(removedOptions));
    return passageText;
}
Also used : TrimmedLookupOption(com.tyndalehouse.step.core.models.TrimmedLookupOption) LookupOption(com.tyndalehouse.step.core.models.LookupOption) TrimmedLookupOption(com.tyndalehouse.step.core.models.TrimmedLookupOption) EnrichedLookupOption(com.tyndalehouse.step.core.models.EnrichedLookupOption) ArrayList(java.util.ArrayList) InterlinearMode(com.tyndalehouse.step.core.models.InterlinearMode) OsisWrapper(com.tyndalehouse.step.core.models.OsisWrapper) Timed(com.yammer.metrics.annotation.Timed)

Example 2 with InterlinearMode

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

the class JSwordPassageServiceImpl method getPassageByDisplayMode.

public OsisWrapper getPassageByDisplayMode(List<String> versionsInput, Key reference, List<LookupOption> options, final String interlinearMode) {
    if (versionsInput.size() == 0) {
        throw new StepInternalException("No versions specified - app error?");
    }
    final String masterVersion = versionsInput.get(0);
    final List<String> extraVersions = this.getExtras(versionsInput);
    final InterlinearMode desiredModeOfDisplay = this.optionsValidationService.getDisplayMode(interlinearMode, masterVersion, extraVersions);
    final InterlinearMode realModeOfDisplay = this.optionsValidationService.determineDisplayMode(options, desiredModeOfDisplay, true);
    if (InterlinearMode.INTERLINEAR.equals(desiredModeOfDisplay) && options.contains(LookupOption.CHAPTER_BOOK_VERSE_NUMBER)) {
        // then we're in a search kind of lookup, so add proper verse numbers
        options.add(LookupOption.VERSE_NUMBERS);
    }
    OsisWrapper passageText;
    final Set<LookupOption> lookupOptions = this.optionsValidationService.trim(options, masterVersion, extraVersions, desiredModeOfDisplay, null);
    if (INTERLINEAR != desiredModeOfDisplay && NONE != desiredModeOfDisplay) {
        // split the versions
        passageText = this.getInterleavedVersions(versionsInput.toArray(new String[versionsInput.size()]), reference, new ArrayList<LookupOption>(lookupOptions), desiredModeOfDisplay, "en");
    } else {
        final String extraVersionsAsString = this.getVersionsAsStrings(extraVersions);
        passageText = this.getOsisText(masterVersion, reference, new ArrayList<LookupOption>(lookupOptions), extraVersionsAsString, desiredModeOfDisplay);
    }
    passageText.setOptions(this.optionsValidationService.optionsToString(this.optionsValidationService.getAvailableFeaturesForVersion(masterVersion, extraVersions, interlinearMode, realModeOfDisplay).getOptions()));
    // The following 15 lines are a patch for the lack of the Book name, chapter and verse for the deutrocanon books
    String tmp = passageText.getValue();
    int pos1 = tmp.indexOf("<span class='verseNumber'></span>");
    if (pos1 > -1) {
        String curOsisId = passageText.getOsisId();
        int pos2 = curOsisId.indexOf(".");
        if (pos2 > 0) {
            String OsisBookName = " " + curOsisId.substring(0, pos2).toLowerCase() + " ";
            String otherBooks = " 1esd 2esd tob jdt addesth wis sir bar prazar sus bel prman 1macc 2macc esthgr addps 3macc 4macc ";
            if (otherBooks.indexOf(OsisBookName) > -1) {
                pos1 += 26;
                passageText.setValue(tmp.substring(0, pos1) + curOsisId + tmp.substring(pos1));
            }
        }
    }
    passageText.setSelectedOptions(this.optionsValidationService.optionsToString(lookupOptions));
    return passageText;
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) LookupOption(com.tyndalehouse.step.core.models.LookupOption) ArrayList(java.util.ArrayList) XMLUtil.writeToString(org.crosswire.common.xml.XMLUtil.writeToString) InterlinearMode(com.tyndalehouse.step.core.models.InterlinearMode) OsisWrapper(com.tyndalehouse.step.core.models.OsisWrapper)

Example 3 with InterlinearMode

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

the class InterleavedOsisReader method main.

/**
 * Just shows XML on the stdout
 *
 * @param args not used
 * @throws Exception any kind of exception
 */
public static void main(final String[] args) throws Exception {
    final String[] versions = new String[] { "OSMHB", "ESV_th" };
    final String ref = "Mic.5";
    final boolean unicodeBreakDown = false;
    final boolean compare = true;
    final InterlinearMode interlinearMode = InterlinearMode.INTERLEAVED;
    boolean format = false;
    final Format prettyFormat = format ? Format.getPrettyFormat() : Format.getRawFormat();
    final Book currentBook = Books.installed().getBook(versions[0]);
    final Book[] books = new Book[versions.length];
    for (int ii = 0; ii < versions.length; ii++) {
        books[ii] = Books.installed().getBook(versions[ii]);
    }
    final BookData bookData = new BookData(books, currentBook.getKey(ref), compare);
    final Element osisFragment = bookData.getOsisFragment();
    final XMLOutputter xmlOutputter = new XMLOutputter(prettyFormat);
    final String inputString = xmlOutputter.outputString(osisFragment);
    LOGGER.debug(inputString);
    if (unicodeBreakDown) {
        outputUnicode(inputString);
    }
    // do the test
    final JSwordPassageServiceImpl jsi = new JSwordPassageServiceImpl(TestUtils.mockVersificationService(), null, null, null, TestUtils.mockVersionResolver(), null);
    final List<LookupOption> options = new ArrayList<LookupOption>();
    options.add(LookupOption.CHAPTER_BOOK_VERSE_NUMBER);
    // options.add(LookupOption.HEADINGS_ONLY);
    // options.add(LookupOption.HEADINGS);
    // options.add(LookupOption.CHAPTER_BOOK_VERSE_NUMBER);
    final String osisText = jsi.getInterleavedVersions(versions, ref, options, interlinearMode, "en").getValue();
    LOGGER.debug(osisText);
    final SAXBuilder sb = new SAXBuilder();
    if (unicodeBreakDown) {
        outputUnicode(osisText);
    }
}
Also used : JSwordPassageServiceImpl(com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl) XMLOutputter(org.jdom2.output.XMLOutputter) SAXBuilder(org.jdom2.input.SAXBuilder) LookupOption(com.tyndalehouse.step.core.models.LookupOption) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Format(org.jdom2.output.Format) Book(org.crosswire.jsword.book.Book) InterlinearMode(com.tyndalehouse.step.core.models.InterlinearMode) BookData(org.crosswire.jsword.book.BookData)

Aggregations

InterlinearMode (com.tyndalehouse.step.core.models.InterlinearMode)3 LookupOption (com.tyndalehouse.step.core.models.LookupOption)3 ArrayList (java.util.ArrayList)3 OsisWrapper (com.tyndalehouse.step.core.models.OsisWrapper)2 StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)1 EnrichedLookupOption (com.tyndalehouse.step.core.models.EnrichedLookupOption)1 TrimmedLookupOption (com.tyndalehouse.step.core.models.TrimmedLookupOption)1 JSwordPassageServiceImpl (com.tyndalehouse.step.core.service.jsword.impl.JSwordPassageServiceImpl)1 Timed (com.yammer.metrics.annotation.Timed)1 XMLUtil.writeToString (org.crosswire.common.xml.XMLUtil.writeToString)1 Book (org.crosswire.jsword.book.Book)1 BookData (org.crosswire.jsword.book.BookData)1 Element (org.jdom2.Element)1 SAXBuilder (org.jdom2.input.SAXBuilder)1 Format (org.jdom2.output.Format)1 XMLOutputter (org.jdom2.output.XMLOutputter)1