use of com.tyndalehouse.step.core.models.OsisWrapper 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);
}
use of com.tyndalehouse.step.core.models.OsisWrapper 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"));
}
use of com.tyndalehouse.step.core.models.OsisWrapper 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));
}
use of com.tyndalehouse.step.core.models.OsisWrapper 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"));
}
use of com.tyndalehouse.step.core.models.OsisWrapper in project step by STEPBible.
the class JSwordPassageServiceImplTest method testSegVariants.
/**
* 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 testSegVariants() throws BookException, NoSuchKeyException, JDOMException, IOException {
final XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());
final String ref = "Mat.9.4";
final String version = "WHNU";
final Book book = Books.installed().getBook(version);
// do the test
final BookData data = new BookData(book, book.getKey(ref));
LOGGER.info("Original is:\n {}", xmlOutputter.outputString(data.getOsisFragment()));
final OsisWrapper interleavedVersions = this.jsi.getOsisText(version, ref);
final SAXBuilder sb = new SAXBuilder();
final Document d = sb.build(new StringReader(interleavedVersions.getValue()));
final String outputString = xmlOutputter.outputString(d);
LOGGER.info(outputString);
assertTrue(outputString.contains("ειδως"));
assertTrue(outputString.contains("title=\"ιδων"));
}
Aggregations