Search in sources :

Example 1 with Key

use of org.crosswire.jsword.passage.Key in project step by STEPBible.

the class JSwordRelatedVersesServiceImpl method getRelatedVerses.

@Override
public Key getRelatedVerses(final String version, final String key) {
    try {
        // target book, and intermediary strong book
        final Book targetBook = jSwordVersificationService.getBookFromVersion(version);
        final Book strongBook = jSwordMetadataService.supportsStrongs(targetBook) ? targetBook : jSwordVersificationService.getBookFromVersion(JSwordPassageService.REFERENCE_BOOK);
        // target and strong key
        final Key targetKey = targetBook.getKey(key);
        final Key strongKey = VersificationsMapper.instance().map(KeyUtil.getPassage(targetKey), jSwordVersificationService.getVersificationForVersion(strongBook));
        // get list of strong numbers
        final String[] strongs = this.getStrongsFromKey(new BookData(strongBook, strongKey));
        final IndexSearcher is = jSwordSearchService.getIndexSearcher(strongBook.getInitials());
        final List<String> filteredStrongs = keepInfrequentStrongs(strongs, is);
        return targetBook.getKey(getRelatedVerseReference(filteredStrongs, is));
    } catch (final NoSuchKeyException ex) {
        throw new StepInternalException(ex.getMessage(), ex);
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) NoSuchKeyException(org.crosswire.jsword.passage.NoSuchKeyException) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) Book(org.crosswire.jsword.book.Book) BookData(org.crosswire.jsword.book.BookData) Key(org.crosswire.jsword.passage.Key)

Example 2 with Key

use of org.crosswire.jsword.passage.Key in project step by STEPBible.

the class JSwordPassageServiceImpl method getSiblingChapter.

@Override
public KeyWrapper getSiblingChapter(final String reference, final String version, final boolean previousChapter) {
    // getting the next chapter
    // FIXME find a way of getting the next chapter from the current key, in the current book, rather than
    // relying on versification systems which may contain verses that the Book does not support
    final Book currentBook = this.versificationService.getBookFromVersion(version);
    final Versification v11n = this.versificationService.getVersificationForVersion(currentBook);
    try {
        final Key key = currentBook.getKey(reference);
        return getSiblingChapter(previousChapter, currentBook, v11n, key);
    } catch (final NoSuchKeyException e) {
        throw new TranslatedException(e, "invalid_reference_in_book", reference, version);
    }
}
Also used : NoSuchKeyException(org.crosswire.jsword.passage.NoSuchKeyException) TranslatedException(com.tyndalehouse.step.core.exceptions.TranslatedException) BibleBook(org.crosswire.jsword.versification.BibleBook) Book(org.crosswire.jsword.book.Book) Versification(org.crosswire.jsword.versification.Versification) Key(org.crosswire.jsword.passage.Key)

Example 3 with Key

use of org.crosswire.jsword.passage.Key in project step by STEPBible.

the class JSwordPassageServiceImpl method setInterlinearOptions.

/**
 * sets up the default interlinear options
 *
 * @param tsep                the transformer that we want to set up
 * @param masterVersion       the master version for this lookup
 * @param masterVersification the versification of the top line
 * @param interlinearVersion  the interlinear version(s) that the users have requested
 * @param reference           the reference the user is interested in
 * @param displayMode         the mode to display the passage, i.e. interlinear, interleaved, etc.
 * @param key                 the key to the passage
 * @param options             the list of options to be applied (used to determine accenting
 */
private MultiInterlinearProvider setInterlinearOptions(final TransformingSAXEventProvider tsep, final String masterVersion, final Versification masterVersification, final String interlinearVersion, final String reference, final InterlinearMode displayMode, final Key key, final List<LookupOption> options) {
    if (displayMode == InterlinearMode.INTERLINEAR) {
        tsep.setParameter("VLine", false);
        // TODO: work out OT or NT
        Iterator<Key> keys = key.iterator();
        if (keys.hasNext()) {
            Key firstKey = keys.next();
            if (firstKey instanceof Verse) {
                final Verse verse = (Verse) firstKey;
                Testament t = masterVersification.getTestament(verse.getOrdinal());
                tsep.setParameter("isOT", t == Testament.OLD);
            }
        }
        if (isNotBlank(interlinearVersion)) {
            tsep.setParameter("interlinearVersion", interlinearVersion);
        }
        boolean stripGreekAccents, stripHebrewAccents, stripVowels = stripHebrewAccents = stripGreekAccents = true;
        for (LookupOption option : options) {
            if (LookupOption.GREEK_ACCENTS == option) {
                stripGreekAccents = false;
            } else if (LookupOption.HEBREW_ACCENTS == option) {
                stripHebrewAccents = false;
            } else if (LookupOption.HEBREW_VOWELS == option) {
                stripVowels = false;
            }
        }
        final MultiInterlinearProviderImpl multiInterlinear = new MultiInterlinearProviderImpl(masterVersion, masterVersification, interlinearVersion, reference, this.versificationService, this.vocabProvider, stripGreekAccents, stripHebrewAccents, stripVowels);
        tsep.setParameter("interlinearProvider", multiInterlinear);
        return multiInterlinear;
    }
    return null;
}
Also used : MultiInterlinearProviderImpl(com.tyndalehouse.step.core.xsl.impl.MultiInterlinearProviderImpl) LookupOption(com.tyndalehouse.step.core.models.LookupOption) Key(org.crosswire.jsword.passage.Key) Verse(org.crosswire.jsword.passage.Verse) Testament(org.crosswire.jsword.versification.Testament)

Example 4 with Key

use of org.crosswire.jsword.passage.Key in project step by STEPBible.

the class JSwordPassageServiceImpl method getBookDataByKey.

/**
 * Gets the BookData set up for verse retrieval
 *
 * @param version the version to be used
 * @param key     the reference
 * @return the BookData object
 */
BookData getBookDataByKey(final String version, final Key key) {
    final Book currentBook = this.versificationService.getBookFromVersion(version);
    final Versification v11n = this.versificationService.getVersificationForVersion(currentBook);
    try {
        Key copyOfKey = normalize(key, v11n);
        return new BookData(currentBook, copyOfKey);
    } catch (final NoSuchKeyException e) {
        return handlePassageLookupNSKException(key.getName(), currentBook, v11n, e);
    }
}
Also used : NoSuchKeyException(org.crosswire.jsword.passage.NoSuchKeyException) BibleBook(org.crosswire.jsword.versification.BibleBook) Book(org.crosswire.jsword.book.Book) Versification(org.crosswire.jsword.versification.Versification) BookData(org.crosswire.jsword.book.BookData) Key(org.crosswire.jsword.passage.Key)

Example 5 with Key

use of org.crosswire.jsword.passage.Key in project step by STEPBible.

the class JSwordPassageServiceImpl method doInterleavedVersionsLookup.

private OsisWrapper doInterleavedVersionsLookup(String[] versions, final BookData data, final Versification v11n, final List<LookupOption> options, final InterlinearMode displayMode, final String userLanguage) {
    Book[] books = data.getBooks();
    try {
        setUnaccenter(data, displayMode);
        final TransformingSAXEventProvider transformer = executeStyleSheet(v11n, options, null, data, data.getSAXEventProvider(), displayMode, userLanguage);
        String[] languages = new String[books.length];
        for (int ii = 0; ii < books.length; ii++) {
            languages[ii] = books[ii].getLanguage().getCode();
        }
        final Key key = data.getKey();
        return new OsisWrapper(writeToString(transformer), key, languages, v11n, resolver.getShortName(versions[0]), displayMode, StringUtils.join(versions, 1));
    } catch (final TransformerException e) {
        throw new StepInternalException(e.getMessage(), e);
    } catch (final SAXException e) {
        throw new StepInternalException(e.getMessage(), e);
    } catch (final BookException e) {
        throw new LocalisedException(e, e.getMessage());
    }
}
Also used : BookException(org.crosswire.jsword.book.BookException) XMLUtil.writeToString(org.crosswire.common.xml.XMLUtil.writeToString) SAXException(org.xml.sax.SAXException) LocalisedException(com.tyndalehouse.step.core.exceptions.LocalisedException) TransformingSAXEventProvider(org.crosswire.common.xml.TransformingSAXEventProvider) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) BibleBook(org.crosswire.jsword.versification.BibleBook) Book(org.crosswire.jsword.book.Book) Key(org.crosswire.jsword.passage.Key) OsisWrapper(com.tyndalehouse.step.core.models.OsisWrapper) TransformerException(javax.xml.transform.TransformerException)

Aggregations

Key (org.crosswire.jsword.passage.Key)34 Book (org.crosswire.jsword.book.Book)19 NoSuchKeyException (org.crosswire.jsword.passage.NoSuchKeyException)13 BibleBook (org.crosswire.jsword.versification.BibleBook)12 Versification (org.crosswire.jsword.versification.Versification)11 BookData (org.crosswire.jsword.book.BookData)9 StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)8 Verse (org.crosswire.jsword.passage.Verse)8 TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)7 Passage (org.crosswire.jsword.passage.Passage)6 VerseKey (org.crosswire.jsword.passage.VerseKey)6 BookException (org.crosswire.jsword.book.BookException)4 VerseRange (org.crosswire.jsword.passage.VerseRange)4 EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)3 LocalisedException (com.tyndalehouse.step.core.exceptions.LocalisedException)3 KeyWrapper (com.tyndalehouse.step.core.models.KeyWrapper)3 OsisWrapper (com.tyndalehouse.step.core.models.OsisWrapper)3 File (java.io.File)3 HashMap (java.util.HashMap)3 RangedPassage (org.crosswire.jsword.passage.RangedPassage)3