Search in sources :

Example 1 with KeyWrapper

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

the class AnalysisServiceImpl method getStatsForPassage.

@Override
public CombinedPassageStats getStatsForPassage(final String version, final String reference, final StatType statType, final ScopeType scopeType, boolean nextChapter, final String userLanguage, final boolean mostOccurrences) {
    final String keyResolutionVersion = statType == StatType.TEXT ? version : JSwordPassageService.REFERENCE_BOOK;
    final KeyWrapper centralReference = nextChapter ? jSwordPassageService.getSiblingChapter(reference, keyResolutionVersion, false) : jSwordPassageService.getKeyInfo(reference, keyResolutionVersion, keyResolutionVersion);
    final CombinedPassageStats statsForPassage = new CombinedPassageStats();
    PassageStat stat = null;
    String curBookName = "";
    switch(statType) {
        case WORD:
            if (scopeType == ScopeType.BOOK) {
                curBookName = getBookName(centralReference.getKey().getOsisID());
                if (!curBookName.equals("")) {
                    CombinedPassageStats cachedStatsForPassage = getPutBookAnalysisCache(curBookName, mostOccurrences, null);
                    if (cachedStatsForPassage != null) {
                        if ((!userLanguage.toLowerCase().startsWith("es")) && (!userLanguage.toLowerCase().startsWith("zh")))
                            return cachedStatsForPassage;
                        stat = cachedStatsForPassage.getPassageStat();
                    }
                }
            }
            if (stat == null) {
                stat = this.jswordAnalysis.getWordStats(centralReference.getKey(), scopeType, userLanguage);
                stat.trim(maxWords, mostOccurrences);
            }
            statsForPassage.setLexiconWords(convertWordStatsToDefinitions(stat, userLanguage));
            stat = this.bibleInformation.getArrayOfStrongNumbers(version, reference, stat, userLanguage);
            break;
        case TEXT:
            stat = this.jswordAnalysis.getTextStats(version, centralReference.getKey(), scopeType);
            stat.trim(maxWords, mostOccurrences);
            break;
        case SUBJECT:
            stat = getSubjectStats(version, centralReference.getName(), scopeType);
            stat.trim(maxWords, mostOccurrences);
            break;
        default:
            throw new StepInternalException("Unsupported type of stat asked for.");
    }
    stat.setReference(centralReference);
    statsForPassage.setPassageStat(stat);
    if ((scopeType == ScopeType.BOOK) && (!curBookName.equals("")) && (!userLanguage.toLowerCase().startsWith("es")) && (!userLanguage.toLowerCase().startsWith("zh")))
        getPutBookAnalysisCache(curBookName, mostOccurrences, statsForPassage);
    return statsForPassage;
}
Also used : KeyWrapper(com.tyndalehouse.step.core.models.KeyWrapper) CombinedPassageStats(com.tyndalehouse.step.core.models.stats.CombinedPassageStats) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) PassageStat(com.tyndalehouse.step.core.models.stats.PassageStat)

Example 2 with KeyWrapper

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

the class JSwordPassageServiceImpl method getSiblingChapter.

private KeyWrapper getSiblingChapter(final boolean previousChapter, final Book currentBook, final Versification v11n, final Key key) throws NoSuchKeyException {
    final Verse verse = KeyUtil.getVerse(previousChapter ? key : key.get(key.getCardinality() - 1));
    final int chapter = verse.getChapter();
    final BibleBook bibleBook = verse.getBook();
    Verse targetVerse;
    if (previousChapter) {
        if (chapter > 1) {
            targetVerse = new Verse(v11n, verse.getBook(), chapter - 1, 1);
        } else {
            // we go down a book
            final BibleBook previousBook = getNonIntroPreviousBook(bibleBook, v11n);
            if (previousBook == null) {
                BibleBook firstBook = getFirstNonIntroBook(v11n);
                targetVerse = new Verse(v11n, firstBook, 1, 1);
            } else {
                targetVerse = new Verse(v11n, previousBook, v11n.getLastChapter(previousBook), 1);
            }
        }
    } else {
        final int lastChapterInBook = v11n.getLastChapter(verse.getBook());
        if (chapter < lastChapterInBook) {
            targetVerse = new Verse(v11n, verse.getBook(), chapter + 1, 1);
        } else {
            // we go up a book
            final BibleBook nextBook = getNonIntroNextBook(bibleBook, v11n);
            if (nextBook == null) {
                final BibleBook lastBook = v11n.getLastBook();
                final int lastChapter = v11n.getLastChapter(lastBook);
                final int lastVerse = v11n.getLastVerse(lastBook, lastChapter);
                targetVerse = new Verse(v11n, lastBook, lastChapter, 1);
            } else {
                targetVerse = new Verse(v11n, nextBook, 1, 1);
            }
        }
    }
    // now we've got our target verse, use it, trim off the verse number
    final Key finalKey = currentBook.getKey(getChapter(targetVerse, v11n));
    final KeyWrapper keyWrapper = new KeyWrapper(finalKey);
    // check whether the target verse is in the last chapter
    if (v11n.getLastChapter(targetVerse.getBook()) == targetVerse.getChapter()) {
        keyWrapper.setLastChapter(true);
    }
    return keyWrapper;
}
Also used : BibleBook(org.crosswire.jsword.versification.BibleBook) KeyWrapper(com.tyndalehouse.step.core.models.KeyWrapper) Verse(org.crosswire.jsword.passage.Verse) Key(org.crosswire.jsword.passage.Key)

Example 3 with KeyWrapper

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

the class JSwordVersificationServiceImpl method convertReference.

@Override
public KeyWrapper convertReference(final String reference, final String sourceVersion, final String targetVersion) {
    final Versification source = this.getVersificationForVersion(sourceVersion);
    final Versification target = this.getVersificationForVersion(targetVersion);
    try {
        Passage p = PassageKeyFactory.instance().getKey(source, reference);
        return new KeyWrapper(VersificationsMapper.instance().map(p, target));
    } catch (NoSuchKeyException e) {
        throw new StepInternalException(e.getMessage(), e);
    }
}
Also used : KeyWrapper(com.tyndalehouse.step.core.models.KeyWrapper) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) Versification(org.crosswire.jsword.versification.Versification)

Example 4 with KeyWrapper

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

the class JSwordPassageServiceImpl method expandToChapter.

@Override
public KeyWrapper expandToChapter(final String version, final String reference) {
    final Key k = this.versificationService.getBookFromVersion(version).getValidKey(reference);
    k.blur(100, RestrictionType.CHAPTER);
    return new KeyWrapper(k);
}
Also used : KeyWrapper(com.tyndalehouse.step.core.models.KeyWrapper) Key(org.crosswire.jsword.passage.Key)

Example 5 with KeyWrapper

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

the class AnalysisServiceImpl method getReferenceSyntax.

/**
 * Creates a lucene query to allow search for multiple chapters/entire books, without generating
 * thousands of boolean queries, because we're expanding a book into all its verses!
 *
 * @param version   the version in which look up the key
 * @param scopeType the scope type
 */
private String getReferenceSyntax(final String reference, final String version, final ScopeType scopeType) {
    final KeyWrapper key = this.jSwordPassageService.getKeyInfo(reference, version, version);
    final Key total = key.getKey();
    StringBuilder sb = new StringBuilder(32);
    switch(scopeType) {
        case PASSAGE:
        case CHAPTER:
        case NEAR_BY_CHAPTER:
            // expand all the chapters....
            int minChapter = -1;
            int maxChapter = -1;
            Verse firstVerse = null;
            Verse lastVerse;
            // need to expand between chapters....
            final Iterator<Key> iterator = total.iterator();
            Verse v = null;
            while (iterator.hasNext()) {
                final Key next = iterator.next();
                if (next instanceof Verse) {
                    v = (Verse) next;
                    if (minChapter == -1) {
                        minChapter = v.getChapter();
                        firstVerse = v;
                    }
                    int currentChapter = v.getChapter();
                    if (currentChapter != maxChapter) {
                        sb.append(v.getBook().getOSIS());
                        sb.append('.');
                        sb.append(v.getChapter());
                        sb.append(".* ");
                    }
                    maxChapter = v.getChapter();
                }
            }
            lastVerse = v;
            // need to add +1 and -1
            if (scopeType == ScopeType.NEAR_BY_CHAPTER) {
                sb.append(firstVerse.getBook().getOSIS());
                sb.append('.');
                sb.append(minChapter - 1);
                sb.append(".* ");
                sb.append(lastVerse.getBook().getOSIS());
                sb.append('.');
                sb.append(minChapter - 1);
                sb.append(".* ");
            }
            break;
        case BOOK:
            Key k = key.getKey().get(0);
            if (k instanceof Verse) {
                sb.append(((Verse) k).getBook().getOSIS());
                sb.append(OSIS_CHAPTER_STARTS_WITH);
            }
            break;
        default:
            throw new StepInternalException("Unsupported option.");
    }
    return sb.toString();
}
Also used : KeyWrapper(com.tyndalehouse.step.core.models.KeyWrapper) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) Key(org.crosswire.jsword.passage.Key) Verse(org.crosswire.jsword.passage.Verse)

Aggregations

KeyWrapper (com.tyndalehouse.step.core.models.KeyWrapper)5 StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)3 Key (org.crosswire.jsword.passage.Key)3 Verse (org.crosswire.jsword.passage.Verse)2 CombinedPassageStats (com.tyndalehouse.step.core.models.stats.CombinedPassageStats)1 PassageStat (com.tyndalehouse.step.core.models.stats.PassageStat)1 BibleBook (org.crosswire.jsword.versification.BibleBook)1 Versification (org.crosswire.jsword.versification.Versification)1