use of com.tyndalehouse.step.core.models.LookupOption in project step by STEPBible.
the class PassageOptionsValidationServiceImpl method getUserOptionsForVersion.
/**
* Given a set of options selected by the user and a verson, retrieves the options that are actually available
*
* @param errors the error messages
* @param options the options given by the user
* @param version the version of interest
* @param extraVersions the secondary versions that affect feature resolution
* @param trimmingExplanations the explanations of why options are being removed
* @return a potentially smaller set of options that are actually possible
*/
private Set<LookupOption> getUserOptionsForVersion(final ResourceBundle errors, final List<LookupOption> options, final String version, final List<String> extraVersions, final List<TrimmedLookupOption> trimmingExplanations) {
final Set<LookupOption> available = this.jswordMetadata.getFeatures(version, extraVersions);
final Set<LookupOption> result = new HashSet<>(options.size());
// do a crazy bubble intersect, but it's tiny so that's fine
for (final LookupOption loOption : options) {
boolean added = false;
for (final LookupOption avOption : available) {
if (loOption.equals(avOption)) {
result.add(loOption);
added = true;
break;
}
}
// option not available in that particular version
if (trimmingExplanations != null && !added) {
trimmingExplanations.add(new TrimmedLookupOption(errors.getString("option_not_supported_by_version"), loOption));
}
}
return result;
}
use of com.tyndalehouse.step.core.models.LookupOption in project step by STEPBible.
the class JSwordMetadataServiceImpl method getFeatures.
@Override
public Set<LookupOption> getFeatures(final String version, List<String> extraVersions) {
// obtain the book
final Book book = this.versificationService.getBookFromVersion(version);
final Set<LookupOption> options = new HashSet<LookupOption>(LookupOption.values().length * 2);
if (book == null) {
return options;
}
// some options are always there for Bibles:
addBibleCategoryOptions(book, options);
addRedLetterOptions(book, options);
addStrongNumberOptions(book, options);
addMorphologyOptions(book, options);
addNotesOptions(book, options);
addHebrewOptions(book, options);
addAncientOptions(version, extraVersions, options);
addMasterAncientOptions(book, options);
addAllMatchingLookupOptions(book, options);
addHiddenOptions(options);
return options;
}
use of com.tyndalehouse.step.core.models.LookupOption 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;
}
use of com.tyndalehouse.step.core.models.LookupOption 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;
}
use of com.tyndalehouse.step.core.models.LookupOption 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;
}
Aggregations