use of com.tyndalehouse.step.core.models.search.BookAndBibleCount in project step by STEPBible.
the class JSwordStrongNumberHelper method calculateStrongArrayCounts.
/**
* Calculate counts for an array of Strong number.
*/
public PassageStat calculateStrongArrayCounts(final String version, PassageStat stat, final String userLanguage) {
Map<String, Integer[]> result = new HashMap<String, Integer[]>(128);
this.isOT = DivisionName.OLD_TESTAMENT.contains(this.reference.getBook());
final Versification targetVersification = isOT ? otV11n : ntV11n;
final Key key = VersificationsMapper.instance().mapVerse(this.reference, targetVersification);
this.allStrongs = new HashMap<>(256);
Map<String, Integer[]> temp = stat.getStats();
temp.forEach((strongNum, feq) -> this.allStrongs.put(strongNum, new BookAndBibleCount()));
Map<String, EntityDoc> augmentedReferences = new HashMap<>(0);
// now get counts in the relevant portion of text
applySearchCounts(getBookFromKey(key), augmentedReferences);
temp.forEach((strongNum, freq) -> {
BookAndBibleCount bBCount = this.allStrongs.get(strongNum);
result.put(strongNum, new Integer[] { freq[0], bBCount.getBook(), bBCount.getBible() });
});
stat.setStats(result);
return stat;
}
use of com.tyndalehouse.step.core.models.search.BookAndBibleCount in project step by STEPBible.
the class JSwordStrongNumberHelper method applySearchCounts.
/**
* Applies the search counts for every strong number.
*
* @param bookName the book name
* @param augmentedByStrong the augmented strongs found in the original augmentation querys
*/
private void applySearchCounts(final String bookName, final Map<String, EntityDoc> augmentedByStrong) {
try {
final IndexSearcher is = jSwordSearchService.getIndexSearcher(this.isOT ? STRONG_OT_VERSION_BOOK.getInitials() : STRONG_NT_VERSION_BOOK.getInitials());
final TermDocs termDocs = is.getIndexReader().termDocs();
for (final Entry<String, BookAndBibleCount> strong : this.allStrongs.entrySet()) {
final String strongKey = strong.getKey();
termDocs.seek(new Term(LuceneIndex.FIELD_STRONG, this.strongAugmentationService.reduce(strongKey)));
final EntityDoc entityDoc = augmentedByStrong.get(strongKey);
final String references = entityDoc != null ? entityDoc.get("references") : null;
// we'll never need more than 200 documents as this is the cut off point
int bible = 0;
int book = 0;
while (termDocs.next()) {
final int freq = termDocs.freq();
final Document doc = is.doc(termDocs.doc());
final String docRef = doc.get(LuceneIndex.FIELD_KEY);
if ((references == null || augmentedVersionInVerse(docRef, references))) {
if (docRef != null && docRef.startsWith(bookName)) {
book += freq;
}
bible += freq;
}
}
final BookAndBibleCount value = strong.getValue();
value.setBible(bible);
value.setBook(book);
}
} catch (final IOException e) {
throw new StepInternalException(e.getMessage(), e);
}
}
use of com.tyndalehouse.step.core.models.search.BookAndBibleCount in project step by STEPBible.
the class JSwordStrongNumberHelper method readDataFromLexicon.
/**
* Read data from lexicon.
*
* @param reader the reader
* @param verseRef the verse ref
* @param augmentedStrongNumbers the strong numbers
*/
private void readDataFromLexicon(final EntityIndexReader reader, final String verseRef, final String augmentedStrongNumbers, final String userLanguage) {
final EntityDoc[] docs = reader.search("strongNumber", augmentedStrongNumbers);
final List<LexiconSuggestion> verseSuggestions = new ArrayList<>();
Map<String, LexiconSuggestion> suggestionsFromSearch = new HashMap<>(docs.length * 2);
for (final EntityDoc d : docs) {
final LexiconSuggestion ls = new LexiconSuggestion();
ls.setStrongNumber(d.get("strongNumber"));
ls.setGloss(d.get("stepGloss"));
if (userLanguage.equalsIgnoreCase("es")) {
ls.set_es_Gloss(d.get("es_Gloss"));
} else if (userLanguage.equalsIgnoreCase("zh")) {
ls.set_zh_Gloss(d.get("zh_Gloss"));
} else if (userLanguage.equalsIgnoreCase("zh_tw")) {
ls.set_zh_tw_Gloss(d.get("zh_tw_Gloss"));
}
ls.setMatchingForm(d.get("accentedUnicode"));
ls.setStepTransliteration(d.get("stepTransliteration"));
suggestionsFromSearch.put(ls.getStrongNumber(), ls);
this.allStrongs.put(ls.getStrongNumber(), new BookAndBibleCount());
}
String[] strongs = StringUtils.split(augmentedStrongNumbers);
for (String s : strongs) {
verseSuggestions.add(suggestionsFromSearch.get(s));
}
this.verseStrongs.put(verseRef, verseSuggestions);
}
Aggregations