Search in sources :

Example 1 with PassageStat

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

the class JSwordAnalysisServiceImpl method getTextStats.

@Override
public PassageStat getTextStats(final String version, final Key reference, final ScopeType scopeType) {
    try {
        final Book book = this.versification.getBookFromVersion(version);
        final Versification av11n = this.versification.getVersificationForVersion(book);
        final BookData bookData = getExpandedBookData(reference, scopeType, av11n, book);
        final String canonicalText = OSISUtil.getCanonicalText(bookData.getOsisFragment());
        final String[] words = split(canonicalText, WORD_SPLIT);
        Set<String> languageStopWords = getLanguageStopList(book);
        final PassageStat stat = new PassageStat();
        for (final String word : words) {
            // only add word if not in STOP list
            if (!languageStopWords.contains(StringConversionUtils.unAccent(word.toUpperCase(), true))) {
                stat.addWord(word);
            }
        }
        return stat;
    } catch (final BookException e) {
        throw new StepInternalException("Unable to read passage text", e);
    }
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) PassageStat(com.tyndalehouse.step.core.models.stats.PassageStat) Book(org.crosswire.jsword.book.Book) Versification(org.crosswire.jsword.versification.Versification) BookException(org.crosswire.jsword.book.BookException) BookData(org.crosswire.jsword.book.BookData)

Example 2 with PassageStat

use of com.tyndalehouse.step.core.models.stats.PassageStat 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 3 with PassageStat

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

the class AnalysisServiceImpl method getSubjectStats.

/**
 * Subject stats.
 *
 * @param version   the version
 * @param reference the reference
 * @param scopeType
 * @return the passage stat
 */
private PassageStat getSubjectStats(final String version, final String reference, final ScopeType scopeType) {
    final SearchResult subjectResults = this.subjects.searchByReference(getReferenceSyntax(reference, version, scopeType));
    final PassageStat stat = new PassageStat();
    // we duplicate the set here because we'd like to keep the casing...
    final List<SearchEntry> results = subjectResults.getResults();
    for (final SearchEntry entry : results) {
        if (entry instanceof ExpandableSubjectHeadingEntry) {
            final ExpandableSubjectHeadingEntry subjectEntry = (ExpandableSubjectHeadingEntry) entry;
            // we will first do the subheading because ideally we want that 'case' to be the master case,
            // i.e. David rather than DAVID
            final String subjectHeading = subjectEntry.getHeading();
            if (subjectHeading != null && !stopSubjects.contains(subjectHeading.toUpperCase())) {
                stat.addWordTryCases(CLEAN_UP_DIGITS.matcher(subjectHeading).replaceAll(""));
            }
            final String root = subjectEntry.getRoot();
            if (root != null && !stopSubjects.contains(root.toUpperCase())) {
                stat.addWordTryCases(CLEAN_UP_DIGITS.matcher(root).replaceAll(root));
            }
        }
    }
    return stat;
}
Also used : PassageStat(com.tyndalehouse.step.core.models.stats.PassageStat) SearchResult(com.tyndalehouse.step.core.models.search.SearchResult) SearchEntry(com.tyndalehouse.step.core.models.search.SearchEntry) ExpandableSubjectHeadingEntry(com.tyndalehouse.step.core.models.search.ExpandableSubjectHeadingEntry)

Example 4 with PassageStat

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

the class JSwordAnalysisServiceImpl method getStatsFromStrongArray.

/**
 * Gets the stats from word array, counting words one by one and using the {@link PassageStat} to do the
 * incrementing word by word
 *
 * @param words the words
 * @return the stats from word array
 */
private PassageStat getStatsFromStrongArray(final String version, final Key reference, final String[] words, final String userLanguage) {
    PassageStat stat = new PassageStat();
    // slight annoyance that we are deserializing the key to re-serialise later
    final String ref = reference.getOsisRef();
    for (final String unaugmentedWord : words) {
        StrongAugmentationService.AugmentedStrongs strongs = this.strongAugmentationService.augment(version, ref, unaugmentedWord);
        for (String word : strongs.getStrongList()) {
            final String paddedStrongNumber = StringConversionUtils.getStrongPaddedKey(word);
            if (!this.stopStrongs.contains(paddedStrongNumber.toUpperCase())) {
                stat.addWord(paddedStrongNumber);
            }
        }
    }
    return stat;
}
Also used : PassageStat(com.tyndalehouse.step.core.models.stats.PassageStat) StrongAugmentationService(com.tyndalehouse.step.core.service.StrongAugmentationService)

Aggregations

PassageStat (com.tyndalehouse.step.core.models.stats.PassageStat)4 StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)2 KeyWrapper (com.tyndalehouse.step.core.models.KeyWrapper)1 ExpandableSubjectHeadingEntry (com.tyndalehouse.step.core.models.search.ExpandableSubjectHeadingEntry)1 SearchEntry (com.tyndalehouse.step.core.models.search.SearchEntry)1 SearchResult (com.tyndalehouse.step.core.models.search.SearchResult)1 CombinedPassageStats (com.tyndalehouse.step.core.models.stats.CombinedPassageStats)1 StrongAugmentationService (com.tyndalehouse.step.core.service.StrongAugmentationService)1 Book (org.crosswire.jsword.book.Book)1 BookData (org.crosswire.jsword.book.BookData)1 BookException (org.crosswire.jsword.book.BookException)1 Versification (org.crosswire.jsword.versification.Versification)1