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);
}
}
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;
}
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;
}
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;
}
Aggregations