Search in sources :

Example 1 with CombinedPassageStats

use of com.tyndalehouse.step.core.models.stats.CombinedPassageStats 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)

Aggregations

StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)1 KeyWrapper (com.tyndalehouse.step.core.models.KeyWrapper)1 CombinedPassageStats (com.tyndalehouse.step.core.models.stats.CombinedPassageStats)1 PassageStat (com.tyndalehouse.step.core.models.stats.PassageStat)1