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);
}
}
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);
}
}
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;
}
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);
}
}
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());
}
}
Aggregations